-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import path from 'path' | ||
import { writeFileSync } from 'fs' | ||
import { Feed } from 'feed' | ||
import { createContentLoader, type SiteConfig } from 'vitepress' | ||
|
||
const baseUrl = `https://pfcc.blog` | ||
|
||
export async function genFeed(config: SiteConfig) { | ||
const feed = new Feed({ | ||
title: '飞桨开源社区博客', | ||
description: 'Wonderful stories from PaddlePaddle contributors', | ||
id: baseUrl, | ||
link: baseUrl, | ||
language: 'zh-CN', | ||
image: 'https://pfcc.blog/logo.png', | ||
favicon: `${baseUrl}/favicon.ico`, | ||
copyright: 'Copyright (c) 2023-present, PaddlePaddle contributors', | ||
}) | ||
|
||
const posts = await createContentLoader('posts/*.md', { | ||
excerpt: true, | ||
render: true, | ||
}).load() | ||
|
||
posts.sort( | ||
(a, b) => +new Date(b.frontmatter.date as string) - +new Date(a.frontmatter.date as string) | ||
) | ||
|
||
const formatAuthor = (author: { | ||
name: string | ||
github?: string | ||
}): { name: string; link?: string } => { | ||
return { | ||
name: author.name, | ||
link: author.github ? `https://github.com/${author.github}` : undefined, | ||
} | ||
} | ||
|
||
for (const { url, excerpt, frontmatter, html } of posts) { | ||
feed.addItem({ | ||
title: frontmatter.title, | ||
id: `${baseUrl}${url}`, | ||
link: `${baseUrl}${url}`, | ||
description: excerpt, | ||
content: html?.replaceAll('​', ''), | ||
author: [ | ||
formatAuthor(frontmatter.author), | ||
...(frontmatter.co_authors?.map(formatAuthor) ?? []), | ||
], | ||
date: new Date(frontmatter.date as string), | ||
}) | ||
} | ||
|
||
writeFileSync(path.join(config.outDir, 'feed.rss'), feed.rss2()) | ||
} |