feat(rss): hot introducing rss feature as seperate utility module after docs is built

This commit is contained in:
andatoshiki 2023-03-25 20:08:03 +08:00
parent 148c74c957
commit 592e22faae
3 changed files with 16 additions and 20 deletions

View File

@ -19,15 +19,13 @@ async function genFeed() {
language: siteData.lang,
image: `${url}/logos/logo-308px.png`,
favicon: `${url}/favicon.ico`,
copyright: siteData.themeConfig.name || '-',
copyright: siteData.themeConfig.name || '-'
})
posts.forEach((post) => {
posts.forEach(post => {
const file = path.resolve(cwd, `dist/${post.href}`)
const rendered = fs.readFileSync(file, 'utf-8')
const content = rendered.match(
/<body>([\s\S]*)<\/body>/
)
const content = rendered.match(/<body>([\s\S]*)<\/body>/)
feed.addItem({
title: post.title,
@ -38,11 +36,9 @@ async function genFeed() {
author: [
{
name: post.data.author,
link: post.data.twitter
? `https://twitter.com/${post.data.twitter}`
: undefined
link: post.data.twitter ? `https://twitter.com/${post.data.twitter}` : undefined
}
],
]
})
})

View File

@ -1,10 +1,10 @@
export interface PostData {
title: string,
href: string,
create: number,
update: number,
tags?: string[],
cover?: string,
excerpt: string,
title: string
href: string
create: number
update: number
tags?: string[]
cover?: string
excerpt: string
}
export declare const data: PostData[]

View File

@ -13,8 +13,8 @@ module.exports = {
const postDir = path.join(cwd, 'docs')
return fs
.readdirSync(postDir)
.filter((file) => file.endsWith('.md'))
.map((file) => getPost(md, file, postDir, asFeed))
.filter(file => file.endsWith('.md'))
.map(file => getPost(md, file, postDir, asFeed))
.sort((a, b) => b.create - a.create)
}
}