diff --git a/apps/blog/src/pages/feed.xml.ts b/apps/blog/src/pages/feed.xml.ts index b564cce..a1d99db 100644 --- a/apps/blog/src/pages/feed.xml.ts +++ b/apps/blog/src/pages/feed.xml.ts @@ -5,6 +5,7 @@ import bookmarksRaw from '../data/bookmarks.yaml?raw'; import fs from 'node:fs'; import path from 'node:path'; import type { APIContext } from 'astro'; +import { getGitDate } from '../utils'; interface Bookmark { date: string; @@ -14,7 +15,7 @@ interface Bookmark { interface TxtFile { name: string; - mtime: Date; + date: Date; } export async function GET(context: APIContext) { @@ -27,7 +28,7 @@ export async function GET(context: APIContext) { .filter(file => file.endsWith('.txt')) .map(name => ({ name, - mtime: fs.statSync(path.join(txtDir, name)).mtime, + date: getGitDate(path.join(txtDir, name)), })) : []; @@ -40,7 +41,7 @@ export async function GET(context: APIContext) { })), ...txtFiles.map(txt => ({ title: txt.name, - pubDate: txt.mtime, + pubDate: txt.date, link: `/txt/${txt.name}`, description: txt.name, })), diff --git a/apps/blog/src/pages/index.astro b/apps/blog/src/pages/index.astro index babf6e3..c5e8e5d 100644 --- a/apps/blog/src/pages/index.astro +++ b/apps/blog/src/pages/index.astro @@ -5,8 +5,8 @@ import yaml from 'js-yaml'; import bookmarksRaw from '../data/bookmarks.yaml?raw'; import fs from 'node:fs'; import path from 'node:path'; -import { execSync } from 'node:child_process'; import { getApprovedEntries, type GuestbookEntry } from '../lib/db'; +import { getGitDate } from '../utils'; interface Bookmark { date: string; @@ -24,15 +24,6 @@ interface TxtConfig { pinned?: string[]; } -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); - } -} - const posts = await getCollection('posts'); // Group by category (default: "posts") diff --git a/apps/blog/src/pages/txt/index.astro b/apps/blog/src/pages/txt/index.astro index 2592466..c1bdc40 100644 --- a/apps/blog/src/pages/txt/index.astro +++ b/apps/blog/src/pages/txt/index.astro @@ -2,8 +2,8 @@ import Layout from '../../layouts/Layout.astro'; import fs from 'node:fs'; import path from 'node:path'; -import { execSync } from 'node:child_process'; import yaml from 'js-yaml'; +import { getGitDate } from '../../utils'; interface TxtFile { name: string; @@ -15,15 +15,6 @@ interface TxtConfig { pinned?: string[]; } -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); - } -} - const txtDir = path.join(process.cwd(), 'public/txt'); const configPath = path.join(txtDir, 'config.yaml'); const config: TxtConfig = fs.existsSync(configPath) diff --git a/apps/blog/src/utils.ts b/apps/blog/src/utils.ts new file mode 100644 index 0000000..8f61965 --- /dev/null +++ b/apps/blog/src/utils.ts @@ -0,0 +1,10 @@ +import { execSync } from 'node:child_process'; + +export 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); + } +}