Skip to content

Commit 3791386

Browse files
committed
add a shrimple rss aggregator
1 parent 59cba77 commit 3791386

5 files changed

Lines changed: 142 additions & 1 deletion

File tree

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The Graphics Programming Blog - A collection of technical articles, project post
55
## Things which work
66
- You can create articles and project posts
77
- LaTeX/KaTeX works
8+
- Blog feed aggregator
89

910
## Things which don't work yet
1011
- Search
@@ -54,7 +55,45 @@ The Graphics Programming Blog - A collection of technical articles, project post
5455
```bash
5556
cd blog
5657
npm i
57-
npm run start
58+
npm run start
5859
```
5960

6061
- `http://localhost:3000` should open automatically
62+
63+
## Adding a blog feed
64+
65+
This site can aggregate blogs from around the web! Here's how to get in on that:
66+
67+
- fork the repo and clone your fork
68+
- add your blog's RSS feed to the `plugins.data` field of `docusaurus.config.ts`
69+
70+
```typescript
71+
plugins: [
72+
[
73+
'@1password/docusaurus-plugin-stored-data',
74+
{
75+
data: {
76+
"Froyok Dev Blog": "https://www.froyok.fr/rss.xml",
77+
your blog goes here! example:
78+
"the flyswatter weekly": "https://example.com/flyswatter/rss.xml"
79+
}
80+
}
81+
],
82+
],
83+
```
84+
85+
- add your blog to the `dataSources` field in `src/components/HomepageFeatures/index.tsx`:
86+
87+
```typescript
88+
const FeedItems = () => {
89+
const dataSources = [
90+
useStoredFeed("Froyok Dev Blog"),
91+
useStoredFeed("the flywratter weekly"),
92+
];
93+
```
94+
95+
- and that's it! make a pull request and your RSS feed will be automatically added to the blog feed!
96+
97+
### WARNING
98+
99+
The blog aggregator ONLY supports RSS. Atom feeds are unsupported

docusaurus.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ const config: Config = {
3232
languages: ["en"], // language codes
3333
},
3434
],
35+
[
36+
'@1password/docusaurus-plugin-stored-data',
37+
{
38+
data: {
39+
"Froyok Dev Blog": "https://www.froyok.fr/rss.xml",
40+
}
41+
}
42+
],
3543
],
3644

3745
// Even if you don't use internationalization, you can use this field to set

package-lock.json

Lines changed: 49 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
@@ -15,6 +15,7 @@
1515
"typecheck": "tsc"
1616
},
1717
"dependencies": {
18+
"@1password/docusaurus-plugin-stored-data": "^1.0.0",
1819
"@docusaurus/core": "3.5.2",
1920
"@docusaurus/preset-classic": "3.5.2",
2021
"@mdx-js/react": "^3.0.0",

src/components/HomepageFeatures/index.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import clsx from 'clsx';
22
import Heading from '@theme/Heading';
33
import styles from './styles.module.css';
4+
import useStoredFeed from "@theme/useStoredFeed";
45

56
type FeatureItem = {
67
title: string;
@@ -25,6 +26,43 @@ function Feature({title, Svg, description}: FeatureItem) {
2526
);
2627
}
2728

29+
interface BlogItem {
30+
source: string;
31+
guid: string;
32+
title: string;
33+
pubDate: Date;
34+
link: string;
35+
}
36+
37+
const FeedItems = () => {
38+
const dataSources = [
39+
useStoredFeed("Froyok Dev Blog"),
40+
];
41+
42+
const feedData: BlogItem[] = [];
43+
44+
// merge the feeds into one
45+
dataSources.forEach((source) => source.item.forEach(({guid, title, pubDate, link}) => feedData.push({
46+
source: source.title,
47+
guid,
48+
title,
49+
pubDate: new Date(Date.parse(pubDate)),
50+
link
51+
})));
52+
53+
// sort by date
54+
feedData.sort((itema: BlogItem, itemb: BlogItem) => (itema.pubDate < itemb.pubDate ? 1 : -1));
55+
56+
// render
57+
return (
58+
<ul>
59+
{feedData.slice(0, 9).map((item: BlogItem) => (
60+
<li key={item.guid}><a href={item.link}>{item.source}: {item.title} ({item.pubDate.toLocaleDateString()})</a></li>
61+
))}
62+
</ul>
63+
);
64+
};
65+
2866
export default function HomepageFeatures(): JSX.Element {
2967
return (
3068
<section className={styles.features}>
@@ -34,6 +72,12 @@ export default function HomepageFeatures(): JSX.Element {
3472
<Feature key={idx} {...props} />
3573
))}
3674
</div>
75+
<div className="row">
76+
<h2>The latest news from around the swamp:</h2>
77+
<p>
78+
<FeedItems />
79+
</p>
80+
</div>
3781
</div>
3882
</section>
3983
);

0 commit comments

Comments
 (0)