@docusaurus/plugin-content-blog 3.0.0-alpha.0 → 3.0.0-rc.0
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/.docusaurus/DONT-EDIT-THIS-FOLDER +5 -0
- package/.docusaurus/client-modules.js +5 -0
- package/.docusaurus/codeTranslations.json +1 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/blog-only-aeb.json +10 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/blog-only-archive-245.json +312 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/blog-only-page-2-d48.json +11 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/blog-only-page-3-8b6.json +10 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/blog-only-tags-birthday-c96-list.json +9 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/blog-only-tags-birthday-c96.json +7 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/blog-only-tags-complex-cf3-list.json +9 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/blog-only-tags-complex-cf3.json +7 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/blog-only-tags-date-c24-list.json +9 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/blog-only-tags-date-c24.json +7 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/blog-only-tags-tags-344.json +17 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/blog-post-list-prop-default.json +30 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/plugin-route-context-module-100.json +4 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/site-src-tests-fixtures-website-blog-2018-12-14-happy-first-birthday-slash-md-d1e.json +46 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/site-src-tests-fixtures-website-blog-blog-with-links-mdx-fe5.json +22 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/site-src-tests-fixtures-website-blog-complex-slug-md-314.json +40 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/site-src-tests-fixtures-website-blog-date-matter-md-191.json +33 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/site-src-tests-fixtures-website-blog-heading-as-title-md-10c.json +25 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/site-src-tests-fixtures-website-blog-mdx-blog-post-mdx-025.json +26 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/site-src-tests-fixtures-website-blog-mdx-require-blog-post-mdx-4ba.json +26 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/site-src-tests-fixtures-website-blog-simple-slug-md-324.json +36 -0
- package/.docusaurus/docusaurus-plugin-content-blog/default/site-src-tests-fixtures-website-blog-unlisted-md-5cb.json +18 -0
- package/.docusaurus/docusaurus-theme-search-algolia/default/plugin-route-context-module-100.json +4 -0
- package/.docusaurus/docusaurus.config.mjs +246 -0
- package/.docusaurus/globalData.json +1 -0
- package/.docusaurus/i18n.json +17 -0
- package/.docusaurus/registry.js +38 -0
- package/.docusaurus/routes.js +99 -0
- package/.docusaurus/routesChunkNames.json +194 -0
- package/.docusaurus/site-metadata.json +24 -0
- package/lib/feed.js +32 -5
- package/lib/options.js +4 -1
- package/package.json +16 -14
- package/src/feed.ts +41 -5
- package/src/options.ts +4 -1
- package/src/plugin-content-blog.d.ts +2 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
{
|
|
2
|
+
"/blog-only/2018/12/14/Happy-First-Birthday-Slash-b2d": {
|
|
3
|
+
"__comp": "ccc49370",
|
|
4
|
+
"__context": {
|
|
5
|
+
"plugin": "1a450a71"
|
|
6
|
+
},
|
|
7
|
+
"sidebar": "814f3328",
|
|
8
|
+
"content": "d1e647af"
|
|
9
|
+
},
|
|
10
|
+
"/blog-only/archive-111": {
|
|
11
|
+
"__comp": "9e4087bc",
|
|
12
|
+
"__context": {
|
|
13
|
+
"plugin": "1a450a71"
|
|
14
|
+
},
|
|
15
|
+
"archive": "8941cadf"
|
|
16
|
+
},
|
|
17
|
+
"/blog-only/blog-with-links-b8a": {
|
|
18
|
+
"__comp": "ccc49370",
|
|
19
|
+
"__context": {
|
|
20
|
+
"plugin": "1a450a71"
|
|
21
|
+
},
|
|
22
|
+
"sidebar": "814f3328",
|
|
23
|
+
"content": "fe567c9f"
|
|
24
|
+
},
|
|
25
|
+
"/blog-only/date-matter-e95": {
|
|
26
|
+
"__comp": "ccc49370",
|
|
27
|
+
"__context": {
|
|
28
|
+
"plugin": "1a450a71"
|
|
29
|
+
},
|
|
30
|
+
"sidebar": "814f3328",
|
|
31
|
+
"content": "1910f98c"
|
|
32
|
+
},
|
|
33
|
+
"/blog-only/heading-as-title-01d": {
|
|
34
|
+
"__comp": "ccc49370",
|
|
35
|
+
"__context": {
|
|
36
|
+
"plugin": "1a450a71"
|
|
37
|
+
},
|
|
38
|
+
"sidebar": "814f3328",
|
|
39
|
+
"content": "10c8a0c7"
|
|
40
|
+
},
|
|
41
|
+
"/blog-only/hey/my super path/héllô-71d": {
|
|
42
|
+
"__comp": "ccc49370",
|
|
43
|
+
"__context": {
|
|
44
|
+
"plugin": "1a450a71"
|
|
45
|
+
},
|
|
46
|
+
"sidebar": "814f3328",
|
|
47
|
+
"content": "31456d57"
|
|
48
|
+
},
|
|
49
|
+
"/blog-only/mdx-blog-post-72e": {
|
|
50
|
+
"__comp": "ccc49370",
|
|
51
|
+
"__context": {
|
|
52
|
+
"plugin": "1a450a71"
|
|
53
|
+
},
|
|
54
|
+
"sidebar": "814f3328",
|
|
55
|
+
"content": "025bf2bf"
|
|
56
|
+
},
|
|
57
|
+
"/blog-only/mdx-require-blog-post-d01": {
|
|
58
|
+
"__comp": "ccc49370",
|
|
59
|
+
"__context": {
|
|
60
|
+
"plugin": "1a450a71"
|
|
61
|
+
},
|
|
62
|
+
"sidebar": "814f3328",
|
|
63
|
+
"content": "4baa0397"
|
|
64
|
+
},
|
|
65
|
+
"/blog-only/page/2-0a4": {
|
|
66
|
+
"__comp": "a6aa9e1f",
|
|
67
|
+
"__context": {
|
|
68
|
+
"plugin": "1a450a71"
|
|
69
|
+
},
|
|
70
|
+
"sidebar": "814f3328",
|
|
71
|
+
"items": [
|
|
72
|
+
{
|
|
73
|
+
"content": "8f113c1e"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"content": "2d0e482b"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"content": "fa937875"
|
|
80
|
+
}
|
|
81
|
+
],
|
|
82
|
+
"metadata": "3401dd63"
|
|
83
|
+
},
|
|
84
|
+
"/blog-only/page/3-070": {
|
|
85
|
+
"__comp": "a6aa9e1f",
|
|
86
|
+
"__context": {
|
|
87
|
+
"plugin": "1a450a71"
|
|
88
|
+
},
|
|
89
|
+
"sidebar": "814f3328",
|
|
90
|
+
"items": [
|
|
91
|
+
{
|
|
92
|
+
"content": "7050df0f"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"content": "69ddce25"
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
"metadata": "84412660"
|
|
99
|
+
},
|
|
100
|
+
"/blog-only/search-043": {
|
|
101
|
+
"__comp": "1a4e3797",
|
|
102
|
+
"__context": {
|
|
103
|
+
"plugin": "90fdef38"
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
"/blog-only/simple/slug-ff5": {
|
|
107
|
+
"__comp": "ccc49370",
|
|
108
|
+
"__context": {
|
|
109
|
+
"plugin": "1a450a71"
|
|
110
|
+
},
|
|
111
|
+
"sidebar": "814f3328",
|
|
112
|
+
"content": "324f81e8"
|
|
113
|
+
},
|
|
114
|
+
"/blog-only/tags-821": {
|
|
115
|
+
"__comp": "01a85c17",
|
|
116
|
+
"__context": {
|
|
117
|
+
"plugin": "1a450a71"
|
|
118
|
+
},
|
|
119
|
+
"sidebar": "814f3328",
|
|
120
|
+
"tags": "6fa419d5"
|
|
121
|
+
},
|
|
122
|
+
"/blog-only/tags/birthday-8e4": {
|
|
123
|
+
"__comp": "6875c492",
|
|
124
|
+
"__context": {
|
|
125
|
+
"plugin": "1a450a71"
|
|
126
|
+
},
|
|
127
|
+
"sidebar": "814f3328",
|
|
128
|
+
"items": [
|
|
129
|
+
{
|
|
130
|
+
"content": "69ddce25"
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
"tag": "0cc99ed5",
|
|
134
|
+
"listMetadata": "44bf5914"
|
|
135
|
+
},
|
|
136
|
+
"/blog-only/tags/complex-f0f": {
|
|
137
|
+
"__comp": "6875c492",
|
|
138
|
+
"__context": {
|
|
139
|
+
"plugin": "1a450a71"
|
|
140
|
+
},
|
|
141
|
+
"sidebar": "814f3328",
|
|
142
|
+
"items": [
|
|
143
|
+
{
|
|
144
|
+
"content": "8f113c1e"
|
|
145
|
+
}
|
|
146
|
+
],
|
|
147
|
+
"tag": "1b99ff01",
|
|
148
|
+
"listMetadata": "b5733902"
|
|
149
|
+
},
|
|
150
|
+
"/blog-only/tags/date-b36": {
|
|
151
|
+
"__comp": "6875c492",
|
|
152
|
+
"__context": {
|
|
153
|
+
"plugin": "1a450a71"
|
|
154
|
+
},
|
|
155
|
+
"sidebar": "814f3328",
|
|
156
|
+
"items": [
|
|
157
|
+
{
|
|
158
|
+
"content": "8f113c1e"
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"content": "7050df0f"
|
|
162
|
+
}
|
|
163
|
+
],
|
|
164
|
+
"tag": "59ce4a4b",
|
|
165
|
+
"listMetadata": "447a0fe3"
|
|
166
|
+
},
|
|
167
|
+
"/blog-only/unlisted-8d8": {
|
|
168
|
+
"__comp": "ccc49370",
|
|
169
|
+
"__context": {
|
|
170
|
+
"plugin": "1a450a71"
|
|
171
|
+
},
|
|
172
|
+
"sidebar": "814f3328",
|
|
173
|
+
"content": "5cb65b8e"
|
|
174
|
+
},
|
|
175
|
+
"/blog-only/-813": {
|
|
176
|
+
"__comp": "a6aa9e1f",
|
|
177
|
+
"__context": {
|
|
178
|
+
"plugin": "1a450a71"
|
|
179
|
+
},
|
|
180
|
+
"sidebar": "814f3328",
|
|
181
|
+
"items": [
|
|
182
|
+
{
|
|
183
|
+
"content": "6dea708c"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"content": "5bd9aa47"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
"content": "3cdbedcf"
|
|
190
|
+
}
|
|
191
|
+
],
|
|
192
|
+
"metadata": "163f190c"
|
|
193
|
+
}
|
|
194
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"docusaurusVersion": "3.0.0-alpha.0",
|
|
3
|
+
"siteVersion": "3.0.0-alpha.0",
|
|
4
|
+
"pluginVersions": {
|
|
5
|
+
"docusaurus-plugin-content-blog": {
|
|
6
|
+
"type": "project"
|
|
7
|
+
},
|
|
8
|
+
"docusaurus-plugin-sitemap": {
|
|
9
|
+
"type": "package",
|
|
10
|
+
"name": "@docusaurus/plugin-sitemap",
|
|
11
|
+
"version": "3.0.0-alpha.0"
|
|
12
|
+
},
|
|
13
|
+
"docusaurus-theme-classic": {
|
|
14
|
+
"type": "package",
|
|
15
|
+
"name": "@docusaurus/theme-classic",
|
|
16
|
+
"version": "3.0.0-alpha.0"
|
|
17
|
+
},
|
|
18
|
+
"docusaurus-theme-search-algolia": {
|
|
19
|
+
"type": "package",
|
|
20
|
+
"name": "@docusaurus/theme-search-algolia",
|
|
21
|
+
"version": "3.0.0-alpha.0"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
package/lib/feed.js
CHANGED
|
@@ -12,6 +12,7 @@ const path_1 = tslib_1.__importDefault(require("path"));
|
|
|
12
12
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
13
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
14
|
const feed_1 = require("feed");
|
|
15
|
+
const srcset = tslib_1.__importStar(require("srcset"));
|
|
15
16
|
const utils_1 = require("@docusaurus/utils");
|
|
16
17
|
const utils_common_1 = require("@docusaurus/utils-common");
|
|
17
18
|
const cheerio_1 = require("cheerio");
|
|
@@ -22,7 +23,10 @@ async function generateBlogFeed({ blogPosts, options, siteConfig, outDir, locale
|
|
|
22
23
|
const { feedOptions, routeBasePath } = options;
|
|
23
24
|
const { url: siteUrl, baseUrl, title, favicon } = siteConfig;
|
|
24
25
|
const blogBaseUrl = (0, utils_1.normalizeUrl)([siteUrl, baseUrl, routeBasePath]);
|
|
25
|
-
const
|
|
26
|
+
const blogPostsForFeed = feedOptions.limit === false || feedOptions.limit === null
|
|
27
|
+
? blogPosts
|
|
28
|
+
: blogPosts.slice(0, feedOptions.limit);
|
|
29
|
+
const updated = blogPostsForFeed[0]?.metadata.date;
|
|
26
30
|
const feed = new feed_1.Feed({
|
|
27
31
|
id: blogBaseUrl,
|
|
28
32
|
title: feedOptions.title ?? `${title} Blog`,
|
|
@@ -35,7 +39,7 @@ async function generateBlogFeed({ blogPosts, options, siteConfig, outDir, locale
|
|
|
35
39
|
});
|
|
36
40
|
const createFeedItems = options.feedOptions.createFeedItems ?? defaultCreateFeedItems;
|
|
37
41
|
const feedItems = await createFeedItems({
|
|
38
|
-
blogPosts,
|
|
42
|
+
blogPosts: blogPostsForFeed,
|
|
39
43
|
siteConfig,
|
|
40
44
|
outDir,
|
|
41
45
|
defaultCreateFeedItems,
|
|
@@ -52,11 +56,34 @@ async function defaultCreateFeedItems({ blogPosts, siteConfig, outDir, }) {
|
|
|
52
56
|
const { metadata: { title: metadataTitle, permalink, date, description, authors, tags, }, } = post;
|
|
53
57
|
const content = await (0, utils_1.readOutputHTMLFile)(permalink.replace(siteConfig.baseUrl, ''), outDir, siteConfig.trailingSlash);
|
|
54
58
|
const $ = (0, cheerio_1.load)(content);
|
|
55
|
-
const
|
|
59
|
+
const blogPostAbsoluteUrl = (0, utils_1.normalizeUrl)([siteUrl, permalink]);
|
|
60
|
+
const toAbsoluteUrl = (src) => String(new URL(src, blogPostAbsoluteUrl));
|
|
61
|
+
// Make links and image urls absolute
|
|
62
|
+
// See https://github.com/facebook/docusaurus/issues/9136
|
|
63
|
+
$(`div#${utils_common_1.blogPostContainerID} a, div#${utils_common_1.blogPostContainerID} img`).each((_, elm) => {
|
|
64
|
+
if (elm.tagName === 'a') {
|
|
65
|
+
const { href } = elm.attribs;
|
|
66
|
+
if (href) {
|
|
67
|
+
elm.attribs.href = toAbsoluteUrl(href);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (elm.tagName === 'img') {
|
|
71
|
+
const { src, srcset: srcsetAttr } = elm.attribs;
|
|
72
|
+
if (src) {
|
|
73
|
+
elm.attribs.src = toAbsoluteUrl(src);
|
|
74
|
+
}
|
|
75
|
+
if (srcsetAttr) {
|
|
76
|
+
elm.attribs.srcset = srcset.stringify(srcset.parse(srcsetAttr).map((props) => ({
|
|
77
|
+
...props,
|
|
78
|
+
url: toAbsoluteUrl(props.url),
|
|
79
|
+
})));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
56
83
|
const feedItem = {
|
|
57
84
|
title: metadataTitle,
|
|
58
|
-
id:
|
|
59
|
-
link,
|
|
85
|
+
id: blogPostAbsoluteUrl,
|
|
86
|
+
link: blogPostAbsoluteUrl,
|
|
60
87
|
date,
|
|
61
88
|
description,
|
|
62
89
|
// Atom feed demands the "term", while other feeds use "name"
|
package/lib/options.js
CHANGED
|
@@ -10,7 +10,7 @@ exports.validateOptions = exports.DEFAULT_OPTIONS = void 0;
|
|
|
10
10
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
11
|
const utils_1 = require("@docusaurus/utils");
|
|
12
12
|
exports.DEFAULT_OPTIONS = {
|
|
13
|
-
feedOptions: { type: ['rss', 'atom'], copyright: '' },
|
|
13
|
+
feedOptions: { type: ['rss', 'atom'], copyright: '', limit: 20 },
|
|
14
14
|
beforeDefaultRehypePlugins: [],
|
|
15
15
|
beforeDefaultRemarkPlugins: [],
|
|
16
16
|
admonitions: true,
|
|
@@ -92,6 +92,9 @@ const PluginOptionSchema = utils_validation_1.Joi.object({
|
|
|
92
92
|
}),
|
|
93
93
|
language: utils_validation_1.Joi.string(),
|
|
94
94
|
createFeedItems: utils_validation_1.Joi.function(),
|
|
95
|
+
limit: utils_validation_1.Joi.alternatives()
|
|
96
|
+
.try(utils_validation_1.Joi.number(), utils_validation_1.Joi.valid(null), utils_validation_1.Joi.valid(false))
|
|
97
|
+
.default(exports.DEFAULT_OPTIONS.feedOptions.limit),
|
|
95
98
|
}).default(exports.DEFAULT_OPTIONS.feedOptions),
|
|
96
99
|
authorsMapPath: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.authorsMapPath),
|
|
97
100
|
readingTime: utils_validation_1.Joi.function().default(() => exports.DEFAULT_OPTIONS.readingTime),
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-blog",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-rc.0",
|
|
4
4
|
"description": "Blog plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-content-blog.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"watch": "tsc --watch"
|
|
9
|
+
"watch": "tsc --watch",
|
|
10
|
+
"test:generate-build-snap": "yarn docusaurus build src/__tests__/__fixtures__/website --out-dir build-snap && yarn rimraf src/__tests__/__fixtures__/website/.docusaurus && yarn rimraf src/__tests__/__fixtures__/website/build-snap/assets && git add src/__tests__/__fixtures__/website/build-snap"
|
|
10
11
|
},
|
|
11
12
|
"repository": {
|
|
12
13
|
"type": "git",
|
|
@@ -18,29 +19,30 @@
|
|
|
18
19
|
},
|
|
19
20
|
"license": "MIT",
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"@docusaurus/core": "3.0.0-
|
|
22
|
-
"@docusaurus/logger": "3.0.0-
|
|
23
|
-
"@docusaurus/mdx-loader": "3.0.0-
|
|
24
|
-
"@docusaurus/types": "3.0.0-
|
|
25
|
-
"@docusaurus/utils": "3.0.0-
|
|
26
|
-
"@docusaurus/utils-common": "3.0.0-
|
|
27
|
-
"@docusaurus/utils-validation": "3.0.0-
|
|
22
|
+
"@docusaurus/core": "3.0.0-rc.0",
|
|
23
|
+
"@docusaurus/logger": "3.0.0-rc.0",
|
|
24
|
+
"@docusaurus/mdx-loader": "3.0.0-rc.0",
|
|
25
|
+
"@docusaurus/types": "3.0.0-rc.0",
|
|
26
|
+
"@docusaurus/utils": "3.0.0-rc.0",
|
|
27
|
+
"@docusaurus/utils-common": "3.0.0-rc.0",
|
|
28
|
+
"@docusaurus/utils-validation": "3.0.0-rc.0",
|
|
28
29
|
"cheerio": "^1.0.0-rc.12",
|
|
29
30
|
"feed": "^4.2.2",
|
|
30
|
-
"fs-extra": "^11.1.
|
|
31
|
+
"fs-extra": "^11.1.1",
|
|
31
32
|
"lodash": "^4.17.21",
|
|
32
33
|
"reading-time": "^1.5.0",
|
|
33
|
-
"
|
|
34
|
+
"srcset": "^4.0.0",
|
|
35
|
+
"tslib": "^2.6.0",
|
|
34
36
|
"unist-util-visit": "^2.0.3",
|
|
35
37
|
"utility-types": "^3.10.0",
|
|
36
|
-
"webpack": "^5.
|
|
38
|
+
"webpack": "^5.88.1"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
39
41
|
"react": "^18.0.0",
|
|
40
42
|
"react-dom": "^18.0.0"
|
|
41
43
|
},
|
|
42
44
|
"engines": {
|
|
43
|
-
"node": ">=
|
|
45
|
+
"node": ">=18.0"
|
|
44
46
|
},
|
|
45
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "e66dfe04d2972edce66f431908470c61340f8ffc"
|
|
46
48
|
}
|
package/src/feed.ts
CHANGED
|
@@ -9,6 +9,7 @@ import path from 'path';
|
|
|
9
9
|
import fs from 'fs-extra';
|
|
10
10
|
import logger from '@docusaurus/logger';
|
|
11
11
|
import {Feed, type Author as FeedAuthor} from 'feed';
|
|
12
|
+
import * as srcset from 'srcset';
|
|
12
13
|
import {normalizeUrl, readOutputHTMLFile} from '@docusaurus/utils';
|
|
13
14
|
import {blogPostContainerID} from '@docusaurus/utils-common';
|
|
14
15
|
import {load as cheerioLoad} from 'cheerio';
|
|
@@ -42,7 +43,12 @@ async function generateBlogFeed({
|
|
|
42
43
|
const {url: siteUrl, baseUrl, title, favicon} = siteConfig;
|
|
43
44
|
const blogBaseUrl = normalizeUrl([siteUrl, baseUrl, routeBasePath]);
|
|
44
45
|
|
|
45
|
-
const
|
|
46
|
+
const blogPostsForFeed =
|
|
47
|
+
feedOptions.limit === false || feedOptions.limit === null
|
|
48
|
+
? blogPosts
|
|
49
|
+
: blogPosts.slice(0, feedOptions.limit);
|
|
50
|
+
|
|
51
|
+
const updated = blogPostsForFeed[0]?.metadata.date;
|
|
46
52
|
|
|
47
53
|
const feed = new Feed({
|
|
48
54
|
id: blogBaseUrl,
|
|
@@ -59,7 +65,7 @@ async function generateBlogFeed({
|
|
|
59
65
|
options.feedOptions.createFeedItems ?? defaultCreateFeedItems;
|
|
60
66
|
|
|
61
67
|
const feedItems = await createFeedItems({
|
|
62
|
-
blogPosts,
|
|
68
|
+
blogPosts: blogPostsForFeed,
|
|
63
69
|
siteConfig,
|
|
64
70
|
outDir,
|
|
65
71
|
defaultCreateFeedItems,
|
|
@@ -105,11 +111,41 @@ async function defaultCreateFeedItems({
|
|
|
105
111
|
);
|
|
106
112
|
const $ = cheerioLoad(content);
|
|
107
113
|
|
|
108
|
-
const
|
|
114
|
+
const blogPostAbsoluteUrl = normalizeUrl([siteUrl, permalink]);
|
|
115
|
+
|
|
116
|
+
const toAbsoluteUrl = (src: string) =>
|
|
117
|
+
String(new URL(src, blogPostAbsoluteUrl));
|
|
118
|
+
|
|
119
|
+
// Make links and image urls absolute
|
|
120
|
+
// See https://github.com/facebook/docusaurus/issues/9136
|
|
121
|
+
$(`div#${blogPostContainerID} a, div#${blogPostContainerID} img`).each(
|
|
122
|
+
(_, elm) => {
|
|
123
|
+
if (elm.tagName === 'a') {
|
|
124
|
+
const {href} = elm.attribs;
|
|
125
|
+
if (href) {
|
|
126
|
+
elm.attribs.href = toAbsoluteUrl(href);
|
|
127
|
+
}
|
|
128
|
+
} else if (elm.tagName === 'img') {
|
|
129
|
+
const {src, srcset: srcsetAttr} = elm.attribs;
|
|
130
|
+
if (src) {
|
|
131
|
+
elm.attribs.src = toAbsoluteUrl(src);
|
|
132
|
+
}
|
|
133
|
+
if (srcsetAttr) {
|
|
134
|
+
elm.attribs.srcset = srcset.stringify(
|
|
135
|
+
srcset.parse(srcsetAttr).map((props) => ({
|
|
136
|
+
...props,
|
|
137
|
+
url: toAbsoluteUrl(props.url),
|
|
138
|
+
})),
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
);
|
|
144
|
+
|
|
109
145
|
const feedItem: BlogFeedItem = {
|
|
110
146
|
title: metadataTitle,
|
|
111
|
-
id:
|
|
112
|
-
link,
|
|
147
|
+
id: blogPostAbsoluteUrl,
|
|
148
|
+
link: blogPostAbsoluteUrl,
|
|
113
149
|
date,
|
|
114
150
|
description,
|
|
115
151
|
// Atom feed demands the "term", while other feeds use "name"
|
package/src/options.ts
CHANGED
|
@@ -22,7 +22,7 @@ import type {
|
|
|
22
22
|
import type {OptionValidationContext} from '@docusaurus/types';
|
|
23
23
|
|
|
24
24
|
export const DEFAULT_OPTIONS: PluginOptions = {
|
|
25
|
-
feedOptions: {type: ['rss', 'atom'], copyright: ''},
|
|
25
|
+
feedOptions: {type: ['rss', 'atom'], copyright: '', limit: 20},
|
|
26
26
|
beforeDefaultRehypePlugins: [],
|
|
27
27
|
beforeDefaultRemarkPlugins: [],
|
|
28
28
|
admonitions: true,
|
|
@@ -123,6 +123,9 @@ const PluginOptionSchema = Joi.object<PluginOptions>({
|
|
|
123
123
|
}),
|
|
124
124
|
language: Joi.string(),
|
|
125
125
|
createFeedItems: Joi.function(),
|
|
126
|
+
limit: Joi.alternatives()
|
|
127
|
+
.try(Joi.number(), Joi.valid(null), Joi.valid(false))
|
|
128
|
+
.default(DEFAULT_OPTIONS.feedOptions.limit),
|
|
126
129
|
}).default(DEFAULT_OPTIONS.feedOptions),
|
|
127
130
|
authorsMapPath: Joi.string().default(DEFAULT_OPTIONS.authorsMapPath),
|
|
128
131
|
readingTime: Joi.function().default(() => DEFAULT_OPTIONS.readingTime),
|
|
@@ -272,6 +272,8 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the
|
|
|
272
272
|
language?: string;
|
|
273
273
|
/** Allow control over the construction of BlogFeedItems */
|
|
274
274
|
createFeedItems?: CreateFeedItemsFn;
|
|
275
|
+
/** Limits the feed to the specified number of posts, false|null for all */
|
|
276
|
+
limit?: number | false | null;
|
|
275
277
|
};
|
|
276
278
|
|
|
277
279
|
type DefaultCreateFeedItemsParams = {
|