Files
react-test/docs/scripts/generateRSSFeed.ts
how2ice 005cf56baf
Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
init project
2025-12-12 14:26:25 +09:00

48 lines
1.5 KiB
TypeScript

import fs from 'fs';
import { Feed } from 'feed';
import { BlogPost } from 'docs/lib/sourcing';
import ROUTES from 'docs/src/route';
export default function generateRssFeed(allBlogPosts: Array<BlogPost>) {
if (process.env.NODE_ENV !== 'production') {
return;
}
const siteUrl = 'https://mui.com';
const feed = new Feed({
title: 'MUI - Blog',
description:
'Follow the MUI blog to learn about new product features, latest advancements in UI development, and business initiatives.',
id: `${siteUrl}/blog`,
link: `${siteUrl}/blog`,
language: 'en',
image: `${siteUrl}/static/logo.svg`,
favicon: `${siteUrl}/favicon.ico`,
copyright: `Copyright © ${new Date().getFullYear()} Material UI SAS, trading as MUI.`,
feedLinks: {
rss2: `${siteUrl}/public${ROUTES.rssFeed}`,
},
});
allBlogPosts.forEach((post) => {
const postAuthors = post.authors && post.authors.map((author) => ({ name: author }));
const postDate = post.date ? new Date(post.date) : new Date();
const postCategory = post.tags.map((tag) => ({ name: tag }));
const postLink = `${siteUrl}/blog/${post.slug}`;
feed.addItem({
title: post.title,
image: post.image,
id: postLink,
link: postLink,
description: post.description,
category: postCategory,
date: postDate,
author: postAuthors,
});
});
fs.mkdirSync(`public${ROUTES.rssFeed.replace('rss.xml', '')}`, { recursive: true });
fs.writeFileSync(`public${ROUTES.rssFeed}`, feed.rss2());
}