fix(build): make `lastUpdated` work with git submodules (#2149)

pull/2164/head
Christian Georgi 2 years ago committed by GitHub
parent 51ecd580a2
commit 4c23003189
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -187,7 +187,7 @@ export async function createMarkdownToVueRenderFn(
} }
if (includeLastUpdatedData) { if (includeLastUpdatedData) {
pageData.lastUpdated = await getGitTimestamp(file) pageData.lastUpdated = await getGitTimestamp(fileOrig)
} }
if (siteConfig?.transformPageData) { if (siteConfig?.transformPageData) {

@ -1,8 +1,13 @@
import { spawn } from 'cross-spawn' import { spawn } from 'cross-spawn'
import { basename, dirname } from 'path'
export function getGitTimestamp(file: string) { export function getGitTimestamp(file: string) {
return new Promise<number>((resolve, reject) => { return new Promise<number>((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 = '' let output = ''
child.stdout.on('data', (d) => (output += String(d))) child.stdout.on('data', (d) => (output += String(d)))
child.on('close', () => { child.on('close', () => {

Loading…
Cancel
Save