mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 20:23:08 +00:00
Co-authored-by: Dan Abramov <dan.abramov@me.com> Co-authored-by: Sylwia Vargas <sylwia.vargas@gmail.com> Co-authored-by: Dan Lebowitz <dan.lebo@me.com> Co-authored-by: Razvan Gradinar <grazvan@fb.com> Co-authored-by: Jared Palmer <jared@palmer.net> Co-authored-by: Dane Grant <danecando@gmail.com> Co-authored-by: Dustin Goodman <dustin.s.goodman@gmail.com> Co-authored-by: Rick Hanlon <rickhanlonii@gmail.com> Co-authored-by: Maggie Appleton <maggie.fm.appleton@gmail.com> Co-authored-by: Alex Moldovan <alex.n.moldovan@gmail.com> Co-authored-by: Ives van Hoorne <ives.v.h@gmail.com> Co-authored-by: Brian Vaughn <bvaughn@fb.com> Co-authored-by: Dmitri Pavlutin <dpavlutin@gmail.com>
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
const RSS = require('rss');
|
|
const fs = require('fs-extra');
|
|
const authorsJson = require('../src/authors.json');
|
|
const blogIndexJson = require('../src/blogIndex.json');
|
|
const parse = require('date-fns/parse');
|
|
|
|
function removeFromLast(path, key) {
|
|
const i = path.lastIndexOf(key);
|
|
return i === -1 ? path : path.substring(0, i);
|
|
}
|
|
|
|
const SITE_URL = 'https://reactjs.org';
|
|
|
|
function generate() {
|
|
const feed = new RSS({
|
|
title: 'React.js Blog',
|
|
site_url: SITE_URL,
|
|
feed_url: SITE_URL + '/feed.xml',
|
|
});
|
|
|
|
blogIndexJson.routes.map((meta) => {
|
|
feed.item({
|
|
title: meta.title,
|
|
guid: removeFromLast(meta.path, '.'),
|
|
url: SITE_URL + removeFromLast(meta.path, '.'),
|
|
date: parse(meta.date, 'yyyy-MM-dd', new Date()),
|
|
description: meta.description,
|
|
custom_elements: [].concat(
|
|
meta.author.map((author) => ({
|
|
author: [{ name: authorsJson[author].name }],
|
|
}))
|
|
),
|
|
});
|
|
});
|
|
|
|
const rss = feed.xml({ indent: true });
|
|
|
|
fs.writeFileSync('./.next/static/feed.xml', rss);
|
|
}
|
|
|
|
try {
|
|
generate();
|
|
} catch (error) {
|
|
console.error('Error generating rss feed');
|
|
throw error;
|
|
}
|