Skip to content

Commit a962efe

Browse files
authored
feat(blog): use hive feed for showing blog posts (#1863)
* f * ff * come on it worked with bun * so prettier
1 parent 45723ce commit a962efe

File tree

6 files changed

+78
-16
lines changed

6 files changed

+78
-16
lines changed

pnpm-lock.yaml

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

website/lib/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hive-blog-feed.json

website/lib/all-blogs.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { format } from 'date-fns';
22
import { asArray } from './as-array';
3+
import externalFeed from './hive-blog-feed.json';
34
import { sortByDateDesc } from './sort-by-date';
45
// eslint-disable-next-line import/no-useless-path-segments -- this will exist when we do `next build`
56
import { pageMap } from '.next/static/chunks/nextra-page-map-.mjs';
67

78
const blogFolder = pageMap.find(item => item.name === 'blog' && item.children).children;
89

9-
export const allBlogs = blogFolder
10+
const allInternalBlogs = blogFolder
1011
.filter(item => !item.data && item.route !== '/blog/tag')
1112
.map(blog => {
1213
if (blog.children) {
@@ -51,6 +52,21 @@ export const allBlogs = blogFolder
5152
thumbnail,
5253
canonical,
5354
updateDate: updateDate ? format(new Date(updateDate), 'y-MM-dd') : undefined,
55+
isHive: false,
5456
};
55-
})
56-
.sort(sortByDateDesc);
57+
});
58+
59+
const allExternalBlogs = externalFeed.items.map(item => ({
60+
title: item.title,
61+
description: item.content,
62+
tags: item.categories,
63+
authors: [item.creator],
64+
link: item.link,
65+
image: null,
66+
date: format(new Date(item.isoDate), 'y-MM-dd'),
67+
thumbnail: null,
68+
canonical: item.link,
69+
updateDate: format(new Date(item.isoDate), 'y-MM-dd'),
70+
}));
71+
72+
export const allBlogs = [...allInternalBlogs, ...allExternalBlogs].sort(sortByDateDesc);

website/load-hive-feed.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as fs from 'node:fs';
2+
import RSSParser from 'rss-parser';
3+
4+
const parser = new RSSParser();
5+
6+
await parser
7+
.parseURL('https://the-guild.dev/graphql/hive/blog/feed.xml')
8+
.then(feed =>
9+
fs.writeFileSync(
10+
import.meta.dirname + '/lib/hive-blog-feed.json',
11+
JSON.stringify(feed, null, 2),
12+
),
13+
)
14+
.catch(err => {
15+
console.log(err);
16+
process.exit(1);
17+
});

website/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
"private": true,
77
"scripts": {
88
"analyze": "ANALYZE=true pnpm build",
9-
"build": "pnpm check-links && next build && next-sitemap",
9+
"build": "pnpm load-hive-feed && pnpm check-links && next build && next-sitemap",
1010
"check-links": "tsx check-links.ts",
1111
"dev": "next",
1212
"export": "tsx rss-generator.ts",
13+
"load-hive-feed": "tsx load-hive-feed.ts",
1314
"start": "next start"
1415
},
1516
"dependencies": {
@@ -33,6 +34,7 @@
3334
"react-dom": "18.3.1",
3435
"react-hot-toast": "2.5.2",
3536
"rss": "1.2.2",
37+
"rss-parser": "3.13.0",
3638
"tailwind-merge": "^3.3.1",
3739
"yup": "1.6.1"
3840
},

website/ui/components/blog-card-list.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ export const BlogCardList = ({
3636
lg:[:is(&:hover,&:focus)>img]:h-36
3737
"
3838
>
39-
<img
40-
src={article.thumbnail ?? article.image}
41-
alt="Article logo"
42-
className="h-40 w-full object-cover transition-all duration-500"
43-
/>
4439
<div className="flex grow flex-col p-5">
4540
<Heading size="md" className="line-clamp-3 [hyphens:auto]">
4641
{article.title}
@@ -53,7 +48,7 @@ export const BlogCardList = ({
5348
</Description>
5449
<div className="mt-auto text-xs">
5550
<span className="font-bold dark:text-[#C4C4C4]">
56-
{AUTHORS[article.authors[0]].name}
51+
{AUTHORS[article.authors[0]]?.name ?? article.authors[0]}
5752
</span>
5853
<span className="before:content-['_•_'] dark:text-gray-500">
5954
{format(new Date(article.date), 'LLL do y')}

0 commit comments

Comments
 (0)