From 5d6aea7aa6e5a373bd72e945d9bb31ecd573ce6c Mon Sep 17 00:00:00 2001 From: lew Date: Sat, 31 Jan 2026 23:41:59 +0000 Subject: [PATCH] fix: updates index date --- www/src/lib/git.ts | 15 +++++++++++---- www/src/pages/index.astro | 7 ++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/www/src/lib/git.ts b/www/src/lib/git.ts index 9a54145..6b702e3 100644 --- a/www/src/lib/git.ts +++ b/www/src/lib/git.ts @@ -1,11 +1,15 @@ import { execSync } from 'node:child_process'; +import path from 'node:path'; export function getGitCreationDate(filePath: string): Date { 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) const timestamp = execSync( - `git log --follow --diff-filter=A --format=%cI -- "${filePath}"`, - { encoding: 'utf8' } + `git log --follow --diff-filter=A --format=%cI -- "${file}"`, + { encoding: 'utf8', cwd: dir } ).trim(); return timestamp ? new Date(timestamp) : new Date(0); } catch { @@ -15,9 +19,12 @@ export function getGitCreationDate(filePath: string): Date { export function getGitLastModifiedDate(filePath: string): Date { try { + // Run git from the file's directory to handle submodules + const dir = path.dirname(filePath); + const file = path.basename(filePath); const timestamp = execSync( - `git log -1 --format=%cI -- "${filePath}"`, - { encoding: 'utf8' } + `git log -1 --format=%cI -- "${file}"`, + { encoding: 'utf8', cwd: dir } ).trim(); return timestamp ? new Date(timestamp) : new Date(0); } catch { diff --git a/www/src/pages/index.astro b/www/src/pages/index.astro index 515e553..8b5c8b9 100644 --- a/www/src/pages/index.astro +++ b/www/src/pages/index.astro @@ -3,10 +3,11 @@ import { getCollection } from 'astro:content'; import Layout from '../layouts/Layout.astro'; import { getApprovedEntries, type GuestbookEntry } from '../lib/db'; 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'; -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 bookmarksCollection = await getCollection('bookmarks'); @@ -30,7 +31,7 @@ try {
{category}
 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 ? [`+${categoryPosts.length - 10} more`] : [])
 ].join('\n')} />