Collection of handy online tools for developers, with great UX.
TypeScript converterdeveloper-productivitydeveloper-toolsfrontendjavascriptproductivitytooltoolstypescriptvuejswebsite
refactor(tool): better new tool logic
Corentin Thomassetfb8a3a0fee05
diff --git a/scripts/create-tool.mjs b/scripts/create-tool.mjsindex 33ab807c..36a20d8e 100644--- a/scripts/create-tool.mjs+++ b/scripts/create-tool.mjs@@ -55,6 +55,7 @@ export const tool = defineTool({keywords: ['${toolName.split('-').join("', '")}'],component: () => import('./${toolName}.vue'),icon: ArrowsShuffle,+ createdAt: new Date('${new Date().toISOString().split('T')[0]}'),});`,);diff --git a/src/tools/tool.ts b/src/tools/tool.tsindex 8289aa33..a5d157e9 100644--- a/src/tools/tool.ts+++ b/src/tools/tool.ts@@ -1,4 +1,5 @@import { config } from '@/config';+import { isAfter, subWeeks } from 'date-fns';import type { Tool } from './tools.types';type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;@@ -7,7 +8,10 @@ export function defineTool(tool: WithOptional<Tool, 'isNew'>,{ newTools }: { newTools: string[] } = { newTools: config.tools.newTools },) {- const isNew = newTools.includes(tool.name);+ const isInNewToolConfig = newTools.includes(tool.name);+ const isRecentTool = tool.createdAt ? isAfter(tool.createdAt, subWeeks(new Date(), 2)) : false;++ const isNew = isInNewToolConfig || isRecentTool;return {isNew,diff --git a/src/tools/tools.types.ts b/src/tools/tools.types.tsindex 5630a12e..48f60629 100644--- a/src/tools/tools.types.ts+++ b/src/tools/tools.types.ts@@ -9,6 +9,7 @@ export type Tool = {icon: Component;redirectFrom?: string[];isNew: boolean;+ createdAt?: Date;};export type ToolCategory = {