@rspress/plugin-rss 2.0.5 → 2.0.7
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 +16 -1
- package/dist/index.js +17 -5
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export declare interface FeedChannel extends PartialPartial<FeedOptions, 'title'
|
|
|
28
28
|
* @param page page data
|
|
29
29
|
* @returns modified feed item
|
|
30
30
|
*/
|
|
31
|
-
item?: (item: FeedItem, page: PageIndexInfo) => FeedItem | PromiseLike<FeedItem>;
|
|
31
|
+
item?: (item: FeedItem, page: PageIndexInfo, siteUrl: string) => FeedItem | PromiseLike<FeedItem>;
|
|
32
32
|
/**
|
|
33
33
|
* feed level output config
|
|
34
34
|
*/
|
|
@@ -62,8 +62,20 @@ export declare interface FeedOutputOptions {
|
|
|
62
62
|
* sort feed items
|
|
63
63
|
*/
|
|
64
64
|
sorting?: (left: FeedItem, right: FeedItem) => number;
|
|
65
|
+
/**
|
|
66
|
+
* transform the final generated feed content before it is written to disk.
|
|
67
|
+
*/
|
|
68
|
+
transform?: FeedOutputTransformer;
|
|
65
69
|
}
|
|
66
70
|
|
|
71
|
+
export declare interface FeedOutputTransformContext {
|
|
72
|
+
type: FeedOutputType;
|
|
73
|
+
feed: Feed;
|
|
74
|
+
channel: FeedChannel;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export declare type FeedOutputTransformer = (content: string, context: FeedOutputTransformContext) => string | PromiseLike<string>;
|
|
78
|
+
|
|
67
79
|
/**
|
|
68
80
|
* output feed file type
|
|
69
81
|
*/
|
|
@@ -140,6 +152,8 @@ export declare interface PluginRssOptions {
|
|
|
140
152
|
output?: Omit<FeedOutputOptions, 'filename'>;
|
|
141
153
|
}
|
|
142
154
|
|
|
155
|
+
export declare function renderFeedContent(feed: Feed, channel: FeedChannel, output: ResolvedOutput): Promise<string>;
|
|
156
|
+
|
|
143
157
|
declare interface ResolvedOutput {
|
|
144
158
|
type: FeedOutputType;
|
|
145
159
|
mime: string;
|
|
@@ -149,6 +163,7 @@ declare interface ResolvedOutput {
|
|
|
149
163
|
publicPath: string;
|
|
150
164
|
url: string;
|
|
151
165
|
sorting: (left: FeedItem, right: FeedItem) => number;
|
|
166
|
+
transform?: FeedOutputTransformer;
|
|
152
167
|
}
|
|
153
168
|
|
|
154
169
|
export declare function testPage(test: FeedChannel['test'], page: PageIndexInfo): boolean;
|
package/dist/index.js
CHANGED
|
@@ -137,6 +137,15 @@ function getFeedFileType(type) {
|
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
+
async function renderFeedContent(feed, channel, output) {
|
|
141
|
+
const content = output.getContent(feed);
|
|
142
|
+
if (!output.transform) return content;
|
|
143
|
+
return output.transform(content, {
|
|
144
|
+
type: output.type,
|
|
145
|
+
feed,
|
|
146
|
+
channel
|
|
147
|
+
});
|
|
148
|
+
}
|
|
140
149
|
function getOutputInfo({ id, output }, { siteUrl, output: globalOutput }) {
|
|
141
150
|
const type = output?.type || globalOutput?.type || 'atom';
|
|
142
151
|
const { extension, mime, getContent } = getFeedFileType(type);
|
|
@@ -149,6 +158,7 @@ function getOutputInfo({ id, output }, { siteUrl, output: globalOutput }) {
|
|
|
149
158
|
filename
|
|
150
159
|
].reduce((u, part)=>u ? resolve(u, part) : part);
|
|
151
160
|
const sorting = output?.sorting || globalOutput?.sorting || ((l, r)=>sortByDate(l.date, r.date));
|
|
161
|
+
const transform = output?.transform || globalOutput?.transform;
|
|
152
162
|
return {
|
|
153
163
|
type,
|
|
154
164
|
mime,
|
|
@@ -157,7 +167,8 @@ function getOutputInfo({ id, output }, { siteUrl, output: globalOutput }) {
|
|
|
157
167
|
dir,
|
|
158
168
|
publicPath,
|
|
159
169
|
url,
|
|
160
|
-
sorting
|
|
170
|
+
sorting,
|
|
171
|
+
transform
|
|
161
172
|
};
|
|
162
173
|
}
|
|
163
174
|
class FeedsSet {
|
|
@@ -195,7 +206,7 @@ class FeedsSet {
|
|
|
195
206
|
async function getRssItems(feeds, page, siteUrl, htmlContent) {
|
|
196
207
|
return Promise.all(feeds.filter((options)=>testPage(options.test, page)).map(async (options)=>{
|
|
197
208
|
const after = options.item || ((feed)=>feed);
|
|
198
|
-
const item = await after(generateFeedItem(page, siteUrl, htmlContent), page);
|
|
209
|
+
const item = await after(generateFeedItem(page, siteUrl, htmlContent), page, siteUrl);
|
|
199
210
|
return {
|
|
200
211
|
...item,
|
|
201
212
|
channel: options.id
|
|
@@ -253,13 +264,14 @@ function pluginRss(pluginRssOptions) {
|
|
|
253
264
|
}
|
|
254
265
|
}
|
|
255
266
|
for (const [channel, feed] of Object.entries(feeds)){
|
|
256
|
-
const
|
|
267
|
+
const feedChannel = feedsSet.get(channel);
|
|
268
|
+
const { output } = feedChannel;
|
|
257
269
|
feed.items.sort(output.sorting);
|
|
258
270
|
const path = node_path.resolve(outDir, output.dir, output.filename);
|
|
259
|
-
await writeFile(path,
|
|
271
|
+
await writeFile(path, await renderFeedContent(feed, feedChannel, output));
|
|
260
272
|
}
|
|
261
273
|
_pagesForRss = null;
|
|
262
274
|
}
|
|
263
275
|
};
|
|
264
276
|
}
|
|
265
|
-
export { PluginComponents, PluginName, createFeed, generateFeedItem, getDefaultFeedOption, getFeedFileType, getOutputInfo, pluginRss, testPage };
|
|
277
|
+
export { PluginComponents, PluginName, createFeed, generateFeedItem, getDefaultFeedOption, getFeedFileType, getOutputInfo, pluginRss, renderFeedContent, testPage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/plugin-rss",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"description": "A plugin for rss generation for rspress",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"feed": "^5.2.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@rslib/core": "0.
|
|
31
|
+
"@rslib/core": "0.20.0",
|
|
32
32
|
"@types/node": "^22.8.1",
|
|
33
33
|
"@types/react": "^19.2.14",
|
|
34
34
|
"react": "^19.2.4",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"typescript": "^5.8.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@rspress/core": "^2.0.
|
|
39
|
+
"@rspress/core": "^2.0.7"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": "^20.19.0 || >=22.12.0"
|