@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 +265 -289
- package/dist/index.d.ts +156 -141
- package/dist/index.mjs +212 -247
- package/package.json +8 -9
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.cjs
CHANGED
@@ -1,322 +1,298 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
3
|
-
|
4
|
-
|
5
|
-
var
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
61
|
+
return null != n;
|
62
62
|
}
|
63
63
|
function concatArray(...arrList) {
|
64
|
-
|
65
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
83
|
-
|
77
|
+
const d = new Date(s);
|
78
|
+
return Number.isNaN(d.getDate()) ? null : d;
|
84
79
|
}
|
85
80
|
function sortByDate(l, r) {
|
86
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
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
|
-
|
145
|
+
return {
|
146
|
+
id: 'blog',
|
147
|
+
test: '/blog/'
|
148
|
+
};
|
159
149
|
}
|
160
150
|
function getFeedFileType(type) {
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
(u, part)
|
194
|
-
|
195
|
-
|
196
|
-
|
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
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
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
|
242
|
-
|
243
|
-
|
244
|
-
|
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
|
-
|
278
|
-
|
279
|
-
language: language || pageData.lang
|
238
|
+
...item,
|
239
|
+
channel: options.id
|
280
240
|
};
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
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
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
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
|