forked from reactjs/ru.react.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add rss feed * Add rss feed * rss readers don't like å characters
- Loading branch information
1 parent
f664028
commit cf53cb5
Showing
17 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,6 @@ yarn-error.log* | |
|
||
# external fonts | ||
public/fonts/**/Optimistic_*.woff2 | ||
|
||
# rss | ||
public/rss.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
3 changes: 3 additions & 0 deletions
3
src/content/blog/2020/12/21/data-fetching-with-react-server-components.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/content/blog/2022/06/15/react-labs-what-we-have-been-working-on-june-2022.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/content/blog/2023/03/22/react-labs-what-we-have-been-working-on-march-2023.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...ontent/blog/2024/02/15/react-labs-what-we-have-been-working-on-february-2024.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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})); | ||
}; |