@rspress/plugin-rss 1.41.1 → 1.41.2

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.cjs CHANGED
@@ -1,322 +1,298 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- PluginComponents: () => PluginComponents,
34
- PluginName: () => PluginName,
35
- createFeed: () => createFeed,
36
- generateFeedItem: () => generateFeedItem,
37
- getDefaultFeedOption: () => getDefaultFeedOption,
38
- getFeedFileType: () => getFeedFileType,
39
- getOutputInfo: () => getOutputInfo,
40
- pluginRss: () => pluginRss,
41
- testPage: () => testPage
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = function(module) {
5
+ var getter = module && module.__esModule ? function() {
6
+ return module['default'];
7
+ } : function() {
8
+ return module;
9
+ };
10
+ __webpack_require__.d(getter, {
11
+ a: getter
12
+ });
13
+ return getter;
14
+ };
15
+ })();
16
+ (()=>{
17
+ __webpack_require__.d = function(exports1, definition) {
18
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
19
+ enumerable: true,
20
+ get: definition[key]
21
+ });
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = function(obj, prop) {
26
+ return Object.prototype.hasOwnProperty.call(obj, prop);
27
+ };
28
+ })();
29
+ (()=>{
30
+ __webpack_require__.r = function(exports1) {
31
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
32
+ value: 'Module'
33
+ });
34
+ Object.defineProperty(exports1, '__esModule', {
35
+ value: true
36
+ });
37
+ };
38
+ })();
39
+ var __webpack_exports__ = {};
40
+ __webpack_require__.r(__webpack_exports__);
41
+ __webpack_require__.d(__webpack_exports__, {
42
+ getDefaultFeedOption: ()=>getDefaultFeedOption,
43
+ PluginComponents: ()=>PluginComponents,
44
+ generateFeedItem: ()=>generateFeedItem,
45
+ getFeedFileType: ()=>getFeedFileType,
46
+ pluginRss: ()=>pluginRss,
47
+ getOutputInfo: ()=>getOutputInfo,
48
+ createFeed: ()=>createFeed,
49
+ testPage: ()=>testPage,
50
+ PluginName: ()=>PluginName
42
51
  });
43
- module.exports = __toCommonJS(src_exports);
44
-
45
- // src/plugin-rss.ts
46
- var import_node_path = __toESM(require("path"));
47
- var import_node_url3 = require("url");
48
- var import_feed = require("feed");
49
-
50
- // src/exports.ts
51
- var PluginName = "@rspress/plugin-rss";
52
- var PluginComponents = {
53
- FeedsAnnotations: "@rspress/plugin-rss/FeedsAnnotations"
52
+ const external_node_path_namespaceObject = require("node:path");
53
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
54
+ const external_node_url_namespaceObject = require("node:url");
55
+ const external_feed_namespaceObject = require("feed");
56
+ const PluginName = '@rspress/plugin-rss';
57
+ const PluginComponents = {
58
+ FeedsAnnotations: '@rspress/plugin-rss/FeedsAnnotations'
54
59
  };
55
-
56
- // src/feed.ts
57
- var import_node_url = require("url");
58
-
59
- // src/internals/lang.ts
60
60
  function notNullish(n) {
61
- return n !== void 0 && n !== null;
61
+ return null != n;
62
62
  }
63
63
  function concatArray(...arrList) {
64
- return arrList.reduce(
65
- (arr, item) => arr.concat((Array.isArray(item) ? item : [item]).filter(notNullish)),
66
- []
67
- );
64
+ return arrList.reduce((arr, item)=>arr.concat((Array.isArray(item) ? item : [
65
+ item
66
+ ]).filter(notNullish)), []);
68
67
  }
69
68
  function selectNonNullishProperty(...list) {
70
- for (const item of list) {
71
- if (item === "")
72
- return "";
73
- if (item === 0)
74
- return "0";
75
- if (typeof item === "number")
76
- return `${item}`;
77
- if (typeof item === "string")
78
- return item;
79
- }
69
+ for (const item of list){
70
+ if ('' === item) return '';
71
+ if (0 === item) return '0';
72
+ if ('number' == typeof item) return `${item}`;
73
+ if ('string' == typeof item) return item;
74
+ }
80
75
  }
81
76
  function toDate(s) {
82
- const d = new Date(s);
83
- return Number.isNaN(d.getDate()) ? null : d;
77
+ const d = new Date(s);
78
+ return Number.isNaN(d.getDate()) ? null : d;
84
79
  }
85
80
  function sortByDate(l, r) {
86
- return (r ? r.getTime() : 0) - (l ? l.getTime() : 0);
81
+ return (r ? r.getTime() : 0) - (l ? l.getTime() : 0);
87
82
  }
88
-
89
- // src/internals/node.ts
90
- var import_node_fs = require("fs");
91
- var NodePath = __toESM(require("path"));
83
+ const external_node_fs_namespaceObject = require("node:fs");
92
84
  async function writeFile(path, content) {
93
- const dir = NodePath.dirname(path);
94
- await import_node_fs.promises.mkdir(dir, { mode: 493, recursive: true });
95
- return import_node_fs.promises.writeFile(path, content);
85
+ const dir = external_node_path_namespaceObject.dirname(path);
86
+ await external_node_fs_namespaceObject.promises.mkdir(dir, {
87
+ mode: 493,
88
+ recursive: true
89
+ });
90
+ return external_node_fs_namespaceObject.promises.writeFile(path, content);
96
91
  }
97
-
98
- // src/feed.ts
99
92
  function generateFeedItem(page, siteUrl) {
100
- const { frontmatter: fm } = page;
101
- return {
102
- id: selectNonNullishProperty(fm.slug, fm.id, page.id) || "",
103
- title: selectNonNullishProperty(fm.title, page.title) || "",
104
- author: toAuthors(fm.author),
105
- link: (0, import_node_url.resolve)(
106
- siteUrl,
107
- selectNonNullishProperty(fm.permalink, page.routePath) || ""
108
- ),
109
- description: selectNonNullishProperty(fm.description) || "",
110
- content: selectNonNullishProperty(fm.summary, page._html) || "",
111
- date: toDate(fm.date || fm.published_at),
112
- category: concatArray(fm.categories, fm.category).map(
113
- (cat) => ({ name: cat })
114
- )
115
- };
93
+ const { frontmatter: fm } = page;
94
+ return {
95
+ id: selectNonNullishProperty(fm.slug, fm.id, page.id) || '',
96
+ title: selectNonNullishProperty(fm.title, page.title) || '',
97
+ author: toAuthors(fm.author),
98
+ link: (0, external_node_url_namespaceObject.resolve)(siteUrl, selectNonNullishProperty(fm.permalink, page.routePath) || ''),
99
+ description: selectNonNullishProperty(fm.description) || '',
100
+ content: selectNonNullishProperty(fm.summary, page._html) || '',
101
+ date: toDate(fm.date || fm.published_at),
102
+ category: concatArray(fm.categories, fm.category).map((cat)=>({
103
+ name: cat
104
+ }))
105
+ };
116
106
  }
117
107
  function createFeed(options, config) {
118
- const { output, item, id, title, ..._options } = options;
119
- return {
120
- id,
121
- copyright: config.themeConfig?.footer?.message || "",
122
- description: config.description || "",
123
- link: output.url,
124
- ..._options,
125
- title: title || config.title || ""
126
- };
108
+ var _config_themeConfig_footer, _config_themeConfig;
109
+ const { output, item, id, title, ..._options } = options;
110
+ return {
111
+ id,
112
+ copyright: (null === (_config_themeConfig = config.themeConfig) || void 0 === _config_themeConfig ? void 0 : null === (_config_themeConfig_footer = _config_themeConfig.footer) || void 0 === _config_themeConfig_footer ? void 0 : _config_themeConfig_footer.message) || '',
113
+ description: config.description || '',
114
+ link: output.url,
115
+ ..._options,
116
+ title: title || config.title || ''
117
+ };
127
118
  }
128
119
  function toAuthors(author) {
129
- const authors = (Array.isArray(author) ? author : [author]).filter(Boolean).map((author2) => ({
130
- // email is mandatory for RSS 2.0.
131
- ...typeof author2 === "string" ? { name: author2 } : author2
132
- }));
133
- return authors.length ? authors : void 0;
120
+ const authors = (Array.isArray(author) ? author : [
121
+ author
122
+ ]).filter(Boolean).map((author)=>({
123
+ ...'string' == typeof author ? {
124
+ name: author
125
+ } : author
126
+ }));
127
+ return authors.length ? authors : void 0;
134
128
  }
135
-
136
- // src/options.ts
137
- var import_node_url2 = require("url");
138
- function testPage(test, page, base = "/") {
139
- if (Array.isArray(test)) {
140
- return test.some((item) => testPage(item, page, base));
141
- }
142
- if (typeof test === "function") {
143
- return test(page, base);
144
- }
145
- const routePath = page.routePath;
146
- const pureRoutePath = `/${routePath.startsWith(base) ? routePath.slice(base.length) : routePath}`.replace(/^\/+/, "/");
147
- if (typeof test === "string") {
148
- return [routePath, pureRoutePath].some((path) => path.startsWith(test));
149
- }
150
- if (test instanceof RegExp) {
151
- return [routePath, pureRoutePath].some((path) => test.test(path));
152
- }
153
- throw new Error(
154
- "test must be of `RegExp` or `string` or `(page: PageIndexInfo, base: string) => boolean`"
155
- );
129
+ function testPage(test, page, base = '/') {
130
+ if (Array.isArray(test)) return test.some((item)=>testPage(item, page, base));
131
+ if ('function' == typeof test) return test(page, base);
132
+ const routePath = page.routePath;
133
+ const pureRoutePath = `/${routePath.startsWith(base) ? routePath.slice(base.length) : routePath}`.replace(/^\/+/, '/');
134
+ if ('string' == typeof test) return [
135
+ routePath,
136
+ pureRoutePath
137
+ ].some((path)=>path.startsWith(test));
138
+ if (test instanceof RegExp) return [
139
+ routePath,
140
+ pureRoutePath
141
+ ].some((path)=>test.test(path));
142
+ throw new Error('test must be of `RegExp` or `string` or `(page: PageIndexInfo, base: string) => boolean`');
156
143
  }
157
144
  function getDefaultFeedOption() {
158
- return { id: "blog", test: "/blog/" };
145
+ return {
146
+ id: 'blog',
147
+ test: '/blog/'
148
+ };
159
149
  }
160
150
  function getFeedFileType(type) {
161
- switch (type) {
162
- case "rss":
163
- return {
164
- extension: "rss",
165
- mime: "application/rss+xml",
166
- getContent: (feed) => feed.rss2()
167
- };
168
- case "json":
169
- return {
170
- extension: "json",
171
- mime: "application/json",
172
- getContent: (feed) => feed.json1()
173
- };
174
- case "atom":
175
- default:
176
- return {
177
- extension: "xml",
178
- mime: "application/atom+xml",
179
- getContent: (feed) => feed.atom1()
180
- };
181
- }
151
+ switch(type){
152
+ case 'rss':
153
+ return {
154
+ extension: 'rss',
155
+ mime: 'application/rss+xml',
156
+ getContent: (feed)=>feed.rss2()
157
+ };
158
+ case 'json':
159
+ return {
160
+ extension: 'json',
161
+ mime: 'application/json',
162
+ getContent: (feed)=>feed.json1()
163
+ };
164
+ case 'atom':
165
+ default:
166
+ return {
167
+ extension: 'xml',
168
+ mime: 'application/atom+xml',
169
+ getContent: (feed)=>feed.atom1()
170
+ };
171
+ }
182
172
  }
183
- function getOutputInfo({ id, output }, {
184
- siteUrl,
185
- output: globalOutput
186
- }) {
187
- const type = output?.type || globalOutput?.type || "atom";
188
- const { extension, mime, getContent } = getFeedFileType(type);
189
- const filename = output?.filename || `${id}.${extension}`;
190
- const dir = output?.dir || globalOutput?.dir || "rss";
191
- const publicPath = output?.publicPath || globalOutput?.publicPath || siteUrl;
192
- const url = [publicPath, `${dir}/`, filename].reduce(
193
- (u, part) => u ? (0, import_node_url2.resolve)(u, part) : part
194
- );
195
- const sorting = output?.sorting || globalOutput?.sorting || ((l, r) => sortByDate(l.date, r.date));
196
- return { type, mime, filename, getContent, dir, publicPath, url, sorting };
173
+ function getOutputInfo({ id, output }, { siteUrl, output: globalOutput }) {
174
+ const type = (null == output ? void 0 : output.type) || (null == globalOutput ? void 0 : globalOutput.type) || 'atom';
175
+ const { extension, mime, getContent } = getFeedFileType(type);
176
+ const filename = (null == output ? void 0 : output.filename) || `${id}.${extension}`;
177
+ const dir = (null == output ? void 0 : output.dir) || (null == globalOutput ? void 0 : globalOutput.dir) || 'rss';
178
+ const publicPath = (null == output ? void 0 : output.publicPath) || (null == globalOutput ? void 0 : globalOutput.publicPath) || siteUrl;
179
+ const url = [
180
+ publicPath,
181
+ `${dir}/`,
182
+ filename
183
+ ].reduce((u, part)=>u ? (0, external_node_url_namespaceObject.resolve)(u, part) : part);
184
+ const sorting = (null == output ? void 0 : output.sorting) || (null == globalOutput ? void 0 : globalOutput.sorting) || ((l, r)=>sortByDate(l.date, r.date));
185
+ return {
186
+ type,
187
+ mime,
188
+ filename,
189
+ getContent,
190
+ dir,
191
+ publicPath,
192
+ url,
193
+ sorting
194
+ };
197
195
  }
198
-
199
- // src/plugin-rss.ts
200
- var FeedsSet = class {
201
- constructor() {
202
- this.feeds = [];
203
- this.feedsMapById = /* @__PURE__ */ Object.create(null);
204
- }
205
- set({ feed, output, siteUrl }, config) {
206
- this.feeds = (Array.isArray(feed) ? feed : [{ ...getDefaultFeedOption(), ...feed }]).map((options) => ({
207
- title: config.title || "",
208
- description: config.description || "",
209
- favicon: config.icon && (0, import_node_url3.resolve)(siteUrl, config.icon),
210
- copyright: config.themeConfig?.footer?.message || "",
211
- link: siteUrl,
212
- docs: "",
213
- ...options,
214
- output: getOutputInfo(options, { siteUrl, output })
215
- }));
216
- this.feedsMapById = this.feeds.reduce(
217
- (m, f) => ({ ...m, [f.id]: f }),
218
- /* @__PURE__ */ Object.create(null)
219
- );
220
- }
221
- get(id) {
222
- if (id) {
223
- return this.feedsMapById[id] || null;
196
+ class FeedsSet {
197
+ set({ feed, output, siteUrl }, config) {
198
+ this.feeds = (Array.isArray(feed) ? feed : [
199
+ {
200
+ ...getDefaultFeedOption(),
201
+ ...feed
202
+ }
203
+ ]).map((options)=>{
204
+ var _config_themeConfig_footer, _config_themeConfig;
205
+ return {
206
+ title: config.title || '',
207
+ description: config.description || '',
208
+ favicon: config.icon && (0, external_node_url_namespaceObject.resolve)(siteUrl, config.icon),
209
+ copyright: (null === (_config_themeConfig = config.themeConfig) || void 0 === _config_themeConfig ? void 0 : null === (_config_themeConfig_footer = _config_themeConfig.footer) || void 0 === _config_themeConfig_footer ? void 0 : _config_themeConfig_footer.message) || '',
210
+ link: siteUrl,
211
+ docs: '',
212
+ ...options,
213
+ output: getOutputInfo(options, {
214
+ siteUrl,
215
+ output
216
+ })
217
+ };
218
+ });
219
+ this.feedsMapById = this.feeds.reduce((m, f)=>({
220
+ ...m,
221
+ [f.id]: f
222
+ }), Object.create(null));
223
+ }
224
+ get(id) {
225
+ if (id) return this.feedsMapById[id] || null;
226
+ return this.feeds.slice(0);
227
+ }
228
+ constructor(){
229
+ this.feeds = [];
230
+ this.feedsMapById = Object.create(null);
224
231
  }
225
- return this.feeds.slice(0);
226
- }
227
- };
228
- function getRssItems(feeds, page, config, siteUrl) {
229
- return Promise.all(
230
- feeds.filter((options) => testPage(options.test, page, config.base)).map(async (options) => {
231
- const after = options.item || ((feed) => feed);
232
- const item = await after(
233
- generateFeedItem(page, siteUrl),
234
- page,
235
- siteUrl
236
- );
237
- return { ...item, channel: options.id };
238
- })
239
- );
240
232
  }
241
- function pluginRss(pluginRssOptions) {
242
- const feedsSet = new FeedsSet();
243
- let _rssWorkaround = null;
244
- let _config;
245
- return {
246
- name: PluginName,
247
- globalUIComponents: Object.values(PluginComponents),
248
- beforeBuild(config, isProd) {
249
- if (!isProd) {
250
- _rssWorkaround = null;
251
- return;
252
- }
253
- _rssWorkaround = {};
254
- _config = config;
255
- feedsSet.set(pluginRssOptions, config);
256
- },
257
- async extendPageData(_pageData) {
258
- if (!_rssWorkaround)
259
- return;
260
- const pageData = _pageData;
261
- _rssWorkaround[pageData.id] = _rssWorkaround[pageData.id] || getRssItems(
262
- feedsSet.get(),
263
- pageData,
264
- _config,
265
- pluginRssOptions.siteUrl
266
- );
267
- const feeds = await _rssWorkaround[pageData.id];
268
- const showRssList = new Set(
269
- concatArray(pageData.frontmatter["link-rss"])
270
- );
271
- for (const feed of feeds) {
272
- showRssList.add(feed.channel);
273
- }
274
- pageData.feeds = Array.from(showRssList, (id) => {
275
- const { output, language } = feedsSet.get(id);
233
+ function getRssItems(feeds, page, config, siteUrl) {
234
+ return Promise.all(feeds.filter((options)=>testPage(options.test, page, config.base)).map(async (options)=>{
235
+ const after = options.item || ((feed)=>feed);
236
+ const item = await after(generateFeedItem(page, siteUrl), page, siteUrl);
276
237
  return {
277
- url: output.url,
278
- mime: output.mime,
279
- language: language || pageData.lang
238
+ ...item,
239
+ channel: options.id
280
240
  };
281
- });
282
- },
283
- async afterBuild(config) {
284
- if (!_rssWorkaround)
285
- return;
286
- const items = concatArray(
287
- ...await Promise.all(Object.values(_rssWorkaround))
288
- );
289
- const feeds = /* @__PURE__ */ Object.create(null);
290
- for (const { channel, ...item } of items) {
291
- feeds[channel] = feeds[channel] || new import_feed.Feed(createFeed(feedsSet.get(channel), config));
292
- feeds[channel].addItem(item);
293
- }
294
- for (const [channel, feed] of Object.entries(feeds)) {
295
- const { output } = feedsSet.get(channel);
296
- feed.items.sort(output.sorting);
297
- const path = import_node_path.default.resolve(
298
- config.outDir || "doc_build",
299
- output.dir,
300
- output.filename
301
- );
302
- await writeFile(path, output.getContent(feed));
303
- }
304
- _rssWorkaround = null;
305
- _config = null;
306
- }
307
- };
241
+ }));
242
+ }
243
+ function pluginRss(pluginRssOptions) {
244
+ const feedsSet = new FeedsSet();
245
+ let _rssWorkaround = null;
246
+ let _config;
247
+ return {
248
+ name: PluginName,
249
+ globalUIComponents: Object.values(PluginComponents),
250
+ beforeBuild (config, isProd) {
251
+ if (!isProd) {
252
+ _rssWorkaround = null;
253
+ return;
254
+ }
255
+ _rssWorkaround = {};
256
+ _config = config;
257
+ feedsSet.set(pluginRssOptions, config);
258
+ },
259
+ async extendPageData (_pageData) {
260
+ if (!_rssWorkaround) return;
261
+ const pageData = _pageData;
262
+ _rssWorkaround[pageData.id] = _rssWorkaround[pageData.id] || getRssItems(feedsSet.get(), pageData, _config, pluginRssOptions.siteUrl);
263
+ const feeds = await _rssWorkaround[pageData.id];
264
+ const showRssList = new Set(concatArray(pageData.frontmatter['link-rss']));
265
+ for (const feed of feeds)showRssList.add(feed.channel);
266
+ pageData.feeds = Array.from(showRssList, (id)=>{
267
+ const { output, language } = feedsSet.get(id);
268
+ return {
269
+ url: output.url,
270
+ mime: output.mime,
271
+ language: language || pageData.lang
272
+ };
273
+ });
274
+ },
275
+ async afterBuild (config) {
276
+ if (!_rssWorkaround) return;
277
+ const items = concatArray(...await Promise.all(Object.values(_rssWorkaround)));
278
+ const feeds = Object.create(null);
279
+ for (const { channel, ...item } of items){
280
+ feeds[channel] = feeds[channel] || new external_feed_namespaceObject.Feed(createFeed(feedsSet.get(channel), config));
281
+ feeds[channel].addItem(item);
282
+ }
283
+ for (const [channel, feed] of Object.entries(feeds)){
284
+ const { output } = feedsSet.get(channel);
285
+ feed.items.sort(output.sorting);
286
+ const path = external_node_path_default().resolve(config.outDir || 'doc_build', output.dir, output.filename);
287
+ await writeFile(path, output.getContent(feed));
288
+ }
289
+ _rssWorkaround = null;
290
+ _config = null;
291
+ }
292
+ };
308
293
  }
309
- // Annotate the CommonJS export names for ESM import in node:
310
- 0 && (module.exports = {
311
- PluginComponents,
312
- PluginName,
313
- createFeed,
314
- generateFeedItem,
315
- getDefaultFeedOption,
316
- getFeedFileType,
317
- getOutputInfo,
318
- pluginRss,
319
- testPage
294
+ var __webpack_export_target__ = exports;
295
+ for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
296
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
297
+ value: true
320
298
  });
321
-
322
- //# sourceMappingURL=index.cjs.map