From c72bda2be975134769129558a4294c366a650e0b Mon Sep 17 00:00:00 2001 From: zce Date: Fri, 11 Oct 2024 21:01:11 +0800 Subject: [PATCH] fix: git-based timestamp empty --- docs/guide/last-modified.md | 2 +- docs/other/snippets.md | 2 +- examples/basic/velite.config.js | 2 +- examples/nextjs/velite.config.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/guide/last-modified.md b/docs/guide/last-modified.md index b34d94e..ee3eeb0 100644 --- a/docs/guide/last-modified.md +++ b/docs/guide/last-modified.md @@ -57,7 +57,7 @@ const timestamp = defineSchema(() => addIssue({ fatal: false, code: 'custom', message: '`s.timestamp()` schema will resolve the value from `git log -1 --format=%cd`' }) } const { stdout } = await execAsync(`git log -1 --format=%cd ${meta.path}`) - return new Date(stdout).toISOString() + return new Date(stdout || Date.now()).toISOString() }) ) ``` diff --git a/docs/other/snippets.md b/docs/other/snippets.md index 32c496b..f9f1902 100644 --- a/docs/other/snippets.md +++ b/docs/other/snippets.md @@ -48,7 +48,7 @@ const timestamp = defineSchema(() => addIssue({ fatal: false, code: 'custom', message: '`s.timestamp()` schema will resolve the value from `git log -1 --format=%cd`' }) } const { stdout } = await execAsync(`git log -1 --format=%cd ${meta.path}`) - return new Date(stdout).toISOString() + return new Date(stdout || Date.now()).toISOString() }) ) diff --git a/examples/basic/velite.config.js b/examples/basic/velite.config.js index f915aee..8588da0 100644 --- a/examples/basic/velite.config.js +++ b/examples/basic/velite.config.js @@ -30,7 +30,7 @@ const timestamp = () => addIssue({ fatal: false, code: 'custom', message: '`s.timestamp()` schema will resolve the value from `git log -1 --format=%cd`' }) } const { stdout } = await execAsync(`git log -1 --format=%cd ${meta.path}`) - return new Date(stdout).toISOString() + return new Date(stdout || Date.now()).toISOString() }) export default defineConfig({ diff --git a/examples/nextjs/velite.config.ts b/examples/nextjs/velite.config.ts index f331e9a..4dc4d96 100644 --- a/examples/nextjs/velite.config.ts +++ b/examples/nextjs/velite.config.ts @@ -30,7 +30,7 @@ const timestamp = () => addIssue({ fatal: false, code: 'custom', message: '`s.timestamp()` schema will resolve the value from `git log -1 --format=%cd`' }) } const { stdout } = await execAsync(`git log -1 --format=%cd ${meta.path}`) - return new Date(stdout).toISOString() + return new Date(stdout || Date.now()).toISOString() }) const options = defineCollection({