@rspress/plugin-rss 2.0.0-beta.16 → 2.0.0-beta.18
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 +3 -4
- package/dist/index.js +10 -13
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
@@ -21,15 +21,14 @@ export declare interface FeedChannel extends PartialPartial<FeedOptions, 'title'
|
|
21
21
|
* to match pages that should be listed in this feed
|
22
22
|
* if RegExp is given, it will match against the route path of each page
|
23
23
|
**/
|
24
|
-
test: RegExp | string | (RegExp | string)[] | ((item: PageIndexInfo
|
24
|
+
test: RegExp | string | (RegExp | string)[] | ((item: PageIndexInfo) => boolean);
|
25
25
|
/**
|
26
26
|
* a function to modify feed item
|
27
27
|
* @param item pre-generated feed item
|
28
28
|
* @param page page data
|
29
|
-
* @param base base path of the rspress site
|
30
29
|
* @returns modified feed item
|
31
30
|
*/
|
32
|
-
item?: (item: FeedItem, page: PageIndexInfo
|
31
|
+
item?: (item: FeedItem, page: PageIndexInfo) => FeedItem | PromiseLike<FeedItem>;
|
33
32
|
/**
|
34
33
|
* feed level output config
|
35
34
|
*/
|
@@ -151,6 +150,6 @@ declare interface ResolvedOutput {
|
|
151
150
|
sorting: (left: FeedItem, right: FeedItem) => number;
|
152
151
|
}
|
153
152
|
|
154
|
-
export declare function testPage(test: FeedChannel['test'], page: PageIndexInfo
|
153
|
+
export declare function testPage(test: FeedChannel['test'], page: PageIndexInfo): boolean;
|
155
154
|
|
156
155
|
export { }
|
package/dist/index.js
CHANGED
@@ -40,7 +40,7 @@ function generateFeedItem(page, siteUrl) {
|
|
40
40
|
id: selectNonNullishProperty(fm.slug, fm.id, page.routePath) || '',
|
41
41
|
title: selectNonNullishProperty(fm.title, page.title) || '',
|
42
42
|
author: toAuthors(fm.author),
|
43
|
-
link: resolve(siteUrl, selectNonNullishProperty(fm.permalink, page.routePath) || ''),
|
43
|
+
link: resolve(siteUrl, selectNonNullishProperty(fm.permalink, page.routePath)?.replace(/^\//, '') || ''),
|
44
44
|
description: selectNonNullishProperty(fm.description) || '',
|
45
45
|
content: selectNonNullishProperty(fm.summary, page._html) || '',
|
46
46
|
date: toDate(fm.date || fm.published_at),
|
@@ -74,11 +74,11 @@ const PluginName = '@rspress/plugin-rss';
|
|
74
74
|
const PluginComponents = {
|
75
75
|
FeedsAnnotations: '@rspress/plugin-rss/FeedsAnnotations'
|
76
76
|
};
|
77
|
-
function testPage(test, page
|
78
|
-
if (Array.isArray(test)) return test.some((item)=>testPage(item, page
|
79
|
-
if ('function' == typeof test) return test(page
|
77
|
+
function testPage(test, page) {
|
78
|
+
if (Array.isArray(test)) return test.some((item)=>testPage(item, page));
|
79
|
+
if ('function' == typeof test) return test(page);
|
80
80
|
const routePath = page.routePath;
|
81
|
-
const pureRoutePath = `/${routePath
|
81
|
+
const pureRoutePath = `/${routePath}`.replace(/^\/+/, '/');
|
82
82
|
if ('string' == typeof test) return [
|
83
83
|
routePath,
|
84
84
|
pureRoutePath
|
@@ -87,7 +87,7 @@ function testPage(test, page, base = '/') {
|
|
87
87
|
routePath,
|
88
88
|
pureRoutePath
|
89
89
|
].some((path)=>test.test(path));
|
90
|
-
throw new Error('test must be of `RegExp` or `string` or `(page: PageIndexInfo
|
90
|
+
throw new Error('test must be of `RegExp` or `string` or `(page: PageIndexInfo) => boolean`');
|
91
91
|
}
|
92
92
|
function getDefaultFeedOption() {
|
93
93
|
return {
|
@@ -173,10 +173,10 @@ class FeedsSet {
|
|
173
173
|
return this.feeds.slice(0);
|
174
174
|
}
|
175
175
|
}
|
176
|
-
function getRssItems(feeds, page,
|
177
|
-
return Promise.all(feeds.filter((options)=>testPage(options.test, page
|
176
|
+
function getRssItems(feeds, page, siteUrl) {
|
177
|
+
return Promise.all(feeds.filter((options)=>testPage(options.test, page)).map(async (options)=>{
|
178
178
|
const after = options.item || ((feed)=>feed);
|
179
|
-
const item = await after(generateFeedItem(page, siteUrl), page
|
179
|
+
const item = await after(generateFeedItem(page, siteUrl), page);
|
180
180
|
return {
|
181
181
|
...item,
|
182
182
|
channel: options.id
|
@@ -186,7 +186,6 @@ function getRssItems(feeds, page, config, siteUrl) {
|
|
186
186
|
function pluginRss(pluginRssOptions) {
|
187
187
|
const feedsSet = new FeedsSet();
|
188
188
|
let _rssWorkaround = null;
|
189
|
-
let _config;
|
190
189
|
return {
|
191
190
|
name: PluginName,
|
192
191
|
globalUIComponents: Object.values(PluginComponents),
|
@@ -196,12 +195,11 @@ function pluginRss(pluginRssOptions) {
|
|
196
195
|
return;
|
197
196
|
}
|
198
197
|
_rssWorkaround = {};
|
199
|
-
_config = config;
|
200
198
|
feedsSet.set(pluginRssOptions, config);
|
201
199
|
},
|
202
200
|
async extendPageData (pageData) {
|
203
201
|
if (!_rssWorkaround) return;
|
204
|
-
_rssWorkaround[pageData.routePath] = _rssWorkaround[pageData.routePath] || getRssItems(feedsSet.get(), pageData,
|
202
|
+
_rssWorkaround[pageData.routePath] = _rssWorkaround[pageData.routePath] || getRssItems(feedsSet.get(), pageData, pluginRssOptions.siteUrl);
|
205
203
|
const feeds = await _rssWorkaround[pageData.routePath];
|
206
204
|
const showRssList = new Set(concatArray(pageData.frontmatter['link-rss']));
|
207
205
|
for (const feed of feeds)showRssList.add(feed.channel);
|
@@ -229,7 +227,6 @@ function pluginRss(pluginRssOptions) {
|
|
229
227
|
await writeFile(path, output.getContent(feed));
|
230
228
|
}
|
231
229
|
_rssWorkaround = null;
|
232
|
-
_config = null;
|
233
230
|
}
|
234
231
|
};
|
235
232
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rspress/plugin-rss",
|
3
|
-
"version": "2.0.0-beta.
|
3
|
+
"version": "2.0.0-beta.18",
|
4
4
|
"description": "A plugin for rss generation for rspress",
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
6
6
|
"repository": {
|
@@ -25,19 +25,19 @@
|
|
25
25
|
],
|
26
26
|
"dependencies": {
|
27
27
|
"feed": "^4.2.2",
|
28
|
-
"@rspress/shared": "2.0.0-beta.
|
28
|
+
"@rspress/shared": "2.0.0-beta.18"
|
29
29
|
},
|
30
30
|
"devDependencies": {
|
31
|
-
"@rslib/core": "0.10.
|
31
|
+
"@rslib/core": "0.10.3",
|
32
32
|
"@types/node": "^22.8.1",
|
33
33
|
"@types/react": "^19.1.8",
|
34
34
|
"react": "^19.1.0",
|
35
35
|
"rsbuild-plugin-publint": "^0.3.2",
|
36
36
|
"typescript": "^5.8.2",
|
37
|
-
"@rspress/runtime": "2.0.0-beta.
|
37
|
+
"@rspress/runtime": "2.0.0-beta.18"
|
38
38
|
},
|
39
39
|
"peerDependencies": {
|
40
|
-
"rspress": "^2.0.0-beta.
|
40
|
+
"rspress": "^2.0.0-beta.18"
|
41
41
|
},
|
42
42
|
"engines": {
|
43
43
|
"node": ">=18.0.0"
|