Skip to content

Commit

Permalink
Add rss feed (#6803)
Browse files Browse the repository at this point in the history
* Add rss feed

* Add rss feed

* rss readers don't like å characters
  • Loading branch information
rickhanlonii authored Apr 26, 2024
1 parent f664028 commit cf53cb5
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ yarn-error.log*

# external fonts
public/fonts/**/Optimistic_*.woff2

# rss
public/rss.xml
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions scripts/generateRss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*/
const {generateRssFeed} = require('../src/utils/rss');

generateRssFeed();
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/content/blog/2021/06/08/the-plan-for-react-18.md
Original file line number Diff line number Diff line change
@@ -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. We’ve started work on the React 18 release, which will be our next major version. We’ve created a Working Group to prepare the community for gradual adoption of new features in React 18. We’ve 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)
Expand Down
3 changes: 3 additions & 0 deletions src/content/blog/2021/12/17/react-conf-2021-recap.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/content/blog/2022/03/08/react-18-upgrade-guide.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/content/blog/2022/03/29/react-v18.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 we’ve learned is that it’s frustrating for the community to wait for new features without having insight into these paths that we’re 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)
Expand Down
3 changes: 3 additions & 0 deletions src/content/blog/2023/03/16/introducing-react-dev.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/content/blog/2023/05/03/react-canaries.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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. We’ve made significant progress since our last update, and we’d 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).
Expand Down
3 changes: 3 additions & 0 deletions src/content/blog/2024/04/25/react-19-upgrade-guide.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/content/blog/2024/04/25/react-19.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/pages/[[...markdownPath]].js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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/';

Expand Down
82 changes: 82 additions & 0 deletions src/utils/rss.js
Original file line number Diff line number Diff line change
@@ -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}));
};

0 comments on commit cf53cb5

Please sign in to comment.