mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-20 14:56:17 -04:00
refactor(tool): better new tool logic
This commit is contained in:
parent
20282987e3
commit
fb8a3a0fee
3 changed files with 7 additions and 1 deletions
|
@ -55,6 +55,7 @@ export const tool = defineTool({
|
||||||
keywords: ['${toolName.split('-').join("', '")}'],
|
keywords: ['${toolName.split('-').join("', '")}'],
|
||||||
component: () => import('./${toolName}.vue'),
|
component: () => import('./${toolName}.vue'),
|
||||||
icon: ArrowsShuffle,
|
icon: ArrowsShuffle,
|
||||||
|
createdAt: new Date('${new Date().toISOString().split('T')[0]}'),
|
||||||
});
|
});
|
||||||
`,
|
`,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { config } from '@/config';
|
import { config } from '@/config';
|
||||||
|
import { isAfter, subWeeks } from 'date-fns';
|
||||||
import type { Tool } from './tools.types';
|
import type { Tool } from './tools.types';
|
||||||
|
|
||||||
type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
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'>,
|
tool: WithOptional<Tool, 'isNew'>,
|
||||||
{ newTools }: { newTools: string[] } = { newTools: config.tools.newTools },
|
{ 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 {
|
return {
|
||||||
isNew,
|
isNew,
|
||||||
|
|
|
@ -9,6 +9,7 @@ export type Tool = {
|
||||||
icon: Component;
|
icon: Component;
|
||||||
redirectFrom?: string[];
|
redirectFrom?: string[];
|
||||||
isNew: boolean;
|
isNew: boolean;
|
||||||
|
createdAt?: Date;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ToolCategory = {
|
export type ToolCategory = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue