feat: sorted home recipe list by updated at time
This commit is contained in:
parent
928e7aecff
commit
e46d2b8d38
2 changed files with 39 additions and 1 deletions
|
|
@ -95,6 +95,21 @@ const getGitCreatedTime = (filePath) => {
|
|||
return null;
|
||||
}
|
||||
|
||||
const getGitModifiedTime = (filePath) => {
|
||||
try {
|
||||
const result = execSync(
|
||||
`git log -1 --format=%aI -- "${filePath}"`,
|
||||
{ encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }
|
||||
).trim();
|
||||
if (result) {
|
||||
return DateTime.fromISO(result).toUTC();
|
||||
}
|
||||
} catch (e) {
|
||||
// Git command failed, return null
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
const getFileCreatedTime = (filePath) => {
|
||||
// Try git first for accurate cross-system creation time
|
||||
const gitTime = getGitCreatedTime(filePath);
|
||||
|
|
@ -127,6 +142,23 @@ const getFileCreatedDateTime = (filePath) => {
|
|||
}
|
||||
}
|
||||
|
||||
const getFileModifiedTime = (filePath) => {
|
||||
try {
|
||||
const stats = fs.statSync(filePath);
|
||||
return DateTime.fromJSDate(stats.mtime, { zone: 'utc' });
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const parseDate = (value) => {
|
||||
if (!value) return null;
|
||||
if (DateTime.isDateTime(value)) return value;
|
||||
if (value instanceof Date) return DateTime.fromJSDate(value, { zone: 'utc' });
|
||||
const parsed = DateTime.fromISO(value, { zone: 'utc' });
|
||||
return parsed.isValid ? parsed : null;
|
||||
}
|
||||
|
||||
const getVersion = (filePath) => {
|
||||
const dirName = path.dirname(filePath)
|
||||
|
||||
|
|
@ -216,6 +248,11 @@ module.exports = {
|
|||
createdAt: (data) => {
|
||||
return getFileCreatedDateTime(data.page.inputPath);
|
||||
},
|
||||
updatedAt: (data) => {
|
||||
return parseDate(data.updatedAt) ??
|
||||
getGitModifiedTime(data.page.inputPath) ??
|
||||
getFileModifiedTime(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