refactor: bookmarks becomes a content collection with auto-id
This commit is contained in:
parent
23a267a242
commit
1d8ef601bc
6 changed files with 33 additions and 57 deletions
|
|
@ -1,18 +1,10 @@
|
|||
import rss from '@astrojs/rss';
|
||||
import { getCollection } from 'astro:content';
|
||||
import yaml from 'js-yaml';
|
||||
import bookmarksRaw from '../content/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;
|
||||
title: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
interface TxtFile {
|
||||
name: string;
|
||||
date: Date;
|
||||
|
|
@ -20,7 +12,7 @@ interface TxtFile {
|
|||
|
||||
export async function GET(context: APIContext) {
|
||||
const posts = await getCollection('posts', ({ data }) => data.draft !== true);
|
||||
const bookmarks = yaml.load(bookmarksRaw) as Bookmark[];
|
||||
const bookmarks = await getCollection('bookmarks');
|
||||
|
||||
const txtDir = path.join(process.cwd(), 'public/txt');
|
||||
const txtFiles: TxtFile[] = fs.existsSync(txtDir)
|
||||
|
|
@ -46,10 +38,10 @@ export async function GET(context: APIContext) {
|
|||
description: txt.name,
|
||||
})),
|
||||
...bookmarks.map(b => ({
|
||||
title: b.title,
|
||||
pubDate: new Date(b.date),
|
||||
link: b.url,
|
||||
description: b.title,
|
||||
title: b.data.title,
|
||||
pubDate: b.data.date,
|
||||
link: b.data.url,
|
||||
description: b.data.title,
|
||||
})),
|
||||
].sort((a, b) => b.pubDate.getTime() - a.pubDate.getTime());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue