fix: updates index date

This commit is contained in:
Lewis Wynne 2026-01-31 23:41:59 +00:00
parent cc6eff22a8
commit 5d6aea7aa6
2 changed files with 15 additions and 7 deletions

View file

@ -1,11 +1,15 @@
import { execSync } from 'node:child_process'; import { execSync } from 'node:child_process';
import path from 'node:path';
export function getGitCreationDate(filePath: string): Date { export function getGitCreationDate(filePath: string): Date {
try { try {
// Run git from the file's directory to handle submodules
const dir = path.dirname(filePath);
const file = path.basename(filePath);
// Get the oldest commit for this file (first commit that added it) // Get the oldest commit for this file (first commit that added it)
const timestamp = execSync( const timestamp = execSync(
`git log --follow --diff-filter=A --format=%cI -- "${filePath}"`, `git log --follow --diff-filter=A --format=%cI -- "${file}"`,
{ encoding: 'utf8' } { encoding: 'utf8', cwd: dir }
).trim(); ).trim();
return timestamp ? new Date(timestamp) : new Date(0); return timestamp ? new Date(timestamp) : new Date(0);
} catch { } catch {
@ -15,9 +19,12 @@ export function getGitCreationDate(filePath: string): Date {
export function getGitLastModifiedDate(filePath: string): Date { export function getGitLastModifiedDate(filePath: string): Date {
try { try {
// Run git from the file's directory to handle submodules
const dir = path.dirname(filePath);
const file = path.basename(filePath);
const timestamp = execSync( const timestamp = execSync(
`git log -1 --format=%cI -- "${filePath}"`, `git log -1 --format=%cI -- "${file}"`,
{ encoding: 'utf8' } { encoding: 'utf8', cwd: dir }
).trim(); ).trim();
return timestamp ? new Date(timestamp) : new Date(0); return timestamp ? new Date(timestamp) : new Date(0);
} catch { } catch {

View file

@ -3,10 +3,11 @@ import { getCollection } from 'astro:content';
import Layout from '../layouts/Layout.astro'; import Layout from '../layouts/Layout.astro';
import { getApprovedEntries, type GuestbookEntry } from '../lib/db'; import { getApprovedEntries, type GuestbookEntry } from '../lib/db';
import { formatDate, extractDomain, formatListItem } from '../lib/format'; import { formatDate, extractDomain, formatListItem } from '../lib/format';
import { organizePostsByCategory, getSlug } from '../lib/md'; import { organizePostsByCategory, getSlug, enrichPostsWithDates } from '../lib/md';
import { getTxtFiles } from '../lib/txt'; import { getTxtFiles } from '../lib/txt';
const posts = await getCollection('md', ({ data }) => data.draft !== true); const rawPosts = await getCollection('md', ({ data }) => data.draft !== true);
const posts = enrichPostsWithDates(rawPosts);
const { grouped, categories: sortedCategories } = organizePostsByCategory(posts); const { grouped, categories: sortedCategories } = organizePostsByCategory(posts);
const bookmarksCollection = await getCollection('bookmarks'); const bookmarksCollection = await getCollection('bookmarks');
@ -30,7 +31,7 @@ try {
<details open> <details open>
<summary>{category}</summary> <summary>{category}</summary>
<pre set:html={[ <pre set:html={[
...categoryPosts.slice(0, 10).map(post => formatListItem(post.data.date, `/md/${getSlug(post.id)}`, post.data.title, { pinned: post.data.pinned })), ...categoryPosts.slice(0, 10).map(post => formatListItem(post.dates.created, `/md/${getSlug(post.id)}`, post.data.title, { pinned: post.data.pinned })),
...(categoryPosts.length > 10 ? [`<a href="/md/">+${categoryPosts.length - 10} more</a>`] : []) ...(categoryPosts.length > 10 ? [`<a href="/md/">+${categoryPosts.length - 10} more</a>`] : [])
].join('\n')} /> ].join('\n')} />
</details> </details>