.*?<\/div><\/div>
.*?<\/div><\/div><\/div><\/div>/g
return content.replace(regexExp, '')
}
}
export async function generateRss(posts) {
const year = new Date().getFullYear()
const feed = new Feed({
title: BLOG.TITLE,
description: BLOG.DESCRIPTION,
link: `${BLOG.LINK}/${BLOG.SUB_PATH}`,
language: BLOG.LANG,
favicon: `${BLOG.LINK}/favicon.png`,
copyright: `All rights reserved ${year}, ${BLOG.AUTHOR}`,
author: {
name: BLOG.AUTHOR,
email: BLOG.CONTACT_EMAIL,
link: BLOG.LINK
}
})
for (const post of posts) {
feed.addItem({
title: post.title,
link: `${BLOG.LINK}/${post.slug}`,
description: post.summary,
content: await createFeedContent(post),
date: new Date(post?.date?.start_date || post?.createdTime)
})
}
try {
fs.mkdirSync('./public/rss', { recursive: true })
fs.writeFileSync('./public/rss/feed.xml', feed.rss2())
fs.writeFileSync('./public/rss/atom.xml', feed.atom1())
fs.writeFileSync('./public/rss/feed.json', feed.json1())
fs.mkdirSync('./rss', { recursive: true })
fs.writeFileSync('./rss/feed.xml', feed.rss2())
fs.writeFileSync('./rss/atom.xml', feed.atom1())
fs.writeFileSync('./rss/feed.json', feed.json1())
} catch (error) {
console.warn('无法写入文件', error)
}
}