diff --git a/src/node/markdownToVue.ts b/src/node/markdownToVue.ts index 0d48de5a969e..420a4bf696b3 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -187,7 +187,7 @@ export async function createMarkdownToVueRenderFn( } if (includeLastUpdatedData) { - pageData.lastUpdated = await getGitTimestamp(file) + pageData.lastUpdated = await getGitTimestamp(fileOrig) } if (siteConfig?.transformPageData) { diff --git a/src/node/utils/getGitTimestamp.ts b/src/node/utils/getGitTimestamp.ts index 07c4d8204964..f14a463b1b39 100644 --- a/src/node/utils/getGitTimestamp.ts +++ b/src/node/utils/getGitTimestamp.ts @@ -1,8 +1,13 @@ import { spawn } from 'cross-spawn' +import { basename, dirname } from 'path' export function getGitTimestamp(file: string) { return new Promise((resolve, reject) => { - const child = spawn('git', ['log', '-1', '--pretty="%ci"', file]) + const cwd = dirname(file) + const fileName = basename(file) + const child = spawn('git', ['log', '-1', '--pretty="%ci"', fileName], { + cwd + }) let output = '' child.stdout.on('data', (d) => (output += String(d))) child.on('close', () => {