Skip to content

Commit 69bcd86

Browse files
committed
refactor(website): generate RSS feed from blog posts
Instead of writing out the full RSS feed XML by hand, generate the feed by inspecting the front matter of each blog post. This will make writing future blog posts easier. It also makes the metadata more consistent. Differences in the XML (with whitespace ignored): @@ -30 +33 @@ - <pubDate>05 Jan 2023 12:00:00 PST</pubDate> + <pubDate>05 Jan 2023 21:32:37 -0800</pubDate> @@ -36 +39 @@ - <description>My journey in finding and fixing a bug in a C++ toolchain.</description> + <description>My journey in finding and fixing a bug in a C++ toolchain</description> @@ -38 +41 @@ - <pubDate>25 May 2022 12:00:00 PDT</pubDate> + <pubDate>25 May 2022 21:04:02 -0700</pubDate> @@ -44 +47 @@ - <description>Neovim is one of the most popular code editors, and JavaScript is one of the most popular programming languages. Let's look at some plugins to catch JavaScript bugs immediately in Neovim.</description> + <description>How to install Homebrew, Neovim, and quick-lint-js on macOS to show JavaScript syntax errors while editing</description> @@ -46 +49 @@ - <pubDate>16 Feb 2022 12:00:00 PST</pubDate> + <pubDate>16 Feb 2022 21:48:38 -0800</pubDate> @@ -50 +53 @@ - <title>quick-lint-js release: version 2.0</title> + <title>Reacts rocks with quick-lint-js</title> @@ -54 +57 @@ - <pubDate>04 Feb 2022 12:00:00 PST</pubDate> + <pubDate>04 Feb 2022 21:43:20 -0800</pubDate> @@ -58 +61 @@ - <title>quick-lint-js release: version 1.0</title> + <title>Faster, easier, friendlier: how quick-lint-js will take over ESLint</title> @@ -62 +65 @@ - <pubDate>13 Dec 2021 12:00:00 PST</pubDate> + <pubDate>13 Dec 2021 19:27:37 -0800</pubDate> @@ -66 +69 @@ - <title>JavaScript syntax errors compared</title> + <title>JavaScript syntax errors compared (2021)</title> @@ -68 +71 @@ - <description>A JavaScript error beauty contest</description> + <description>Comparison of errors produced by different JavaScript parsers</description> @@ -70 +73 @@ - <pubDate>11 Dec 2021 12:00:00 PST</pubDate> + <pubDate>11 Dec 2021 17:19:10 -0800</pubDate> @@ -71,0 +75 @@
1 parent a0d2a53 commit 69bcd86

File tree

6 files changed

+51
-54
lines changed

6 files changed

+51
-54
lines changed

website/public/blog/feed.ejs.xml

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22
<!-- Copyright (C) 2020 Matthew "strager" Glazar -->
33
<!-- See end of file for extended copyright information. -->
44
<rss version="2.0">
5+
<% let { loadBlogPostsAsync } = await importFileAsync("./index.mjs"); %>
6+
57
<channel>
68
<title>quick-lint-js blog</title>
79
<link>https://quick-lint-js.com/blog/</link>
810
<description>Technical writings centered around JavaScript and quick-lint-js development</description>
911

10-
<%#
11-
This block should be stripped by EJS.
12-
This block is here just to ensure EJS is working properly.
13-
%>
14-
1512
<language>en-US</language>
1613
<copyright>Copyright (C) 2020 Matthew "strager" Glazar</copyright>
1714
<managingEditor>[email protected] (strager)</managingEditor>
@@ -27,53 +24,15 @@
2724
<height>256</height>
2825
</image>
2926

30-
<item>
31-
<title>Is coding in Rust as bad as in C++?</title>
32-
<link>https://quick-lint-js.com/blog/cpp-vs-rust-build-times/</link>
33-
<description>A practical comparison of build and test speed between C++ and Rust.</description>
34-
<author>[email protected] (strager)</author>
35-
<pubDate>05 Jan 2023 12:00:00 PST</pubDate>
36-
</item>
37-
38-
<item>
39-
<title>Sometimes it *is* a compiler bug</title>
40-
<link>https://quick-lint-js.com/blog/bug-journey/</link>
41-
<description>My journey in finding and fixing a bug in a C++ toolchain.</description>
42-
<author>[email protected] (strager)</author>
43-
<pubDate>25 May 2022 12:00:00 PDT</pubDate>
44-
</item>
45-
46-
<item>
47-
<title>Show JavaScript errors in Neovim on macOS</title>
48-
<link>https://quick-lint-js.com/blog/show-js-errors-neovim-macos/</link>
49-
<description>Neovim is one of the most popular code editors, and JavaScript is one of the most popular programming languages. Let's look at some plugins to catch JavaScript bugs immediately in Neovim.</description>
50-
<author>[email protected] (strager)</author>
51-
<pubDate>16 Feb 2022 12:00:00 PST</pubDate>
52-
</item>
53-
54-
<item>
55-
<title>quick-lint-js release: version 2.0</title>
56-
<link>https://quick-lint-js.com/blog/version-2.0/</link>
57-
<description>We are proud to announce version 2.0 of quick-lint-js!</description>
58-
<author>[email protected] (strager)</author>
59-
<pubDate>04 Feb 2022 12:00:00 PST</pubDate>
60-
</item>
61-
62-
<item>
63-
<title>quick-lint-js release: version 1.0</title>
64-
<link>https://quick-lint-js.com/blog/version-1.0/</link>
65-
<description>Faster, easier, friendlier: how quick-lint-js will take over ESLint</description>
66-
<author>[email protected] (strager)</author>
67-
<pubDate>13 Dec 2021 12:00:00 PST</pubDate>
68-
</item>
69-
70-
<item>
71-
<title>JavaScript syntax errors compared</title>
72-
<link>https://quick-lint-js.com/blog/syntax-errors-2021/</link>
73-
<description>A JavaScript error beauty contest</description>
74-
<author>[email protected] (strager)</author>
75-
<pubDate>11 Dec 2021 12:00:00 PST</pubDate>
76-
</item>
27+
<% for (let post of await loadBlogPostsAsync()) { %>
28+
<item>
29+
<title><%= post.meta.title %></title>
30+
<link>https://quick-lint-js.com/blog/<%= post.dir %>/</link>
31+
<description><%= post.meta.description %></description>
32+
<author>strager.nds@gmail.com (strager)</author>
33+
<pubDate><%= post.timestamp.rfc822 %></pubDate>
34+
</item>
35+
<% } %>
7736
</channel>
7837
</rss>
7938

website/public/blog/index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export async function loadBlogPostsAsync() {
4545
return {
4646
dir: dir.name,
4747
meta: meta,
48+
timestamp: parseTimestamp(meta.blogDate),
4849
};
4950
})
5051
);

website/public/blog/version-1.0/index.ejs.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!---{
22
"title": "Faster, easier, friendlier: how quick-lint-js will take over ESLint",
33
"linkLabelHTML": "Release: version 1.0",
4+
"description": "Faster, easier, friendlier: how quick-lint-js will take over ESLint",
45
"blogDate": "2021-12-13T19:27:37-08:00"
56
}--->
67

website/public/blog/version-2.0/index.ejs.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!---{
22
"title": "Reacts rocks with quick-lint-js",
33
"linkLabelHTML": "Release: version 2.0",
4+
"description": "We are proud to announce version 2.0 of quick-lint-js!",
45
"blogDate": "2022-02-04T21:43:20-08:00"
56
}--->
67

website/src/timestamp.mjs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
11
// Copyright (C) 2020 Matthew "strager" Glazar
22
// See end of file for extended copyright information.
33

4-
// Parses a full ISO 8601 timestamp.
4+
// See: https://www.w3.org/Protocols/rfc822/#z28
5+
let rfc822Months = [
6+
"Jan",
7+
"Feb",
8+
"Mar",
9+
"Apr",
10+
"May",
11+
"Jun",
12+
"Jul",
13+
"Aug",
14+
"Sep",
15+
"Oct",
16+
"Nov",
17+
"Dec",
18+
];
19+
20+
// Parses a subset of ISO 8601 timestamps.
521
//
622
// Example: "2022-05-25T21:04:02-07:00"
723
export function parseTimestamp(timestamp) {
24+
let match = timestamp.match(
25+
/^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})T(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})(?<zoneoffset>[-+]\d{2}:\d{2})$/
26+
);
27+
if (!match) {
28+
throw new Error(`failed to parse timestamp: ${timestamp}`);
29+
}
30+
let { year, month, day, hour, minute, second, zoneoffset } = match.groups;
31+
let monthNumber = parseInt(month, 10);
832
return {
9-
date: timestamp.match(/^[^T]+/)[0],
33+
date: `${year}-${month}-${day}`,
34+
// See: https://www.w3.org/Protocols/rfc822/#z28
35+
rfc822: `${day} ${
36+
rfc822Months[monthNumber - 1]
37+
} ${year} ${hour}:${minute}:${second} ${zoneoffset.replace(":", "")}`,
1038
};
1139
}
1240

website/test/test-timestamp.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ describe("parse timestamp", () => {
1010
"2022-05-25"
1111
);
1212
});
13+
14+
it("gives RFC 822 timestamp in local timezone without day of week", () => {
15+
// This date is 2022-05-26 in UTC.
16+
expect(parseTimestamp("2022-05-25T21:04:02-07:00").rfc822).toEqual(
17+
"25 May 2022 21:04:02 -0700"
18+
);
19+
});
1320
});
1421

1522
// quick-lint-js finds bugs in JavaScript programs.

0 commit comments

Comments
 (0)