Skip to content

Commit 576a67a

Browse files
committed
refactor: roll our own feed loader
1 parent feabcd5 commit 576a67a

File tree

5 files changed

+44
-58
lines changed

5 files changed

+44
-58
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"format:check": "prettier . --check"
1313
},
1414
"dependencies": {
15-
"@ascorbic/feed-loader": "^2.0.1",
1615
"@astrojs/markdown-remark": "^7.0.0",
1716
"@astrojs/starlight": "^0.38.1",
1817
"@astrojs/svelte": "^8.0.1",
@@ -36,6 +35,7 @@
3635
"@types/mdast": "^4.0.4",
3736
"@types/node": "^25.5.0",
3837
"dead-or-alive": "^1.0.4",
38+
"feedsmith": "3.0.0-next.6",
3939
"prettier": "3.8.1",
4040
"prettier-plugin-astro": "0.14.1",
4141
"prettier-plugin-organize-imports": "^4.3.0",

pnpm-lock.yaml

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

src/components/changelog/Release.astro

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,26 @@ interface Props {
88
}
99
1010
const { id, entry } = Astro.props;
11-
const { Content } = await render(entry);
1211
---
1312

1413
<article>
15-
<AnchorHeading {id} level={2}>{entry.data.title}</AnchorHeading>
14+
<AnchorHeading {id} level={2}>{entry.data.title.value}</AnchorHeading>
1615
<p class="description">
1716
Released on {
18-
(entry.data.published ?? entry.data.updated)?.toLocaleDateString("en", {
17+
new Date(entry.data.published ?? entry.data.updated).toLocaleDateString("en", {
1918
dateStyle: "medium",
2019
timeZone: "UTC",
21-
}) ?? "-"
20+
})
2221
}
2322
{
24-
entry.data.url && (
23+
entry.data.links?.[0] && (
2524
<>
26-
- <a href={entry.data.url}>GitHub</a>
25+
- <a href={entry.data.links[0].href}>GitHub</a>
2726
</>
2827
)
2928
}
3029
</p>
31-
<Content />
30+
<Fragment set:html={entry.data.content.value} />
3231
</article>
3332

3433
<style>

src/components/changelog/Releases.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ interface Props {
1010
1111
const { title, collection } = Astro.props;
1212
13-
const entries = await getCollection(collection);
13+
const entries = (await getCollection(collection)).sort((a, b) => a.data.index - b.data.index);
1414
const headings = entries.map((entry) => {
1515
const id = entry.id.substring(entry.id.lastIndexOf("/") + 1);
1616
1717
return {
1818
slug: id,
19-
text: entry.data.title ?? id,
19+
text: entry.data.title.value ?? id,
2020
depth: 2,
2121
};
2222
});

src/content.config.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
import { feedLoader } from "@ascorbic/feed-loader";
21
import { docsLoader } from "@astrojs/starlight/loaders";
32
import { docsSchema } from "@astrojs/starlight/schema";
4-
import { defineCollection, z } from "astro:content";
3+
import { z } from "astro/zod";
4+
import { defineCollection } from "astro:content";
5+
import { parseAtomFeed, type Atom } from "feedsmith";
6+
7+
const feedLoader = (url: string): (() => Promise<(Atom.Entry<string> & { id: string })[]>) => {
8+
return async () => {
9+
const response = await fetch(url);
10+
if (!response.ok) {
11+
throw new Error(`Failed to fetch feed from ${url}: ${response.statusText}`);
12+
}
13+
14+
const feed = parseAtomFeed(await response.text());
15+
return feed.entries!.map((e, i) => ({ ...e, id: e.id!, index: i }));
16+
};
17+
};
518

619
export const collections = {
720
docs: defineCollection({
@@ -18,18 +31,12 @@ export const collections = {
1831
}),
1932
}),
2033
"adventure-releases": defineCollection({
21-
loader: feedLoader({
22-
url: "https://github.com/PaperMC/adventure/releases.atom",
23-
}),
34+
loader: feedLoader("https://github.com/PaperMC/adventure/releases.atom"),
2435
}),
2536
"adventure-platform-releases": defineCollection({
26-
loader: feedLoader({
27-
url: "https://github.com/PaperMC/adventure-platform/releases.atom",
28-
}),
37+
loader: feedLoader("https://github.com/PaperMC/adventure-platform/releases.atom"),
2938
}),
3039
"adventure-platform-mod-releases": defineCollection({
31-
loader: feedLoader({
32-
url: "https://github.com/PaperMC/adventure-platform-mod/releases.atom",
33-
}),
40+
loader: feedLoader("https://github.com/PaperMC/adventure-platform-mod/releases.atom"),
3441
}),
3542
};

0 commit comments

Comments
 (0)