Skip to content

Commit

Permalink
fix: git-based timestamp empty
Browse files Browse the repository at this point in the history
  • Loading branch information
zce committed Oct 11, 2024
1 parent 8e3f134 commit c72bda2
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/guide/last-modified.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
)
```
Expand Down
2 changes: 1 addition & 1 deletion docs/other/snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
)

Expand Down
2 changes: 1 addition & 1 deletion examples/basic/velite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs/velite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit c72bda2

Please sign in to comment.