Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhuxb-Clouds committed Jan 8, 2025
1 parent afd2388 commit 7b4578c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
26 changes: 15 additions & 11 deletions utils/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ export function generateFeedXML() {
const postList = getSortedPostsData()
const metaData = {
title: "Zhuxb Blog",
description: "Share Everything I know.",
description: "Share Everything I know.\nfeedId:99668989463861248+userId:94711388466895872",
link: "https://www.zhuxb.dev/",
lastBuildDate: new Date(),
pubDate: new Date(),
}
const itemData = postList.map(post => ({
title: post.title,
description: "",
link: `https://www.zhuxb.dev/posts/${post.path}`,
guid: post.id,
pubDate: new Date(post.date)
}))
fs.writeFileSync("./public/feed.xml",convertToXml(metaData, itemData))
return [metaData, itemData]

const promise = Promise.all(postList.map(p => getPostData([p.path])))
promise.then(res => {
const itemData = postList.map((post, index) => ({
title: post.title,
description: "",
link: `https://www.zhuxb.dev/posts/${post.path}`,
guid: post.id,
pubDate: new Date(post.date),
content: res[index].rawCotent
}))

fs.writeFileSync("./public/feed.xml", convertToXml(metaData, itemData))
})
}

interface MetaData {
Expand Down Expand Up @@ -82,6 +87,5 @@ function convertToXml(metaData: MetaData, itemData: ItemData[]): string {
// Close XML tags
xml += ` </channel>\n`;
xml += `</rss>`;

return xml;
}
1 change: 1 addition & 0 deletions utils/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export async function getPostData(slug: string[]) {
title: slug.at(-1),
date: format(matterResult.data.date, "yyyy-MM-dd"),
tags: matterResult.data.tags,
rawCotent: matterResult.content
};
}

Expand Down

0 comments on commit 7b4578c

Please sign in to comment.