Add rss feed (#6803)

* Add rss feed

* Add rss feed

* rss readers don't like å characters
This commit is contained in:
Ricky
2024-04-26 11:56:47 -04:00
committed by GitHub
parent f66402862d
commit cf53cb5d52
17 changed files with 132 additions and 2 deletions

3
.gitignore vendored
View File

@@ -36,3 +36,6 @@ yarn-error.log*
# external fonts
public/fonts/**/Optimistic_*.woff2
# rss
public/rss.xml

View File

@@ -15,11 +15,12 @@
"prettier:diff": "yarn nit:source",
"lint-heading-ids": "node scripts/headingIdLinter.js",
"fix-headings": "node scripts/headingIdLinter.js --fix",
"ci-check": "npm-run-all prettier:diff --parallel lint tsc lint-heading-ids",
"ci-check": "npm-run-all prettier:diff --parallel lint tsc lint-heading-ids rss",
"tsc": "tsc --noEmit",
"start": "next start",
"postinstall": "patch-package && (is-ci || husky install .husky)",
"check-all": "npm-run-all prettier lint:fix tsc"
"check-all": "npm-run-all prettier lint:fix tsc rss",
"rss": "node scripts/generateRss.js"
},
"dependencies": {
"@codesandbox/sandpack-react": "2.13.5",

6
scripts/generateRss.js Normal file
View File

@@ -0,0 +1,6 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*/
const {generateRssFeed} = require('../src/utils/rss');
generateRssFeed();

View File

@@ -1,5 +1,8 @@
---
title: "Introducing Zero-Bundle-Size React Server Components"
author: Dan Abramov, Lauren Tan, Joseph Savona, and Sebastian Markbage
date: 2020/12/21
description: 2020 has been a long year. As it comes to an end we wanted to share a special Holiday Update on our research into zero-bundle-size React Server Components.
---
December 21, 2020 by [Dan Abramov](https://twitter.com/dan_abramov), [Lauren Tan](https://twitter.com/potetotes), [Joseph Savona](https://twitter.com/en_JS), and [Sebastian Markbåge](https://twitter.com/sebmarkbage)

View File

@@ -1,5 +1,8 @@
---
title: "The Plan for React 18"
author: Andrew Clark, Brian Vaughn, Christine Abernathy, Dan Abramov, Rachel Nabors, Rick Hanlon, Sebastian Markbage, and Seth Webster
date: 2021/06/08
description: The React team is excited to share a few updates. Weve started work on the React 18 release, which will be our next major version. Weve created a Working Group to prepare the community for gradual adoption of new features in React 18. Weve published a React 18 Alpha so that library authors can try it and provide feedback...
---
June 8, 2021 by [Andrew Clark](https://twitter.com/acdlite), [Brian Vaughn](https://github.com/bvaughn), [Christine Abernathy](https://twitter.com/abernathyca), [Dan Abramov](https://twitter.com/dan_abramov), [Rachel Nabors](https://twitter.com/rachelnabors), [Rick Hanlon](https://twitter.com/rickhanlonii), [Sebastian Markbåge](https://twitter.com/sebmarkbage), and [Seth Webster](https://twitter.com/sethwebster)

View File

@@ -1,5 +1,8 @@
---
title: "React Conf 2021 Recap"
author: Jesslyn Tannady and Rick Hanlon
date: 2021/12/17
description: Last week we hosted our 6th React Conf. In previous years, we've used the React Conf stage to deliver industry changing announcements such as React Native and React Hooks. This year, we shared our multi-platform vision for React, starting with the release of React 18 and gradual adoption of concurrent features.
---
December 17, 2021 by [Jesslyn Tannady](https://twitter.com/jtannady) and [Rick Hanlon](https://twitter.com/rickhanlonii)

View File

@@ -1,5 +1,8 @@
---
title: "How to Upgrade to React 18"
author: Rick Hanlon
date: 2022/03/08
description: As we shared in the release post, React 18 introduces features powered by our new concurrent renderer, with a gradual adoption strategy for existing applications. In this post, we will guide you through the steps for upgrading to React 18.
---
March 08, 2022 by [Rick Hanlon](https://twitter.com/rickhanlonii)

View File

@@ -1,5 +1,8 @@
---
title: "React v18.0"
author: The React Team
date: 2022/03/08
description: React 18 is now available on npm! In our last post, we shared step-by-step instructions for upgrading your app to React 18. In this post, we'll give an overview of what's new in React 18, and what it means for the future.
---
March 29, 2022 by [The React Team](/community/team)

View File

@@ -1,5 +1,8 @@
---
title: "React Labs: What We've Been Working On June 2022"
author: Andrew Clark, Dan Abramov, Jan Kassens, Joseph Savona, Josh Story, Lauren Tan, Luna Ruan, Mengdi Chen, Rick Hanlon, Robert Zhang, Sathya Gunasekaran, Sebastian Markbage, and Xuan Huang
date: 2022/06/15
description: React 18 was years in the making, and with it brought valuable lessons for the React team. Its release was the result of many years of research and exploring many paths. Some of those paths were successful; many more were dead-ends that led to new insights. One lesson weve learned is that its frustrating for the community to wait for new features without having insight into these paths that were exploring.
---
June 15, 2022 by [Andrew Clark](https://twitter.com/acdlite), [Dan Abramov](https://twitter.com/dan_abramov), [Jan Kassens](https://twitter.com/kassens), [Joseph Savona](https://twitter.com/en_JS), [Josh Story](https://twitter.com/joshcstory), [Lauren Tan](https://twitter.com/potetotes), [Luna Ruan](https://twitter.com/lunaruan), [Mengdi Chen](https://twitter.com/mengdi_en), [Rick Hanlon](https://twitter.com/rickhanlonii), [Robert Zhang](https://twitter.com/jiaxuanzhang01), [Sathya Gunasekaran](https://twitter.com/_gsathya), [Sebastian Markbåge](https://twitter.com/sebmarkbage), and [Xuan Huang](https://twitter.com/Huxpro)

View File

@@ -1,5 +1,8 @@
---
title: "Introducing react.dev"
author: Dan Abramov and Rachel Nabors
date: 2023/03/16
description: Today we are thrilled to launch react.dev, the new home for React and its documentation. In this post, we would like to give you a tour of the new site.
---
March 16, 2023 by [Dan Abramov](https://twitter.com/dan_abramov) and [Rachel Nabors](https://twitter.com/rachelnabors)

View File

@@ -1,5 +1,8 @@
---
title: "React Labs: What We've Been Working On March 2023"
author: Joseph Savona, Josh Story, Lauren Tan, Mengdi Chen, Samuel Susla, Sathya Gunasekaran, Sebastian Markbage, and Andrew Clark
date: 2023/03/22
description: In React Labs posts, we write about projects in active research and development. We've made significant progress on them since our last update, and we'd like to share what we learned.
---
March 22, 2023 by [Joseph Savona](https://twitter.com/en_JS), [Josh Story](https://twitter.com/joshcstory), [Lauren Tan](https://twitter.com/potetotes), [Mengdi Chen](https://twitter.com/mengdi_en), [Samuel Susla](https://twitter.com/SamuelSusla), [Sathya Gunasekaran](https://twitter.com/_gsathya), [Sebastian Markbåge](https://twitter.com/sebmarkbage), and [Andrew Clark](https://twitter.com/acdlite)

View File

@@ -1,5 +1,8 @@
---
title: "React Canaries: Enabling Incremental Feature Rollout Outside Meta"
author: Dan Abramov, Sophie Alpert, Rick Hanlon, Sebastian Markbage, and Andrew Clark
date: 2023/05/03
description: We'd like to offer the React community an option to adopt individual new features as soon as their design is close to final, before they're released in a stable version--similar to how Meta has long used bleeding-edge versions of React internally. We are introducing a new officially supported [Canary release channel](/community/versioning-policy#canary-channel). It lets curated setups like frameworks decouple adoption of individual React features from the React release schedule.
---
May 3, 2023 by [Dan Abramov](https://twitter.com/dan_abramov), [Sophie Alpert](https://twitter.com/sophiebits), [Rick Hanlon](https://twitter.com/rickhanlonii), [Sebastian Markbåge](https://twitter.com/sebmarkbage), and [Andrew Clark](https://twitter.com/acdlite)

View File

@@ -1,5 +1,8 @@
---
title: "React Labs: What We've Been Working On February 2024"
author: Joseph Savona, Ricky Hanlon, Andrew Clark, Matt Carroll, and Dan Abramov
date: 2024/02/15
description: In React Labs posts, we write about projects in active research and development. Weve made significant progress since our last update, and wed like to share our progress.
---
February 15, 2024 by [Joseph Savona](https://twitter.com/en_JS), [Ricky Hanlon](https://twitter.com/rickhanlonii), [Andrew Clark](https://twitter.com/acdlite), [Matt Carroll](https://twitter.com/mattcarrollcode), and [Dan Abramov](https://twitter.com/dan_abramov).

View File

@@ -1,5 +1,8 @@
---
title: "React 19 Beta Upgrade Guide"
author: Ricky Hanlon
date: 2024/04/25
description: The improvements added to React 19 require some breaking changes, but we've worked to make the upgrade as smooth as possible and we don't expect the changes to impact most apps. In this post, we will guide you through the steps for upgrading libraries to React 19 beta.
---
April 25, 2024 by [Ricky Hanlon](https://twitter.com/rickhanlonii)

View File

@@ -1,5 +1,8 @@
---
title: "React 19 Beta"
author: The React Team
date: 2024/04/25
description: React 19 Beta is now available on npm! In this post, we'll give an overview of the new features in React 19, and how you can adopt them.
---
April 25, 2024 by [The React Team](/community/team)

View File

@@ -12,6 +12,7 @@ import sidebarCommunity from '../sidebarCommunity.json';
import sidebarBlog from '../sidebarBlog.json';
import {MDXComponents} from 'components/MDX/MDXComponents';
import compileMDX from 'utils/compileMDX';
import {generateRssFeed} from '../utils/rss';
export default function Layout({content, toc, meta}) {
const parsedContent = useMemo(
() => JSON.parse(content, reviveNodeOnClient),
@@ -96,6 +97,7 @@ function reviveNodeOnClient(key, val) {
// Put MDX output into JSON for client.
export async function getStaticProps(context) {
generateRssFeed();
const fs = require('fs');
const rootDir = process.cwd() + '/src/content/';

82
src/utils/rss.js Normal file
View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*/
const Feed = require('rss');
const fs = require('fs');
const path = require('path');
const matter = require('gray-matter');
const getAllFiles = function (dirPath, arrayOfFiles) {
const files = fs.readdirSync(dirPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach(function (file) {
if (fs.statSync(dirPath + '/' + file).isDirectory()) {
arrayOfFiles = getAllFiles(dirPath + '/' + file, arrayOfFiles);
} else {
arrayOfFiles.push(path.join(dirPath, '/', file));
}
});
return arrayOfFiles;
};
exports.generateRssFeed = function () {
const feed = new Feed({
title: 'React Blog',
description:
'This blog is the official source for the updates from the React team. Anything important, including release notes or deprecation notices, will be posted here first.',
feed_url: 'https://react.dev/rss.xml',
site_url: 'https://react.dev/',
language: 'en',
favicon: 'https://react.dev/favicon.ico',
pubDate: new Date(),
generator: 'react.dev rss module',
});
const dirPath = path.join(process.cwd(), 'src/content/blog');
const filesByOldest = getAllFiles(dirPath);
const files = filesByOldest.reverse();
for (const filePath of files) {
const id = filePath.split('/').slice(-1).join('');
if (id !== 'index.md') {
const content = fs.readFileSync(filePath, 'utf-8');
const {data} = matter(content);
const slug = filePath.split('/').slice(-4).join('/').replace('.md', '');
if (data.title == null || data.title.trim() === '') {
throw new Error(
`${id}: Blog posts must include a title in the metadata, for RSS feeds`
);
}
if (data.author == null || data.author.trim() === '') {
throw new Error(
`${id}: Blog posts must include an author in the metadata, for RSS feeds`
);
}
if (data.date == null || data.date.trim() === '') {
throw new Error(
`${id}: Blog posts must include a date in the metadata, for RSS feeds`
);
}
if (data.description == null || data.description.trim() === '') {
throw new Error(
`${id}: Blog posts must include a description in the metadata, for RSS feeds`
);
}
feed.item({
id,
title: data.title,
author: data.author || '',
date: new Date(data.date),
url: `https://react.dev/blog/${slug}`,
description: data.description,
});
}
}
fs.writeFileSync('./public/rss.xml', feed.xml({indent: true}));
};