feat: localized time on cards
This commit is contained in:
parent
9a80850230
commit
55e67d1e27
5 changed files with 25 additions and 3 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue