Skip to content

Commit c8cf526

Browse files
committed
fix: more accurate rss
1 parent 622e152 commit c8cf526

3 files changed

Lines changed: 29 additions & 19 deletions

File tree

apps/next-blog/src/utils/generateRSSFeed.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function generateRssFeed(type: 'rss' | 'atom' | 'json' = 'rss') {
3535
allPosts.forEach((post) => {
3636
const url = `https://blog.trialanderror.org/${post.slug}?utm_source=rss&utm_medium=rss&utm_campaign=rss`
3737

38-
const image = post.image?.formats?.medium?.url ?? post.image.url
38+
const image = post.image?.formats?.thumbnail ?? post.image
3939
const author =
4040
[...(post.team_members ?? []), ...(post.blog_authors ?? [])]
4141
.map((member) => {
@@ -53,36 +53,46 @@ export async function generateRssFeed(type: 'rss' | 'atom' | 'json' = 'rss') {
5353
date: new Date(post.publishedAt ?? post.publishDate ?? Date.now()),
5454
link: url,
5555
description: post.excerpt,
56-
guid: post.slug,
56+
guid: url,
5757
content: url,
58-
// image: post.image?.formats?.thumbnail?.url ?? post.image.url,
58+
published: new Date(post.publishedAt ?? post.publishDate ?? Date.now()),
59+
5960
category: [
6061
{
61-
term: post.category?.title,
62+
name: post.category?.title,
6263
},
6364
...(post.blog_tags?.map((tag) => ({
64-
term: tag.title,
65+
name: tag.title,
6566
})) ?? []),
6667
],
67-
// image: 'https://google.com',
6868
...(image
6969
? {
7070
image,
7171
}
7272
: {}),
7373
...(author.length ? { author } : {}),
74+
...(image
75+
? {
76+
extensions: [
77+
{
78+
name: `media:thumbnail width="${image.width}" height="${image.height}" url="${image.url}"`,
79+
},
80+
],
81+
}
82+
: {}),
7483
})
7584
})
85+
feed.addExtension({})
7686

7787
if (type === 'rss') {
7888
return feed.rss2()
7989
}
8090

81-
if (type === 'atom') {
82-
return feed.atom1()
83-
}
91+
// if (type === 'atom') {
92+
// return feed.atom1()
93+
// }
8494

85-
if (type === 'json') {
86-
return feed.json1()
87-
}
95+
// if (type === 'json') {
96+
// return feed.json1()
97+
// }
8898
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"date-fns": "^2.30.0",
4848
"dotenv": "^16.0.3",
4949
"fast-blurhash": "^1.1.2",
50-
"feed": "^4.2.2",
50+
"feed": "^5.1.0",
5151
"fetch-jsonp": "^1.2.3",
5252
"form-data": "^4.0.0",
5353
"framer-motion": "^10.12.8",

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)