Files
homepage-template/node_modules/@11ty/eleventy/src/Util/DateGitFirstAdded.js
2024-11-03 17:41:45 +01:00

25 lines
539 B
JavaScript

import spawn from "cross-spawn";
function getGitFirstAddedTimeStamp(filePath) {
return (
parseInt(
spawn
.sync(
"git",
// Formats https://www.git-scm.com/docs/git-log#_pretty_formats
// %at author date, UNIX timestamp
["log", "--diff-filter=A", "--follow", "-1", "--format=%at", filePath],
)
.stdout.toString("utf-8"),
) * 1000
);
}
// return a Date
export default function (inputPath) {
let timestamp = getGitFirstAddedTimeStamp(inputPath);
if (timestamp) {
return new Date(timestamp);
}
}