@rspress/plugin-rss 2.0.6 → 2.0.8

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 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
@@ -1,8 +1,9 @@
1
1
  import { resolve } from "node:url";
2
2
  import { promises } from "node:fs";
3
- import node_path, { dirname } from "node:path";
3
+ import node_path from "node:path";
4
4
  import { getIconUrlPath } from "@rspress/core";
5
5
  import { Feed } from "feed";
6
+ import * as __rspack_external_node_path_c5b9b54f from "node:path";
6
7
  function notNullish(n) {
7
8
  return null != n;
8
9
  }
@@ -27,7 +28,7 @@ function sortByDate(l, r) {
27
28
  return (r ? r.getTime() : 0) - (l ? l.getTime() : 0);
28
29
  }
29
30
  async function writeFile(path, content) {
30
- const dir = dirname(path);
31
+ const dir = __rspack_external_node_path_c5b9b54f.dirname(path);
31
32
  await promises.mkdir(dir, {
32
33
  mode: 493,
33
34
  recursive: true
@@ -137,6 +138,15 @@ function getFeedFileType(type) {
137
138
  };
138
139
  }
139
140
  }
141
+ async function renderFeedContent(feed, channel, output) {
142
+ const content = output.getContent(feed);
143
+ if (!output.transform) return content;
144
+ return output.transform(content, {
145
+ type: output.type,
146
+ feed,
147
+ channel
148
+ });
149
+ }
140
150
  function getOutputInfo({ id, output }, { siteUrl, output: globalOutput }) {
141
151
  const type = output?.type || globalOutput?.type || 'atom';
142
152
  const { extension, mime, getContent } = getFeedFileType(type);
@@ -149,6 +159,7 @@ function getOutputInfo({ id, output }, { siteUrl, output: globalOutput }) {
149
159
  filename
150
160
  ].reduce((u, part)=>u ? resolve(u, part) : part);
151
161
  const sorting = output?.sorting || globalOutput?.sorting || ((l, r)=>sortByDate(l.date, r.date));
162
+ const transform = output?.transform || globalOutput?.transform;
152
163
  return {
153
164
  type,
154
165
  mime,
@@ -157,7 +168,8 @@ function getOutputInfo({ id, output }, { siteUrl, output: globalOutput }) {
157
168
  dir,
158
169
  publicPath,
159
170
  url,
160
- sorting
171
+ sorting,
172
+ transform
161
173
  };
162
174
  }
163
175
  class FeedsSet {
@@ -195,7 +207,7 @@ class FeedsSet {
195
207
  async function getRssItems(feeds, page, siteUrl, htmlContent) {
196
208
  return Promise.all(feeds.filter((options)=>testPage(options.test, page)).map(async (options)=>{
197
209
  const after = options.item || ((feed)=>feed);
198
- const item = await after(generateFeedItem(page, siteUrl, htmlContent), page);
210
+ const item = await after(generateFeedItem(page, siteUrl, htmlContent), page, siteUrl);
199
211
  return {
200
212
  ...item,
201
213
  channel: options.id
@@ -253,13 +265,14 @@ function pluginRss(pluginRssOptions) {
253
265
  }
254
266
  }
255
267
  for (const [channel, feed] of Object.entries(feeds)){
256
- const { output } = feedsSet.get(channel);
268
+ const feedChannel = feedsSet.get(channel);
269
+ const { output } = feedChannel;
257
270
  feed.items.sort(output.sorting);
258
271
  const path = node_path.resolve(outDir, output.dir, output.filename);
259
- await writeFile(path, output.getContent(feed));
272
+ await writeFile(path, await renderFeedContent(feed, feedChannel, output));
260
273
  }
261
274
  _pagesForRss = null;
262
275
  }
263
276
  };
264
277
  }
265
- export { PluginComponents, PluginName, createFeed, generateFeedItem, getDefaultFeedOption, getFeedFileType, getOutputInfo, pluginRss, testPage };
278
+ 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.6",
3
+ "version": "2.0.8",
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.20.0",
31
+ "@rslib/core": "0.20.2",
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.6"
39
+ "@rspress/core": "^2.0.8"
40
40
  },
41
41
  "engines": {
42
42
  "node": "^20.19.0 || >=22.12.0"