diff --git a/quartz/plugins/transformers/lastmod.ts b/quartz/plugins/transformers/lastmod.ts index 3d6177c67..a1d31cdbe 100644 --- a/quartz/plugins/transformers/lastmod.ts +++ b/quartz/plugins/transformers/lastmod.ts @@ -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> = (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 {