Skip to content

Commit

Permalink
♻️ Add default logo for tools
Browse files Browse the repository at this point in the history
  • Loading branch information
prateek3255 committed Sep 12, 2021
1 parent c8f6ebe commit 99584c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 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

0 comments on commit 99584c4

Please sign in to comment.