Skip to content

Commit

Permalink
🤔 try new feed
Browse files Browse the repository at this point in the history
  • Loading branch information
YUANCONG LIU committed Dec 14, 2023
1 parent 2ed7d71 commit 7b35d3c
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions src/utils/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import fs from 'fs';
import { Feed } from 'feed';
import { getAllPosts } from './posts';
import { getAllPosts, markdownToHtml } from './posts';

export const generateRssFeed = () => {
export const generateRssFeed = async () => {
const posts = getAllPosts(['slug', 'title', 'date', 'tags', 'content']);
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || '';
const date = new Date();
Expand All @@ -16,19 +16,6 @@ export const generateRssFeed = () => {
link: process.env.NEXT_PUBLIC_SITE_URL,
};

// const getLocale = (languageTag: string) => {
// switch (languageTag) {
// case 'Chinese':
// return 'zh-Hant';
// case 'English':
// return 'en';
// case 'Japanese':
// return 'ja';
// default:
// return 'en';
// }
// };

const feed = new Feed({
title: "YUANCONG.L's Blog",
id: siteUrl,
Expand All @@ -45,19 +32,21 @@ export const generateRssFeed = () => {
author,
});

posts.forEach((post) => {
const postPromise = posts.map(async (post) => {
feed.addItem({
title: post.title,
id: `${siteUrl}/blog/${post.slug}`,
link: `${siteUrl}/blog/${post.slug}`,
description: post.title,
content: post.title,
content: await markdownToHtml(post.content),
date: new Date(post.date),
});
});

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());
Promise.all(postPromise).then(() => {
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());
});
};

1 comment on commit 7b35d3c

@vercel
Copy link

@vercel vercel bot commented on 7b35d3c Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.