Fix CreatedModifiedDate plugin when storing content in a separate repo

Following on from https://github.com/jackyzha0/quartz/pull/1791. The change in
a737207981
did not fix the issue for me. Another important change in my PR was the
relative path of the file within the repo that gets passed to `repo.getFileLatestModifiedDateAsync`.
This commit is contained in:
Shane McDonald 2025-03-17 17:22:12 -04:00
parent c0b73ddaa4
commit 766f6c5ef0

View File

@ -35,6 +35,7 @@ export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options>> = (u
return [ return [
() => { () => {
let repo: Repository | undefined = undefined let repo: Repository | undefined = undefined
let repoRoot: string | undefined = undefined
return async (_tree, file) => { return async (_tree, file) => {
let created: MaybeDate = undefined let created: MaybeDate = undefined
let modified: MaybeDate = undefined let modified: MaybeDate = undefined
@ -57,10 +58,13 @@ export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options>> = (u
// It's either the same as the workdir, // It's either the same as the workdir,
// or 1+ level higher in case of a submodule/subtree setup // or 1+ level higher in case of a submodule/subtree setup
repo = Repository.discover(ctx.argv.directory) repo = Repository.discover(ctx.argv.directory)
repoRoot = path.join(repo.path(), "..")
} }
try { try {
modified ||= await repo.getFileLatestModifiedDateAsync(fullFp) modified ||= await repo.getFileLatestModifiedDateAsync(
path.relative(repoRoot!, fullFp),
)
} catch { } catch {
console.log( console.log(
chalk.yellow( chalk.yellow(