Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default defineConfig([
globalIgnores([
"**/dist/",
"**/examples/",
"**/printable.mdx",
"src/content/loaders/_*.mdx",
"src/content/plugins/_*.mdx",
"src/content/contribute/Governance-*.mdx",
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"fetch-all": "run-s fetch-repos fetch",
"prebuild": "npm run clean",
"build": "run-s fetch-repos fetch:governance fetch content && webpack --config webpack.prod.mjs --config-node-env production && run-s printable content && webpack --config webpack.ssg.mjs --config-node-env production --env ssg",
"postbuild": "npm run sitemap",
"postbuild": "npm run sitemap && npm run rss",
"build-test": "npm run build && http-server --port 4200 dist/",
"serve-dist": "http-server --port 4200 dist/",
"test": "npm run lint",
Expand All @@ -47,6 +47,7 @@
"lint:prose": "vale --config='.vale.ini' src/content",
"lint:links": "hyperlink -c 8 --root dist -r dist/index.html --canonicalroot https://webpack.js.org/ --internal --skip /plugins/extract-text-webpack-plugin/ --skip /printable --skip /contribute/Governance --skip https:// --skip http:// --skip sw.js --skip /vendor > internal-links.tap; cat internal-links.tap | tap-spot",
"sitemap": "cd dist && sitemap-static --ignore-file=../sitemap-ignore.json --pretty --prefix=https://webpack.js.org/ > sitemap.xml",
"rss": "node src/scripts/generate-rss.mjs",
"serve": "npm run build && sirv start ./dist --port 4000",
"preprintable": "npm run clean-printable",
"printable": "node ./src/scripts/concatenate-docs.mjs",
Expand Down Expand Up @@ -105,6 +106,7 @@
"cypress": "^15.9.0",
"directory-tree": "^3.6.0",
"directory-tree-webpack-plugin": "^1.0.3",
"feed": "^5.0.0",
"duplexer": "^0.1.1",
"eslint": "^9.39.2",
"eslint-config-webpack": "^4.9.3",
Expand Down
6 changes: 6 additions & 0 deletions src/components/Site/Site.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ function Site(props) {
location.pathname,
)}`}
/>
<link
rel="alternate"
type="application/rss+xml"
title="webpack Blog"
href="https://webpack.js.org/feed.xml"
/>
<meta name="mobile-web-app-capable" content="yes" />
<link rel="icon" sizes="192x192" href="/icon_192x192.png" />
<link rel="icon" sizes="512x512" href="/icon_512x512.png" />
Expand Down
94 changes: 94 additions & 0 deletions src/scripts/generate-rss.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { Feed } from "feed";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.resolve(__dirname, "../..");
const BASE_URL = "https://webpack.js.org";

function extractPubDate(node) {
const name = node.name || "";

const filenameDateMatch = name.match(/^(\d{4}-\d{2}-\d{2})-/);
if (filenameDateMatch) {
const date = new Date(filenameDateMatch[1]);
if (!Number.isNaN(date.getTime())) return date;
}

const title = node.title || "";
const titleDateMatch = title.match(/\((\d{4}-\d{2}-\d{2})\)/);
if (titleDateMatch) {
const date = new Date(titleDateMatch[1]);
if (!Number.isNaN(date.getTime())) return date;
}

const filePath = path.resolve(ROOT, node.path);
try {
const stat = fs.statSync(filePath);
return stat.mtime;
} catch {
return new Date();
}
}

function main() {
const contentPath = path.resolve(ROOT, "src/_content.json");
const contentTree = JSON.parse(fs.readFileSync(contentPath, "utf8"));

const blogSection = contentTree.children?.find(
(child) => child.name === "blog" && child.type === "directory",
);

if (!blogSection?.children) {
throw new Error("generate-rss: blog section not found in content tree");
}

const posts = blogSection.children
.filter(
(child) =>
child.type === "file" &&
(child.extension === ".mdx" || child.extension === ".md") &&
child.name !== "index.mdx" &&
child.name !== "index.md" &&
child.name !== "printable.mdx" &&
child.name !== "printable.md" &&
child.url !== "/blog/" &&
!child.url?.includes("/printable"),
)
.map((node) => ({
title: node.title || "Untitled",
link: `${BASE_URL}${node.url}`,
date: extractPubDate(node),
description: node.description || node.title || "Untitled",
}))
.toSorted((a, b) => b.date.getTime() - a.date.getTime());

const feed = new Feed({
title: "webpack Blog",
description: "Announcements and updates from the webpack team",
id: `${BASE_URL}/blog/`,
link: `${BASE_URL}/blog/`,
language: "en",
updated: new Date(),
feedLinks: {
rss: `${BASE_URL}/feed.xml`,
},
});

for (const post of posts) {
feed.addItem({
title: post.title,
link: post.link,
description: post.description,
date: post.date,
id: post.link,
});
}

const distPath = path.resolve(ROOT, "dist/feed.xml");
fs.writeFileSync(distPath, feed.rss2(), "utf8");
console.log(`Successfully generated RSS feed at ${distPath}`);
}

main();
22 changes: 18 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6626,6 +6626,13 @@ fdir@^6.5.0:
resolved "https://registry.yarnpkg.com/fdir/-/fdir-6.5.0.tgz#ed2ab967a331ade62f18d077dae192684d50d350"
integrity sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==

feed@^5.0.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/feed/-/feed-5.2.0.tgz#f5cf2cb7395f64614017557764bdf49fe1a3d69a"
integrity sha512-hgH6CCb+7+0c8PBlakI2KubG6R+Rb1MhpNcdvqUXZTBwBHf32piwY255diAkAmkGZ6AWlywOU88AkOgP9q8Rdw==
dependencies:
xml-js "^1.6.11"

figures@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/figures/-/figures-3.2.0.tgz#625c18bd293c604dc4a8ddb2febf0c88341746af"
Expand Down Expand Up @@ -12400,10 +12407,10 @@ sass@^1.97.2:
optionalDependencies:
"@parcel/watcher" "^2.4.1"

sax@>=0.6.0:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
sax@>=0.6.0, sax@^1.2.4:
version "1.4.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.4.4.tgz#f29c2bba80ce5b86f4343b4c2be9f2b96627cf8b"
integrity sha512-1n3r/tGXO6b6VXMdFT54SHzT9ytu9yr7TaELowdYpMqY/Ao7EnlQGmAQ1+RatX7Tkkdm6hONI2owqNx2aZj5Sw==

saxes@^5.0.1:
version "5.0.1"
Expand Down Expand Up @@ -15109,6 +15116,13 @@ xhr@^2.0.1:
parse-headers "^2.0.0"
xtend "^4.0.0"

xml-js@^1.6.11:
version "1.6.11"
resolved "https://registry.yarnpkg.com/xml-js/-/xml-js-1.6.11.tgz#927d2f6947f7f1c19a316dd8eea3614e8b18f8e9"
integrity sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==
dependencies:
sax "^1.2.4"

xml-name-validator@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"
Expand Down
Loading