Fix CreatedModifiedDate plugin when storing content in a separate repo

This commit is contained in:
Shane McDonald 2025-02-24 18:43:49 -05:00
parent dd6bd498db
commit b4b905abde

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
@ -56,11 +57,14 @@ export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options>> = (u
// Get a reference to the main git repo. // Get a reference to the main git repo.
// 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(file.cwd) repo = Repository.discover(fp)
repoRoot = path.join(repo.path(), "..")
} }
try { try {
modified ||= await repo.getFileLatestModifiedDateAsync(file.data.filePath!) modified ||= await repo.getFileLatestModifiedDateAsync(
path.relative(repoRoot!, fp),
)
} catch { } catch {
console.log( console.log(
chalk.yellow( chalk.yellow(