Skip to content

Commit

Permalink
Merge pull request #67 from scriptified/add-default-tool-asset
Browse files Browse the repository at this point in the history
♻️  Add default logo for tools
  • Loading branch information
gupta-ji6 authored Sep 12, 2021
2 parents c8f6ebe + 9452149 commit 4fed532
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion interfaces/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export interface ToolsEntity {
id: number;
name: string;
url: string;
logo: string;
logo?: string | null;
description: string;
issue: number;
published_at: string;
Expand Down
10 changes: 8 additions & 2 deletions lib/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const ASSETS_URL = 'https://images.scriptified.dev/';

const OG_IMAGE_BASE = 'https://og.scriptified.dev/';

const DEFAULT_TOOL_ASSET = `${ASSETS_URL}common/default-tool.png`;

export function getAllIssueIds(issues: IssueAPIResponse[]): Array<{ params: { id: string } }> {
// Returns an array that looks like this:
// [
Expand Down Expand Up @@ -73,7 +75,11 @@ function isValidHttpUrl(str: string) {
return url.protocol === 'http:' || url.protocol === 'https:';
}

function getAssetURL(issueNumber: number, assetURL: string) {
function getAssetURL(issueNumber: number, assetURL: string | undefined | null, defaultAssetURL?: string): string {
if ((typeof assetURL !== 'string' || assetURL.length === 0) && typeof defaultAssetURL === 'string') {
return defaultAssetURL;
}

if (isValidHttpUrl(assetURL)) {
return assetURL;
}
Expand Down Expand Up @@ -125,7 +131,7 @@ export function mapToIssue(issue: IssueAPIResponse): Issue {
? issue.tools.map(tool => ({
title: tool.name,
url: tool.url,
logo: getAssetURL(issue.id, tool.logo),
logo: getAssetURL(issue.id, tool.logo, DEFAULT_TOOL_ASSET),
desc: tool.description,
tags: tool.tags.map(tag => tag.name),
author: oxfordComma(tool.authors.map(author => author.Name)),
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scriptified",
"version": "2.1.2",
"version": "2.1.3",
"private": true,
"license": "(MIT OR Apache-2.0)",
"scripts": {
Expand Down Expand Up @@ -45,4 +45,4 @@
"prettier": "2.1.1",
"typescript": "4.3.5"
}
}
}

0 comments on commit 4fed532

Please sign in to comment.