--- import { spawnSync } from "child_process"; import { basename, dirname } from "path"; let { lang, lastUpdated } = Astro.locals.starlightRoute; const published = (f: string) => spawnSync( "git", [ "log", "--format=%ct", "--follow", "--diff-filter=A", "--max-count=1", basename(f), ], { cwd: dirname(f), encoding: "utf-8", } ).stdout?.trim(); const updated = (f: string) => { const cmd = `git log --follow --format=%ct ${basename(f)} | head -n 1`; const res = spawnSync("bash", ["-c", cmd], { cwd: dirname(f), encoding: "utf-8", }).stdout?.trim(); return res; }; const firstPublished = new Date( Number(published(Astro.locals.starlightRoute.entry.filePath) + "000") ); // use starlights value lastUpdated ||= new Date( Number(updated(Astro.locals.starlightRoute.entry.filePath) + "000") ); --- { lastUpdated && (
{"Last updated:"}{" "} {"First published:"}{" "}
) }