From 99584c4b4fd6de1c483f77ab03fdb5f84511b544 Mon Sep 17 00:00:00 2001 From: Prateek Surana Date: Sun, 12 Sep 2021 22:14:36 +0530 Subject: [PATCH 1/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20Add=20default=20log?= =?UTF-8?q?o=20for=20tools?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/api.ts | 2 +- lib/issues.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/interfaces/api.ts b/interfaces/api.ts index cfde77e..5588ae2 100644 --- a/interfaces/api.ts +++ b/interfaces/api.ts @@ -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; diff --git a/lib/issues.ts b/lib/issues.ts index d9731aa..b647492 100644 --- a/lib/issues.ts +++ b/lib/issues.ts @@ -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: // [ @@ -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; } @@ -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)), From 9452149e281fa3fe8371d6e4dba5292b78459d46 Mon Sep 17 00:00:00 2001 From: Prateek Surana Date: Sun, 12 Sep 2021 22:17:38 +0530 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=96=20=20v2.1.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3a4238c..ae4f552 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scriptified", - "version": "2.1.2", + "version": "2.1.3", "private": true, "license": "(MIT OR Apache-2.0)", "scripts": { @@ -45,4 +45,4 @@ "prettier": "2.1.1", "typescript": "4.3.5" } -} +} \ No newline at end of file