Skip to content

Commit

Permalink
add rss feed generation and link on the website, closes tokio-rs#458 (t…
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs authored Jul 28, 2020
1 parent 4169459 commit ba54a72
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 4 deletions.
6 changes: 4 additions & 2 deletions components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ const Layout: FC<Props> = ({ blog, children }) => (
<Head>
<title>Tokio</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="alternate icon" type="image/png" href="favicon-32x32.png"/>
<link rel="icon" type="image/svg+xml" href="favicon.svg"/>
<link rel="alternate icon" type="image/png" href="favicon-32x32.png" />
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<link rel="alternate" type="application/rss+xml" href="/_next/static/feed.xml" />

<link
href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;600;700&display=swap"
rel="stylesheet"
Expand Down
8 changes: 7 additions & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@
# A basic redirect rule
[[redirects]]
from = "/docs/overview"
to = "/tokio/tutorial"
to = "/tokio/tutorial"

# Redirect previous rss feed location
[[redirects]]
from = "/blog/index.xml"
to = "/_next/static/feed.xml"

15 changes: 15 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
target: "serverless",
webpack: (config, { isServer, dev }) => {
if (isServer && !dev) {
const originalEntry = config.entry;
config.entry = async () => {
const entries = { ...(await originalEntry()) };
entries["./scripts/generate-rss-feed.js"] = "./scripts/generate-rss-feed.js";
return entries;
};
}
return config;
},
};

27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build && next export",
"build": "next build && npm run build:rss && next export",
"build:rss": "node ./.next/serverless/scripts/generate-rss-feed.js",
"start": "next start",
"fmt": "prettier --write --prose-wrap always '{components,content,pages,lib,styles}/**/*.{js,jsx,ts,tsx,scss}'"
},
Expand All @@ -20,6 +21,7 @@
"react-markdown": "^4.3.1",
"react-syntax-highlighter": "^12.2.1",
"remark-custom-blocks": "^2.5.0",
"rss": "^1.2.2",
"sass": "^1.26.5"
},
"devDependencies": {
Expand Down
25 changes: 25 additions & 0 deletions scripts/generate-rss-feed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import RSS from "rss";
import { getDateOrderedPaths } from "../lib/api.js";
import fs from "fs";

const siteUrl = "https://tokio.rs";

function generateRSSFeed() {
const feed = new RSS({
title: "Tokio",
site_url: siteUrl,
});

getDateOrderedPaths("blog").map((post) => {
feed.item({
title: post.title,
guid: post.key,
url: `${siteUrl}${post.href}`,
date: new Date(post.date),
});
});
const rss = feed.xml({ indent: true });
fs.writeFileSync("./.next/static/feed.xml", rss);
}

generateRSSFeed();

0 comments on commit ba54a72

Please sign in to comment.