feat: extracts some repeated logic out into lib/ files

This commit is contained in:
Lewis Wynne 2026-01-31 22:10:03 +00:00
parent 38653f2aa1
commit 99c1539aad
22 changed files with 200 additions and 336 deletions

View file

@ -1,34 +1,19 @@
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';
import fs from 'node:fs';
import path from 'node:path';
import type { APIContext } from 'astro';
import { getGitDate } from '../utils';
interface TxtFile {
name: string;
date: Date;
}
import { getTxtFiles } from '../lib/txt';
import { getSlug } from '../utils';
export async function GET(context: APIContext) {
const posts = await getCollection('posts', ({ data }) => data.draft !== true);
const posts = await getCollection('md', ({ data }) => data.draft !== true);
const bookmarks = await getCollection('bookmarks');
const txtDir = path.join(process.cwd(), 'public/txt');
const txtFiles: TxtFile[] = fs.existsSync(txtDir)
? fs.readdirSync(txtDir)
.filter(file => file.endsWith('.txt'))
.map(name => ({
name,
date: getGitDate(path.join(txtDir, name)),
}))
: [];
const txtFiles = getTxtFiles();
const items = [
...posts.map(post => ({
title: post.data.title,
pubDate: post.data.date,
link: `/md/${post.id}`,
link: `/md/${getSlug(post.id)}`,
description: post.data.title,
})),
...txtFiles.map(txt => ({