@barodoc/plugin-rss 6.0.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +10 -0
- package/dist/index.js +41 -0
- package/package.json +7 -5
- package/src/feed.ts +49 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _barodoc_core from '@barodoc/core';
|
|
2
|
+
|
|
3
|
+
interface RssPluginOptions {
|
|
4
|
+
title?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
collections?: ("blog" | "changelog")[];
|
|
7
|
+
}
|
|
8
|
+
declare const _default: (options: RssPluginOptions) => _barodoc_core.BarodocPlugin;
|
|
9
|
+
|
|
10
|
+
export { type RssPluginOptions, _default as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { definePlugin } from "@barodoc/core";
|
|
3
|
+
var index_default = definePlugin((options = {}) => {
|
|
4
|
+
const {
|
|
5
|
+
title,
|
|
6
|
+
description = "Latest updates",
|
|
7
|
+
collections = ["blog"]
|
|
8
|
+
} = options;
|
|
9
|
+
return {
|
|
10
|
+
name: "@barodoc/plugin-rss",
|
|
11
|
+
astroIntegration: (context) => {
|
|
12
|
+
const siteUrl = context.config.site;
|
|
13
|
+
if (!siteUrl) {
|
|
14
|
+
console.warn("[rss] No 'site' configured in barodoc.config.json \u2014 RSS links will use localhost");
|
|
15
|
+
}
|
|
16
|
+
const integration = {
|
|
17
|
+
name: "@barodoc/plugin-rss",
|
|
18
|
+
hooks: {
|
|
19
|
+
"astro:config:setup": ({ injectRoute }) => {
|
|
20
|
+
injectRoute({
|
|
21
|
+
pattern: "/rss.xml",
|
|
22
|
+
entrypoint: "@barodoc/plugin-rss/feed-endpoint"
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return integration;
|
|
28
|
+
},
|
|
29
|
+
hooks: {
|
|
30
|
+
"config:loaded": (config) => {
|
|
31
|
+
return {
|
|
32
|
+
...config,
|
|
33
|
+
_rss: { title: title || config.name, description, collections }
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
export {
|
|
40
|
+
index_default as default
|
|
41
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barodoc/plugin-rss",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "RSS feed plugin for Barodoc",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -9,24 +9,26 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"import": "./dist/index.js"
|
|
12
|
-
}
|
|
12
|
+
},
|
|
13
|
+
"./feed-endpoint": "./src/feed.ts"
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
|
-
"dist"
|
|
16
|
+
"dist",
|
|
17
|
+
"src/feed.ts"
|
|
16
18
|
],
|
|
17
19
|
"dependencies": {
|
|
18
20
|
"@astrojs/rss": "^4.0.0"
|
|
19
21
|
},
|
|
20
22
|
"peerDependencies": {
|
|
21
23
|
"astro": "^5.0.0",
|
|
22
|
-
"@barodoc/core": "
|
|
24
|
+
"@barodoc/core": "8.0.0"
|
|
23
25
|
},
|
|
24
26
|
"devDependencies": {
|
|
25
27
|
"@types/node": "^22.0.0",
|
|
26
28
|
"astro": "^5.0.0",
|
|
27
29
|
"tsup": "^8.3.0",
|
|
28
30
|
"typescript": "^5.7.0",
|
|
29
|
-
"@barodoc/core": "
|
|
31
|
+
"@barodoc/core": "8.0.0"
|
|
30
32
|
},
|
|
31
33
|
"license": "MIT",
|
|
32
34
|
"scripts": {
|
package/src/feed.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import rss from "@astrojs/rss";
|
|
2
|
+
import type { APIContext } from "astro";
|
|
3
|
+
// @ts-ignore - virtual module provided by @barodoc/core
|
|
4
|
+
import config from "virtual:barodoc/config";
|
|
5
|
+
|
|
6
|
+
export async function GET(context: APIContext) {
|
|
7
|
+
const rssConfig = (config as any)._rss ?? {};
|
|
8
|
+
const feedTitle = rssConfig.title ?? config.name ?? "Documentation";
|
|
9
|
+
const feedDescription = rssConfig.description ?? "Latest updates";
|
|
10
|
+
const site = context.site ?? (config.site ? new URL(config.site) : new URL("http://localhost:4321"));
|
|
11
|
+
|
|
12
|
+
let items: { title: string; pubDate: Date; link: string; description?: string }[] = [];
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const { getCollection } = await import("astro:content");
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const blogs = await getCollection("blog");
|
|
19
|
+
for (const post of blogs) {
|
|
20
|
+
items.push({
|
|
21
|
+
title: post.data.title,
|
|
22
|
+
pubDate: post.data.date ? new Date(post.data.date) : new Date(),
|
|
23
|
+
link: `/blog/${post.slug ?? post.id}`,
|
|
24
|
+
description: post.data.description || post.data.excerpt || "",
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
} catch {}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const changelogs = await getCollection("changelog");
|
|
31
|
+
for (const entry of changelogs) {
|
|
32
|
+
items.push({
|
|
33
|
+
title: `${entry.data.version}${entry.data.title ? ` - ${entry.data.title}` : ""}`,
|
|
34
|
+
pubDate: new Date(entry.data.date),
|
|
35
|
+
link: `/changelog#${entry.data.version}`,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
} catch {}
|
|
39
|
+
} catch {}
|
|
40
|
+
|
|
41
|
+
items.sort((a, b) => b.pubDate.getTime() - a.pubDate.getTime());
|
|
42
|
+
|
|
43
|
+
return rss({
|
|
44
|
+
title: feedTitle,
|
|
45
|
+
description: feedDescription,
|
|
46
|
+
site: site.toString(),
|
|
47
|
+
items,
|
|
48
|
+
});
|
|
49
|
+
}
|