Skip to content

Commit 1086673

Browse files
Add RSS feed to the website.
1 parent 05e013c commit 1086673

File tree

10 files changed

+2818
-3260
lines changed

10 files changed

+2818
-3260
lines changed

docusaurus.config.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const config: Config = {
2020
organizationName: "/HaudinFlorence/", // Usually your GitHub org/user name.
2121
projectName: "quantstack.github.io", // Usually your repo name.
2222

23-
onBrokenLinks: "throw",
23+
onBrokenLinks: "warn",
2424
onBrokenMarkdownLinks: "warn",
2525
staticDirectories: ["static"],
2626

@@ -52,6 +52,7 @@ const config: Config = {
5252
},
5353
theme: {
5454
customCss: "./src/css/custom.css",
55+
5556
},
5657
} satisfies Preset.Options,
5758
],
@@ -61,6 +62,17 @@ const config: Config = {
6162
// Replace with your project's social card
6263
//image: 'img/docusaurus-social-card.jpg',
6364
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
65+
headTags: [
66+
{
67+
tagName: 'link',
68+
attributes: {
69+
rel: 'alternate',
70+
type: 'application/rss+xml',
71+
title: 'RSS Feed',
72+
href: '/rss.xml',
73+
},
74+
},
75+
],
6476
navbar: {
6577
title: "",
6678
logo: {
@@ -99,13 +111,22 @@ const config: Config = {
99111
label: "Blog",
100112
position: "left",
101113
},
114+
{
115+
href: 'rss.xml',
116+
position: 'left',
117+
target: '_blank',
118+
rel: 'noopener noreferrer',
119+
className: "rss-icon",
120+
},
102121
{
103122
to: "/contact/",
104123
label: "CONTACT US",
105124
position: "right",
106125
className: "contact",
107126
},
108127

128+
129+
109130
{
110131
to: "https://github.com/QuantStack",
111132
title: "GitHub",

package-lock.json

Lines changed: 40 additions & 3254 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
},
1010
"scripts": {
1111
"docusaurus": "docusaurus",
12-
"prestart": "node scripts/resize-images.js",
13-
"prebuild": "node scripts/resize-images.js",
12+
"prestart": "node scripts/resize-images.js && tsc src/components/blog/blogpostsDetails.ts && node scripts/generate-rss-feed.js",
13+
"prebuild": "node scripts/resize-images.js && tsc src/components/blog/blogpostsDetails.ts && node scripts/generate-rss-feed.js",
1414
"start": "docusaurus start",
1515
"build": "docusaurus build",
1616
"swizzle": "docusaurus swizzle",
@@ -50,6 +50,7 @@
5050
"react-slick": "^0.30.2",
5151
"reactjs-popup": "^2.0.6",
5252
"request": "^2.88.2",
53+
"rss": "^1.2.2",
5354
"sharp": "^0.34.2",
5455
"slick-carousel": "^1.8.1"
5556
},
@@ -58,7 +59,9 @@
5859
"@docusaurus/tsconfig": "3.8.1",
5960
"@docusaurus/types": "3.8.1",
6061
"@types/node": "^20.12.12",
61-
"typescript": "~5.2.2"
62+
"@types/react": "^19.1.8",
63+
"@types/react-dom": "^19.1.6",
64+
"typescript": "^5.8.3"
6265
},
6366
"browserslist": {
6467
"production": [
@@ -75,4 +78,4 @@
7578
"engines": {
7679
"node": "18.x"
7780
}
78-
}
81+
}

scripts/generate-rss-feed.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const fs = require('fs');
2+
const RSS = require('rss');
3+
const { blogpostsDetails } = require('../src/components/blog/blogpostsDetails.js');
4+
const path = require('path');
5+
6+
const outputDir = path.join(__dirname, '../static');
7+
if (!fs.existsSync(outputDir)) {
8+
fs.mkdirSync(outputDir, { recursive: true });
9+
}
10+
11+
const generateFeedFromBlogDetails = (feed, blogpostsDetails, nbOfBlogPosts) => {
12+
let posts = [];
13+
for (let i = 0; i < nbOfBlogPosts; i++) {
14+
const post = blogpostsDetails[i];
15+
posts.push({
16+
title: post.title,
17+
description: post.summary,
18+
date: post.date,
19+
authors: post.authors,
20+
url: post.url,
21+
image: post.image,
22+
23+
})
24+
};
25+
26+
posts.forEach((post) => {
27+
feed.item({
28+
title: post.title,
29+
description: post.description,
30+
url: post.url,
31+
date: post.date,
32+
author: post.authors,
33+
enclosure: {
34+
url: 'https://quantstack.net' + post.image,
35+
type: 'image/png',
36+
length: 0,
37+
},
38+
});
39+
});
40+
return feed;
41+
}
42+
43+
let feedLast20 = new RSS({
44+
title: 'Last 20 blog posts featured by QuantStack team',
45+
description: 'RSS feed for QuantStack website blog page',
46+
feed_url: 'https://quantstack.net/rss.xml',
47+
site_url: 'https://quantstack.net',
48+
language: 'en',
49+
});
50+
51+
const updatedFeedLast20 = generateFeedFromBlogDetails(feedLast20, blogpostsDetails, 20);
52+
fs.writeFileSync(path.join(outputDir, 'rss.xml'), updatedFeedLast20.xml({ indent: true }));
53+
54+
const feedAll = new RSS({
55+
title: 'All blog posts featured by QuantStack team',
56+
description: 'RSS feed for QuantStack website blog page',
57+
feed_url: 'https://quantstack.net/rss_all.xml',
58+
site_url: 'https://quantstack.net',
59+
language: 'en',
60+
});
61+
62+
const updatedFeedAll = generateFeedFromBlogDetails(feedAll, blogpostsDetails, blogpostsDetails.length)
63+
fs.writeFileSync(path.join(outputDir, 'rss_all.xml'), updatedFeedAll.xml({ indent: true }));

0 commit comments

Comments
 (0)