feat: optional dates, otherwise fetched from git

This commit is contained in:
Lewis Wynne 2026-01-31 23:39:29 +00:00
parent 4d9e3c56da
commit cc6eff22a8
8 changed files with 90 additions and 31 deletions

View file

@ -1,17 +1,8 @@
import { execSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import yaml from 'js-yaml';
import { sortByPinnedThenDate } from './format';
function getGitDate(filePath: string): Date {
try {
const timestamp = execSync(`git log -1 --format=%cI -- "${filePath}"`, { encoding: 'utf8' }).trim();
return timestamp ? new Date(timestamp) : new Date(0);
} catch {
return new Date(0);
}
}
import { getGitLastModifiedDate } from './git';
export interface TxtFile {
name: string;
@ -45,7 +36,7 @@ export function getTxtFiles(): TxtFile[] {
.filter(file => file.endsWith('.txt'))
.map(name => ({
name,
date: getGitDate(path.join(txtDir, name)),
date: getGitLastModifiedDate(path.join(txtDir, name)),
pinned: pinnedSet.has(name),
}));
return sortByPinnedThenDate(files);