Last modified git-based remark plugin, site URL

This commit is contained in:
2024-03-10 07:43:32 -05:00
parent 775d1ba88e
commit 9290bde8c7
4 changed files with 33 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
import type { RemarkPlugins } from "astro";
import { execSync } from "child_process";
export const remarkModifiedTime: RemarkPlugins[number] = () => {
return function (_, file) {
const filepath = file.history[0];
const command = `git log -1 --pretty="format:%cI" "${filepath}"`;
let result = execSync(command).toString();
// File is not in git yet
if (result === "") {
result = new Date().toISOString();
}
// @ts-ignore
file.data.astro.frontmatter.lastModified = result;
};
};