fix(transformer): keep find file from relative path of repo workdir

This commit is contained in:
Dralagen 2025-03-18 21:03:20 +01:00
parent 025db83060
commit baa9a49c8c

View File

@ -2,6 +2,7 @@ import fs from "fs"
import { Repository } from "@napi-rs/simple-git"
import { QuartzTransformerPlugin } from "../types"
import chalk from "chalk"
import path from "path"
export interface Options {
priority: ("frontmatter" | "git" | "filesystem")[]
@ -60,15 +61,8 @@ export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options>> = (u
created ||= file.data.frontmatter.created as MaybeDate
modified ||= file.data.frontmatter.modified as MaybeDate
published ||= file.data.frontmatter.published as MaybeDate
} else if (source === "git") {
if (!repo) {
// Get a reference to the main git repo.
// It's either the same as the workdir,
// or 1+ level higher in case of a submodule/subtree setup
repo = Repository.discover(fullFp)
}
} else if (source === "git" && repo) {
const relativePath = path.relative(repo.workdir()!, fullFp)
try {
modified ||= await repo.getFileLatestModifiedDateAsync(relativePath)
} catch {