import path from 'node:path' import { writeFileSync } from 'node:fs' import { Feed } from 'feed' import { type SiteConfig, createContentLoader } from 'vitepress' import { site as baseUrl, description, name } from '../config/meta' function reName(name: string) { if (!name) name = 'Anda Toshiki' return name === 'Anda Toshiki' ? 'andatoshiki' : name } function getGithubLink(name: string) { return `https://github.com/${reName(name)}` } export async function genFeed(config: SiteConfig) { const feed = new Feed({ title: name, description, id: baseUrl, link: baseUrl, language: 'en-US', image: 'https://note.toshiki.dev/logo-308px.png', favicon: `${baseUrl}/favicon.ico`, copyright: 'Copyright (c) 2023-present, Anda Toshiki at Toshiki Dev', }) const posts = await createContentLoader('**/*.md', { excerpt: true, render: true, }).load() posts.sort((a, b) => +new Date(b.frontmatter?.date as string) - +new Date(a.frontmatter?.date as string)) for (const { url, frontmatter, html } of posts) { let postTitle = 'No Title' postTitle = html?.match(/