feat: localized time on cards

This commit is contained in:
Leyla Becker 2026-02-19 17:35:13 -06:00
parent 9a80850230
commit 55e67d1e27
5 changed files with 25 additions and 3 deletions

View file

@ -1,6 +1,7 @@
const fs = require('fs')
const path = require("path");
const { execSync } = require("child_process");
const { DateTime } = require("luxon");
const getSlugFromPath = (filePath) => {
// Normalize the path - remove leading ./ if present
@ -62,6 +63,21 @@ const getFileCreatedTime = (filePath) => {
}
}
const getFileCreatedDateTime = (filePath) => {
const gitTime = getGitCreatedTime(filePath);
if (gitTime) {
return DateTime.fromMillis(gitTime, { zone: 'utc' });
}
try {
const stats = fs.statSync(filePath);
const time = stats.birthtime ?? stats.mtime;
return DateTime.fromJSDate(time, { zone: 'utc' });
} catch (e) {
return DateTime.utc();
}
}
const getVersion = (filePath) => {
const dirName = path.dirname(filePath)
@ -145,6 +161,9 @@ module.exports = {
isDraft: (data) => {
return data.draft === true;
},
createdAt: (data) => {
return getFileCreatedDateTime(data.page.inputPath);
},
permalink: (data) => {
const slug = getSlugFromPath(data.page.inputPath);
const version = getVersion(data.page.inputPath);