@rspress/plugin-rss 2.0.0-beta.0 → 2.0.0-beta.10

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/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  > RSS plugin for rspress
4
4
 
5
- [Documentation](https://rspress.dev/plugin/official-plugins/rss)
5
+ [Documentation](https://rspress.rs/plugin/official-plugins/rss)
@@ -1,5 +1,6 @@
1
1
  import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
2
2
  import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__ from "@rspress/shared/node-utils";
3
4
  import * as __WEBPACK_EXTERNAL_MODULE_feed__ from "feed";
4
5
  import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
5
6
  function notNullish(n) {
@@ -49,11 +50,10 @@ function generateFeedItem(page, siteUrl) {
49
50
  };
50
51
  }
51
52
  function createFeed(options, config) {
52
- var _config_themeConfig_footer, _config_themeConfig;
53
53
  const { output, item, id, title, ..._options } = options;
54
54
  return {
55
55
  id,
56
- copyright: (null == (_config_themeConfig = config.themeConfig) ? void 0 : null == (_config_themeConfig_footer = _config_themeConfig.footer) ? void 0 : _config_themeConfig_footer.message) || '',
56
+ copyright: config.themeConfig?.footer?.message || '',
57
57
  description: config.description || '',
58
58
  link: output.url,
59
59
  ..._options,
@@ -119,17 +119,17 @@ function getFeedFileType(type) {
119
119
  }
120
120
  }
121
121
  function getOutputInfo({ id, output }, { siteUrl, output: globalOutput }) {
122
- const type = (null == output ? void 0 : output.type) || (null == globalOutput ? void 0 : globalOutput.type) || 'atom';
122
+ const type = output?.type || globalOutput?.type || 'atom';
123
123
  const { extension, mime, getContent } = getFeedFileType(type);
124
- const filename = (null == output ? void 0 : output.filename) || `${id}.${extension}`;
125
- const dir = (null == output ? void 0 : output.dir) || (null == globalOutput ? void 0 : globalOutput.dir) || 'rss';
126
- const publicPath = (null == output ? void 0 : output.publicPath) || (null == globalOutput ? void 0 : globalOutput.publicPath) || siteUrl;
124
+ const filename = output?.filename || `${id}.${extension}`;
125
+ const dir = output?.dir || globalOutput?.dir || 'rss';
126
+ const publicPath = output?.publicPath || globalOutput?.publicPath || siteUrl;
127
127
  const url = [
128
128
  publicPath,
129
129
  `${dir}/`,
130
130
  filename
131
131
  ].reduce((u, part)=>u ? (0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.resolve)(u, part) : part);
132
- const sorting = (null == output ? void 0 : output.sorting) || (null == globalOutput ? void 0 : globalOutput.sorting) || ((l, r)=>sortByDate(l.date, r.date));
132
+ const sorting = output?.sorting || globalOutput?.sorting || ((l, r)=>sortByDate(l.date, r.date));
133
133
  return {
134
134
  type,
135
135
  mime,
@@ -141,30 +141,20 @@ function getOutputInfo({ id, output }, { siteUrl, output: globalOutput }) {
141
141
  sorting
142
142
  };
143
143
  }
144
- function _define_property(obj, key, value) {
145
- if (key in obj) Object.defineProperty(obj, key, {
146
- value: value,
147
- enumerable: true,
148
- configurable: true,
149
- writable: true
150
- });
151
- else obj[key] = value;
152
- return obj;
153
- }
154
144
  class FeedsSet {
145
+ feeds = [];
146
+ feedsMapById = Object.create(null);
155
147
  set({ feed, output, siteUrl }, config) {
156
148
  this.feeds = (Array.isArray(feed) ? feed : [
157
149
  {
158
150
  ...getDefaultFeedOption(),
159
151
  ...feed
160
152
  }
161
- ]).map((options)=>{
162
- var _config_themeConfig_footer, _config_themeConfig;
163
- return {
153
+ ]).map((options)=>({
164
154
  title: config.title || '',
165
155
  description: config.description || '',
166
- favicon: config.icon && (0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.resolve)(siteUrl, config.icon),
167
- copyright: (null == (_config_themeConfig = config.themeConfig) ? void 0 : null == (_config_themeConfig_footer = _config_themeConfig.footer) ? void 0 : _config_themeConfig_footer.message) || '',
156
+ favicon: config.icon && (0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.resolve)(siteUrl, (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getIconUrlPath)(config.icon)),
157
+ copyright: config.themeConfig?.footer?.message || '',
168
158
  link: siteUrl,
169
159
  docs: '',
170
160
  ...options,
@@ -172,8 +162,7 @@ class FeedsSet {
172
162
  siteUrl,
173
163
  output
174
164
  })
175
- };
176
- });
165
+ }));
177
166
  this.feedsMapById = this.feeds.reduce((m, f)=>({
178
167
  ...m,
179
168
  [f.id]: f
@@ -183,10 +172,6 @@ class FeedsSet {
183
172
  if (id) return this.feedsMapById[id] || null;
184
173
  return this.feeds.slice(0);
185
174
  }
186
- constructor(){
187
- _define_property(this, "feeds", []);
188
- _define_property(this, "feedsMapById", Object.create(null));
189
- }
190
175
  }
191
176
  function getRssItems(feeds, page, config, siteUrl) {
192
177
  return Promise.all(feeds.filter((options)=>testPage(options.test, page, config.base)).map(async (options)=>{
package/package.json CHANGED
@@ -1,24 +1,23 @@
1
1
  {
2
2
  "name": "@rspress/plugin-rss",
3
- "version": "2.0.0-beta.0",
3
+ "version": "2.0.0-beta.10",
4
4
  "description": "A plugin for rss generation for rspress",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/web-infra-dev/rspress",
8
+ "url": "git+https://github.com/web-infra-dev/rspress.git",
9
9
  "directory": "packages/plugin-rss"
10
10
  },
11
11
  "license": "MIT",
12
+ "type": "module",
12
13
  "exports": {
13
14
  ".": {
14
15
  "types": "./dist/index.d.ts",
15
- "import": "./dist/index.mjs",
16
- "default": "./dist/index.cjs"
16
+ "default": "./dist/index.js"
17
17
  },
18
- "./FeedsAnnotations": "./static/global-components/FeedsAnnotations"
18
+ "./FeedsAnnotations": "./static/global-components/FeedsAnnotations.tsx"
19
19
  },
20
- "main": "./dist/index.cjs",
21
- "module": "./dist/index.mjs",
20
+ "module": "./dist/index.js",
22
21
  "types": "./dist/index.d.ts",
23
22
  "files": [
24
23
  "dist",
@@ -26,22 +25,22 @@
26
25
  ],
27
26
  "dependencies": {
28
27
  "feed": "^4.2.2",
29
- "@rspress/shared": "2.0.0-beta.0"
28
+ "@rspress/shared": "2.0.0-beta.10"
30
29
  },
31
30
  "devDependencies": {
32
- "@rslib/core": "0.6.5",
33
- "@types/node": "^18.11.17",
34
- "@types/react": "^18.3.20",
31
+ "@rslib/core": "0.8.0",
32
+ "@types/node": "^22.8.1",
33
+ "@types/react": "^18.3.22",
35
34
  "react": "^19.1.0",
35
+ "rsbuild-plugin-publint": "^0.3.2",
36
36
  "typescript": "^5.8.2",
37
- "@rspress/runtime": "2.0.0-beta.0"
37
+ "@rspress/runtime": "2.0.0-beta.10"
38
38
  },
39
39
  "peerDependencies": {
40
- "react": ">=17.0.0",
41
- "rspress": "^2.0.0-beta.0"
40
+ "rspress": "^2.0.0-beta.10"
42
41
  },
43
42
  "engines": {
44
- "node": ">=14.17.6"
43
+ "node": ">=18.0.0"
45
44
  },
46
45
  "publishConfig": {
47
46
  "access": "public",
@@ -1,14 +1,14 @@
1
1
  /// <reference path="../../index.d.ts" />
2
2
 
3
3
  import type { LinkHTMLAttributes } from 'react';
4
- import { Helmet, usePageData } from 'rspress/runtime';
4
+ import { Head, usePageData } from 'rspress/runtime';
5
5
 
6
6
  export default function FeedsAnnotations() {
7
7
  const { page } = usePageData();
8
8
  const feeds = page.feeds || [];
9
9
 
10
10
  return (
11
- <Helmet>
11
+ <Head>
12
12
  {feeds.map(({ language, url, mime }) => {
13
13
  const props: LinkHTMLAttributes<HTMLLinkElement> = {
14
14
  rel: 'alternate',
@@ -21,6 +21,6 @@ export default function FeedsAnnotations() {
21
21
  // biome-ignore lint/correctness/useJsxKeyInIterable: no key props
22
22
  return <link {...props} />;
23
23
  })}
24
- </Helmet>
24
+ </Head>
25
25
  );
26
26
  }
package/dist/index.cjs DELETED
@@ -1,319 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
- __webpack_require__.d(getter, {
7
- a: getter
8
- });
9
- return getter;
10
- };
11
- })();
12
- (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
18
- };
19
- })();
20
- (()=>{
21
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
- })();
23
- (()=>{
24
- __webpack_require__.r = (exports1)=>{
25
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
- value: 'Module'
27
- });
28
- Object.defineProperty(exports1, '__esModule', {
29
- value: true
30
- });
31
- };
32
- })();
33
- var __webpack_exports__ = {};
34
- __webpack_require__.r(__webpack_exports__);
35
- __webpack_require__.d(__webpack_exports__, {
36
- getDefaultFeedOption: ()=>getDefaultFeedOption,
37
- PluginComponents: ()=>PluginComponents,
38
- createFeed: ()=>createFeed,
39
- getFeedFileType: ()=>getFeedFileType,
40
- PluginName: ()=>PluginName,
41
- generateFeedItem: ()=>generateFeedItem,
42
- getOutputInfo: ()=>getOutputInfo,
43
- testPage: ()=>testPage,
44
- pluginRss: ()=>pluginRss
45
- });
46
- const external_node_path_namespaceObject = require("node:path");
47
- var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
48
- const external_node_url_namespaceObject = require("node:url");
49
- const external_feed_namespaceObject = require("feed");
50
- function notNullish(n) {
51
- return null != n;
52
- }
53
- function concatArray(...arrList) {
54
- return arrList.reduce((arr, item)=>arr.concat((Array.isArray(item) ? item : [
55
- item
56
- ]).filter(notNullish)), []);
57
- }
58
- function selectNonNullishProperty(...list) {
59
- for (const item of list){
60
- if ('' === item) return '';
61
- if (0 === item) return '0';
62
- if ('number' == typeof item) return `${item}`;
63
- if ('string' == typeof item) return item;
64
- }
65
- }
66
- function toDate(s) {
67
- const d = new Date(s);
68
- return Number.isNaN(d.getDate()) ? null : d;
69
- }
70
- function sortByDate(l, r) {
71
- return (r ? r.getTime() : 0) - (l ? l.getTime() : 0);
72
- }
73
- const external_node_fs_namespaceObject = require("node:fs");
74
- async function writeFile(path, content) {
75
- const dir = external_node_path_namespaceObject.dirname(path);
76
- await external_node_fs_namespaceObject.promises.mkdir(dir, {
77
- mode: 493,
78
- recursive: true
79
- });
80
- return external_node_fs_namespaceObject.promises.writeFile(path, content);
81
- }
82
- function generateFeedItem(page, siteUrl) {
83
- const { frontmatter: fm } = page;
84
- return {
85
- id: selectNonNullishProperty(fm.slug, fm.id, page.id) || '',
86
- title: selectNonNullishProperty(fm.title, page.title) || '',
87
- author: toAuthors(fm.author),
88
- link: (0, external_node_url_namespaceObject.resolve)(siteUrl, selectNonNullishProperty(fm.permalink, page.routePath) || ''),
89
- description: selectNonNullishProperty(fm.description) || '',
90
- content: selectNonNullishProperty(fm.summary, page._html) || '',
91
- date: toDate(fm.date || fm.published_at),
92
- category: concatArray(fm.categories, fm.category).map((cat)=>({
93
- name: cat
94
- }))
95
- };
96
- }
97
- function createFeed(options, config) {
98
- var _config_themeConfig_footer, _config_themeConfig;
99
- const { output, item, id, title, ..._options } = options;
100
- return {
101
- id,
102
- copyright: (null == (_config_themeConfig = config.themeConfig) ? void 0 : null == (_config_themeConfig_footer = _config_themeConfig.footer) ? void 0 : _config_themeConfig_footer.message) || '',
103
- description: config.description || '',
104
- link: output.url,
105
- ..._options,
106
- title: title || config.title || ''
107
- };
108
- }
109
- function toAuthors(author) {
110
- const authors = (Array.isArray(author) ? author : [
111
- author
112
- ]).filter(Boolean).map((author)=>({
113
- ...'string' == typeof author ? {
114
- name: author
115
- } : author
116
- }));
117
- return authors.length ? authors : void 0;
118
- }
119
- const PluginName = '@rspress/plugin-rss';
120
- const PluginComponents = {
121
- FeedsAnnotations: '@rspress/plugin-rss/FeedsAnnotations'
122
- };
123
- function testPage(test, page, base = '/') {
124
- if (Array.isArray(test)) return test.some((item)=>testPage(item, page, base));
125
- if ('function' == typeof test) return test(page, base);
126
- const routePath = page.routePath;
127
- const pureRoutePath = `/${routePath.startsWith(base) ? routePath.slice(base.length) : routePath}`.replace(/^\/+/, '/');
128
- if ('string' == typeof test) return [
129
- routePath,
130
- pureRoutePath
131
- ].some((path)=>path.startsWith(test));
132
- if (test instanceof RegExp) return [
133
- routePath,
134
- pureRoutePath
135
- ].some((path)=>test.test(path));
136
- throw new Error('test must be of `RegExp` or `string` or `(page: PageIndexInfo, base: string) => boolean`');
137
- }
138
- function getDefaultFeedOption() {
139
- return {
140
- id: 'blog',
141
- test: '/blog/'
142
- };
143
- }
144
- function getFeedFileType(type) {
145
- switch(type){
146
- case 'rss':
147
- return {
148
- extension: 'rss',
149
- mime: 'application/rss+xml',
150
- getContent: (feed)=>feed.rss2()
151
- };
152
- case 'json':
153
- return {
154
- extension: 'json',
155
- mime: 'application/json',
156
- getContent: (feed)=>feed.json1()
157
- };
158
- case 'atom':
159
- default:
160
- return {
161
- extension: 'xml',
162
- mime: 'application/atom+xml',
163
- getContent: (feed)=>feed.atom1()
164
- };
165
- }
166
- }
167
- function getOutputInfo({ id, output }, { siteUrl, output: globalOutput }) {
168
- const type = (null == output ? void 0 : output.type) || (null == globalOutput ? void 0 : globalOutput.type) || 'atom';
169
- const { extension, mime, getContent } = getFeedFileType(type);
170
- const filename = (null == output ? void 0 : output.filename) || `${id}.${extension}`;
171
- const dir = (null == output ? void 0 : output.dir) || (null == globalOutput ? void 0 : globalOutput.dir) || 'rss';
172
- const publicPath = (null == output ? void 0 : output.publicPath) || (null == globalOutput ? void 0 : globalOutput.publicPath) || siteUrl;
173
- const url = [
174
- publicPath,
175
- `${dir}/`,
176
- filename
177
- ].reduce((u, part)=>u ? (0, external_node_url_namespaceObject.resolve)(u, part) : part);
178
- const sorting = (null == output ? void 0 : output.sorting) || (null == globalOutput ? void 0 : globalOutput.sorting) || ((l, r)=>sortByDate(l.date, r.date));
179
- return {
180
- type,
181
- mime,
182
- filename,
183
- getContent,
184
- dir,
185
- publicPath,
186
- url,
187
- sorting
188
- };
189
- }
190
- function _define_property(obj, key, value) {
191
- if (key in obj) Object.defineProperty(obj, key, {
192
- value: value,
193
- enumerable: true,
194
- configurable: true,
195
- writable: true
196
- });
197
- else obj[key] = value;
198
- return obj;
199
- }
200
- class FeedsSet {
201
- set({ feed, output, siteUrl }, config) {
202
- this.feeds = (Array.isArray(feed) ? feed : [
203
- {
204
- ...getDefaultFeedOption(),
205
- ...feed
206
- }
207
- ]).map((options)=>{
208
- var _config_themeConfig_footer, _config_themeConfig;
209
- return {
210
- title: config.title || '',
211
- description: config.description || '',
212
- favicon: config.icon && (0, external_node_url_namespaceObject.resolve)(siteUrl, config.icon),
213
- copyright: (null == (_config_themeConfig = config.themeConfig) ? void 0 : null == (_config_themeConfig_footer = _config_themeConfig.footer) ? void 0 : _config_themeConfig_footer.message) || '',
214
- link: siteUrl,
215
- docs: '',
216
- ...options,
217
- output: getOutputInfo(options, {
218
- siteUrl,
219
- output
220
- })
221
- };
222
- });
223
- this.feedsMapById = this.feeds.reduce((m, f)=>({
224
- ...m,
225
- [f.id]: f
226
- }), Object.create(null));
227
- }
228
- get(id) {
229
- if (id) return this.feedsMapById[id] || null;
230
- return this.feeds.slice(0);
231
- }
232
- constructor(){
233
- _define_property(this, "feeds", []);
234
- _define_property(this, "feedsMapById", Object.create(null));
235
- }
236
- }
237
- function getRssItems(feeds, page, config, siteUrl) {
238
- return Promise.all(feeds.filter((options)=>testPage(options.test, page, config.base)).map(async (options)=>{
239
- const after = options.item || ((feed)=>feed);
240
- const item = await after(generateFeedItem(page, siteUrl), page, siteUrl);
241
- return {
242
- ...item,
243
- channel: options.id
244
- };
245
- }));
246
- }
247
- function pluginRss(pluginRssOptions) {
248
- const feedsSet = new FeedsSet();
249
- let _rssWorkaround = null;
250
- let _config;
251
- return {
252
- name: PluginName,
253
- globalUIComponents: Object.values(PluginComponents),
254
- beforeBuild (config, isProd) {
255
- if (!isProd) {
256
- _rssWorkaround = null;
257
- return;
258
- }
259
- _rssWorkaround = {};
260
- _config = config;
261
- feedsSet.set(pluginRssOptions, config);
262
- },
263
- async extendPageData (pageData) {
264
- if (!_rssWorkaround) return;
265
- _rssWorkaround[pageData.id] = _rssWorkaround[pageData.id] || getRssItems(feedsSet.get(), pageData, _config, pluginRssOptions.siteUrl);
266
- const feeds = await _rssWorkaround[pageData.id];
267
- const showRssList = new Set(concatArray(pageData.frontmatter['link-rss']));
268
- for (const feed of feeds)showRssList.add(feed.channel);
269
- pageData.feeds = Array.from(showRssList, (id)=>{
270
- const { output, language } = feedsSet.get(id);
271
- return {
272
- url: output.url,
273
- mime: output.mime,
274
- language: language || pageData.lang
275
- };
276
- });
277
- },
278
- async afterBuild (config) {
279
- if (!_rssWorkaround) return;
280
- const items = concatArray(...await Promise.all(Object.values(_rssWorkaround)));
281
- const feeds = Object.create(null);
282
- for (const { channel, ...item } of items){
283
- feeds[channel] = feeds[channel] || new external_feed_namespaceObject.Feed(createFeed(feedsSet.get(channel), config));
284
- feeds[channel].addItem(item);
285
- }
286
- for (const [channel, feed] of Object.entries(feeds)){
287
- const { output } = feedsSet.get(channel);
288
- feed.items.sort(output.sorting);
289
- const path = external_node_path_default().resolve(config.outDir || 'doc_build', output.dir, output.filename);
290
- await writeFile(path, output.getContent(feed));
291
- }
292
- _rssWorkaround = null;
293
- _config = null;
294
- }
295
- };
296
- }
297
- exports.PluginComponents = __webpack_exports__.PluginComponents;
298
- exports.PluginName = __webpack_exports__.PluginName;
299
- exports.createFeed = __webpack_exports__.createFeed;
300
- exports.generateFeedItem = __webpack_exports__.generateFeedItem;
301
- exports.getDefaultFeedOption = __webpack_exports__.getDefaultFeedOption;
302
- exports.getFeedFileType = __webpack_exports__.getFeedFileType;
303
- exports.getOutputInfo = __webpack_exports__.getOutputInfo;
304
- exports.pluginRss = __webpack_exports__.pluginRss;
305
- exports.testPage = __webpack_exports__.testPage;
306
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
307
- "PluginComponents",
308
- "PluginName",
309
- "createFeed",
310
- "generateFeedItem",
311
- "getDefaultFeedOption",
312
- "getFeedFileType",
313
- "getOutputInfo",
314
- "pluginRss",
315
- "testPage"
316
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
317
- Object.defineProperty(exports, '__esModule', {
318
- value: true
319
- });