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)), 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