Skip to content

Commit f4661cb

Browse files
committed
feat: add RSS feed generation
1 parent 1fa2bbd commit f4661cb

File tree

6 files changed

+86
-5
lines changed

6 files changed

+86
-5
lines changed

assets/styles/styles.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ body {
55
color: #fff;
66
}
77

8+
code {
9+
font-family: 'Courier New', Courier, monospace;
10+
background: rgba(0, 0, 0, 0.2);
11+
font-size: 0.8em;
12+
padding: 0.1em 0.3em;
13+
}
14+
815
* {
916
font-size: 1em;
1017
position: relative;

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"eslint-plugin-prettier": "^3.1.3",
3838
"execa": "^5.0.0",
3939
"favicons-generate": "0.0.15",
40+
"feed": "^4.2.2",
4041
"firebase-tools": "^8.2.0",
4142
"husky": "^4.2.5",
4243
"listr": "^0.14.3",

scripts/generateRssFeed.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import * as fs from 'fs';
2+
import { Feed } from 'feed';
3+
4+
export const generateRssFeed = (
5+
articles: {
6+
title: string;
7+
link: string;
8+
excerpt: string;
9+
body: string;
10+
date: string;
11+
dateObj: Date;
12+
dateNum: number;
13+
}[]
14+
): void => {
15+
const feed = new Feed({
16+
title: 'Ripixel (James King)',
17+
description: 'Feed for thoughts articles',
18+
id: 'https://www.ripixel.co.uk/',
19+
link: 'https://www.ripixel.co.uk/',
20+
language: 'en',
21+
favicon: 'https://www.ripixel.co.uk/favicon.ico',
22+
copyright: `All rights reserved ${new Date()
23+
.getFullYear()
24+
.toString()}, James King`,
25+
feedLinks: {
26+
json: 'https://example.com/json.json',
27+
atom: 'https://example.com/atom.xml',
28+
},
29+
author: {
30+
name: 'James King',
31+
email: 'ripixel+feed@gmail.com',
32+
link: 'https://www.ripixel.co.uk/',
33+
},
34+
});
35+
36+
articles.forEach((article) => {
37+
feed.addItem({
38+
title: article.title,
39+
id: article.link,
40+
link: article.link,
41+
description: article.body,
42+
content: article.body,
43+
date: article.dateObj,
44+
author: [
45+
{
46+
name: 'James King',
47+
email: 'ripixel+feed@gmail.com',
48+
link: 'https://www.ripixel.co.uk/',
49+
},
50+
],
51+
});
52+
});
53+
54+
fs.writeFileSync('./public/rss.xml', feed.rss2(), 'utf8');
55+
fs.writeFileSync('./public/json.json', feed.json1(), 'utf8');
56+
fs.writeFileSync('./public/atom.xml', feed.atom1(), 'utf8');
57+
};

scripts/generateThoughts.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import { format as dateFormat } from 'date-fns';
55

66
import findInDir from './findInDir';
77
import { getWebmentions, webmentionsForPage } from './getWebmentions';
8+
import { generateRssFeed } from './generateRssFeed';
89

910
const ARTICLES_TO_SHOW = 5;
1011

1112
const generateWebmentionBlock = (
12-
tag: string,
13+
tag: 'COMMENTS' | 'LIKES' | 'REPOSTS',
1314
content: string,
1415
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1516
mentions: any[]
@@ -162,8 +163,10 @@ const generateThoughts = async (): Promise<void> => {
162163
const articlesGenerated: Array<{
163164
title: string;
164165
link: string;
166+
excerpt: string;
165167
body: string;
166168
date: string;
169+
dateObj: Date;
167170
dateNum: number;
168171
}> = [];
169172

@@ -173,7 +176,7 @@ const generateThoughts = async (): Promise<void> => {
173176
const articleWithoutFolder = article
174177
.replace('thoughts/articles/', '')
175178
.replace('.md', '.html');
176-
console.log(`Processing article ${articleWithoutFolder}`);
179+
// console.log(`Processing article ${articleWithoutFolder}`);
177180
const [datestring, titleWithDash] = articleWithoutFolder
178181
.replace('.html', '')
179182
.split('_');
@@ -220,8 +223,10 @@ const generateThoughts = async (): Promise<void> => {
220223
link: `${datestring}_${titleWithDash}`,
221224
title,
222225
date,
226+
dateObj,
223227
dateNum: dateObj.valueOf(),
224-
body: `${splitBody[0]}</p>${splitBody[1]}</p>`,
228+
body,
229+
excerpt: `${splitBody[0]}</p>${splitBody[1]}</p>`,
225230
});
226231
});
227232

@@ -254,7 +259,7 @@ const generateThoughts = async (): Promise<void> => {
254259
`${repeatableBlock}`
255260
.replace(`{title}`, articlesGenerated[i].title)
256261
.replace(`{date}`, articlesGenerated[i].date)
257-
.replace(`{body}`, articlesGenerated[i].body)
262+
.replace(`{body}`, articlesGenerated[i].excerpt)
258263
.replace(`{link}`, articlesGenerated[i].link);
259264
}
260265

@@ -270,6 +275,8 @@ const generateThoughts = async (): Promise<void> => {
270275

271276
fs.writeFileSync('./public/thoughts.html', thoughtsPageContents, 'utf8');
272277

278+
generateRssFeed(articlesGenerated);
279+
273280
// console.log('/// Finished generation of thoughts');
274281
};
275282

scripts/getWebmentions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const webmentionsForPage = (
5757
.filter((mention) => mention['wm-target'] === url)
5858
.sort(
5959
(a, b) =>
60-
new Date(b.published).getTime() - new Date(a.published).getTime()
60+
new Date(a.published).getTime() - new Date(b.published).getTime()
6161
)
6262
.map(clean);
6363

0 commit comments

Comments
 (0)