@docusaurus/plugin-content-blog 2.4.1 → 3.0.0-beta.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/authors.d.ts +2 -2
- package/lib/blogUtils.d.ts +3 -2
- package/lib/blogUtils.js +30 -16
- package/lib/feed.d.ts +1 -1
- package/lib/feed.js +39 -6
- package/lib/frontMatter.js +4 -3
- package/lib/index.js +12 -19
- package/lib/options.js +6 -6
- package/lib/props.d.ts +15 -0
- package/lib/props.js +23 -0
- package/lib/types.d.ts +3 -3
- package/package.json +17 -15
- package/src/blogUtils.ts +47 -28
- package/src/feed.ts +51 -6
- package/src/frontMatter.ts +7 -5
- package/src/index.ts +13 -23
- package/src/options.ts +7 -6
- package/src/plugin-content-blog.d.ts +18 -1
- package/src/props.ts +34 -0
- package/src/remark/footnoteIDFixer.ts +1 -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/authors.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { BlogContentPaths } from './types';
|
|
8
8
|
import type { Author, BlogPostFrontMatter } from '@docusaurus/plugin-content-blog';
|
|
9
|
-
export
|
|
9
|
+
export type AuthorsMap = {
|
|
10
10
|
[authorKey: string]: Author;
|
|
11
11
|
};
|
|
12
12
|
export declare function validateAuthorsMap(content: unknown): AuthorsMap;
|
|
@@ -14,7 +14,7 @@ export declare function getAuthorsMap(params: {
|
|
|
14
14
|
authorsMapPath: string;
|
|
15
15
|
contentPaths: BlogContentPaths;
|
|
16
16
|
}): Promise<AuthorsMap | undefined>;
|
|
17
|
-
|
|
17
|
+
type AuthorsParam = {
|
|
18
18
|
frontMatter: BlogPostFrontMatter;
|
|
19
19
|
authorsMap: AuthorsMap | undefined;
|
|
20
20
|
};
|
package/lib/blogUtils.d.ts
CHANGED
|
@@ -18,20 +18,21 @@ export declare function paginateBlogPosts({ blogPosts, basePageUrl, blogTitle, b
|
|
|
18
18
|
blogDescription: string;
|
|
19
19
|
postsPerPageOption: number | 'ALL';
|
|
20
20
|
}): BlogPaginated[];
|
|
21
|
+
export declare function shouldBeListed(blogPost: BlogPost): boolean;
|
|
21
22
|
export declare function getBlogTags({ blogPosts, ...params }: {
|
|
22
23
|
blogPosts: BlogPost[];
|
|
23
24
|
blogTitle: string;
|
|
24
25
|
blogDescription: string;
|
|
25
26
|
postsPerPageOption: number | 'ALL';
|
|
26
27
|
}): BlogTags;
|
|
27
|
-
|
|
28
|
+
type ParsedBlogFileName = {
|
|
28
29
|
date: Date | undefined;
|
|
29
30
|
text: string;
|
|
30
31
|
slug: string;
|
|
31
32
|
};
|
|
32
33
|
export declare function parseBlogFileName(blogSourceRelative: string): ParsedBlogFileName;
|
|
33
34
|
export declare function generateBlogPosts(contentPaths: BlogContentPaths, context: LoadContext, options: PluginOptions): Promise<BlogPost[]>;
|
|
34
|
-
export
|
|
35
|
+
export type LinkifyParams = {
|
|
35
36
|
filePath: string;
|
|
36
37
|
fileString: string;
|
|
37
38
|
} & Pick<BlogMarkdownLoaderOptions, 'sourceToPermalink' | 'siteDir' | 'contentPaths' | 'onBrokenMarkdownLink'>;
|
package/lib/blogUtils.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.linkify = exports.generateBlogPosts = exports.parseBlogFileName = exports.getBlogTags = exports.paginateBlogPosts = exports.getSourceToPermalink = exports.truncate = void 0;
|
|
9
|
+
exports.linkify = exports.generateBlogPosts = exports.parseBlogFileName = exports.getBlogTags = exports.shouldBeListed = exports.paginateBlogPosts = exports.getSourceToPermalink = exports.truncate = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
@@ -55,18 +55,29 @@ function paginateBlogPosts({ blogPosts, basePageUrl, blogTitle, blogDescription,
|
|
|
55
55
|
return pages;
|
|
56
56
|
}
|
|
57
57
|
exports.paginateBlogPosts = paginateBlogPosts;
|
|
58
|
+
function shouldBeListed(blogPost) {
|
|
59
|
+
return !blogPost.metadata.unlisted;
|
|
60
|
+
}
|
|
61
|
+
exports.shouldBeListed = shouldBeListed;
|
|
58
62
|
function getBlogTags({ blogPosts, ...params }) {
|
|
59
63
|
const groups = (0, utils_1.groupTaggedItems)(blogPosts, (blogPost) => blogPost.metadata.tags);
|
|
60
|
-
return lodash_1.default.mapValues(groups, ({ tag, items: tagBlogPosts }) =>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
return lodash_1.default.mapValues(groups, ({ tag, items: tagBlogPosts }) => {
|
|
65
|
+
const tagVisibility = (0, utils_1.getTagVisibility)({
|
|
66
|
+
items: tagBlogPosts,
|
|
67
|
+
isUnlisted: (item) => item.metadata.unlisted,
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
label: tag.label,
|
|
71
|
+
items: tagVisibility.listedItems.map((item) => item.id),
|
|
72
|
+
permalink: tag.permalink,
|
|
73
|
+
pages: paginateBlogPosts({
|
|
74
|
+
blogPosts: tagVisibility.listedItems,
|
|
75
|
+
basePageUrl: tag.permalink,
|
|
76
|
+
...params,
|
|
77
|
+
}),
|
|
78
|
+
unlisted: tagVisibility.unlisted,
|
|
79
|
+
};
|
|
80
|
+
});
|
|
70
81
|
}
|
|
71
82
|
exports.getBlogTags = getBlogTags;
|
|
72
83
|
const DATE_FILENAME_REGEX = /^(?<folder>.*)(?<date>\d{4}[-/]\d{1,2}[-/]\d{1,2})[-/]?(?<text>.*?)(?:\/index)?.mdx?$/;
|
|
@@ -125,7 +136,9 @@ async function processBlogSourceFile(blogSourceRelative, contentPaths, context,
|
|
|
125
136
|
const blogSourceAbsolute = path_1.default.join(blogDirPath, blogSourceRelative);
|
|
126
137
|
const { frontMatter, content, contentTitle, excerpt } = await parseBlogPostMarkdownFile(blogSourceAbsolute);
|
|
127
138
|
const aliasedSource = (0, utils_1.aliasedSitePath)(blogSourceAbsolute, siteDir);
|
|
128
|
-
|
|
139
|
+
const draft = (0, utils_1.isDraft)({ frontMatter });
|
|
140
|
+
const unlisted = (0, utils_1.isUnlisted)({ frontMatter });
|
|
141
|
+
if (draft) {
|
|
129
142
|
return undefined;
|
|
130
143
|
}
|
|
131
144
|
if (frontMatter.id) {
|
|
@@ -213,6 +226,7 @@ async function processBlogSourceFile(blogSourceRelative, contentPaths, context,
|
|
|
213
226
|
hasTruncateMarker: truncateMarker.test(content),
|
|
214
227
|
authors,
|
|
215
228
|
frontMatter,
|
|
229
|
+
unlisted,
|
|
216
230
|
},
|
|
217
231
|
content,
|
|
218
232
|
};
|
|
@@ -230,15 +244,15 @@ async function generateBlogPosts(contentPaths, context, options) {
|
|
|
230
244
|
contentPaths,
|
|
231
245
|
authorsMapPath: options.authorsMapPath,
|
|
232
246
|
});
|
|
233
|
-
|
|
247
|
+
async function doProcessBlogSourceFile(blogSourceFile) {
|
|
234
248
|
try {
|
|
235
249
|
return await processBlogSourceFile(blogSourceFile, contentPaths, context, options, authorsMap);
|
|
236
250
|
}
|
|
237
251
|
catch (err) {
|
|
238
|
-
|
|
239
|
-
throw err;
|
|
252
|
+
throw new Error(`Processing of blog source file path=${blogSourceFile} failed.`, { cause: err });
|
|
240
253
|
}
|
|
241
|
-
}
|
|
254
|
+
}
|
|
255
|
+
const blogPosts = (await Promise.all(blogSourceFiles.map(doProcessBlogSourceFile))).filter(Boolean);
|
|
242
256
|
blogPosts.sort((a, b) => b.metadata.date.getTime() - a.metadata.date.getTime());
|
|
243
257
|
if (options.sortPosts === 'ascending') {
|
|
244
258
|
return blogPosts.reverse();
|
package/lib/feed.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { DocusaurusConfig } from '@docusaurus/types';
|
|
8
8
|
import type { PluginOptions, BlogPost } from '@docusaurus/plugin-content-blog';
|
|
9
|
-
export declare function createBlogFeedFiles({ blogPosts, options, siteConfig, outDir, locale, }: {
|
|
9
|
+
export declare function createBlogFeedFiles({ blogPosts: allBlogPosts, options, siteConfig, outDir, locale, }: {
|
|
10
10
|
blogPosts: BlogPost[];
|
|
11
11
|
options: PluginOptions;
|
|
12
12
|
siteConfig: DocusaurusConfig;
|
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"
|
|
@@ -93,7 +120,13 @@ async function createBlogFeedFile({ feed, feedType, generatePath, }) {
|
|
|
93
120
|
throw err;
|
|
94
121
|
}
|
|
95
122
|
}
|
|
96
|
-
|
|
123
|
+
function shouldBeInFeed(blogPost) {
|
|
124
|
+
const excluded = blogPost.metadata.frontMatter.draft ||
|
|
125
|
+
blogPost.metadata.frontMatter.unlisted;
|
|
126
|
+
return !excluded;
|
|
127
|
+
}
|
|
128
|
+
async function createBlogFeedFiles({ blogPosts: allBlogPosts, options, siteConfig, outDir, locale, }) {
|
|
129
|
+
const blogPosts = allBlogPosts.filter(shouldBeInFeed);
|
|
97
130
|
const feed = await generateBlogFeed({
|
|
98
131
|
blogPosts,
|
|
99
132
|
options,
|
package/lib/frontMatter.js
CHANGED
|
@@ -23,7 +23,6 @@ const BlogFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
|
23
23
|
title: utils_validation_1.JoiFrontMatter.string().allow(''),
|
|
24
24
|
description: utils_validation_1.JoiFrontMatter.string().allow(''),
|
|
25
25
|
tags: utils_validation_1.FrontMatterTagsSchema,
|
|
26
|
-
draft: utils_validation_1.JoiFrontMatter.boolean(),
|
|
27
26
|
date: utils_validation_1.JoiFrontMatter.date().raw(),
|
|
28
27
|
// New multi-authors front matter:
|
|
29
28
|
authors: utils_validation_1.JoiFrontMatter.alternatives()
|
|
@@ -53,9 +52,11 @@ const BlogFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
|
53
52
|
keywords: utils_validation_1.JoiFrontMatter.array().items(utils_validation_1.JoiFrontMatter.string().required()),
|
|
54
53
|
hide_table_of_contents: utils_validation_1.JoiFrontMatter.boolean(),
|
|
55
54
|
...utils_validation_1.FrontMatterTOCHeadingLevels,
|
|
56
|
-
})
|
|
55
|
+
})
|
|
56
|
+
.messages({
|
|
57
57
|
'deprecate.error': '{#label} blog frontMatter field is deprecated. Please use {#alternative} instead.',
|
|
58
|
-
})
|
|
58
|
+
})
|
|
59
|
+
.concat(utils_validation_1.ContentVisibilitySchema);
|
|
59
60
|
function validateBlogPostFrontMatter(frontMatter) {
|
|
60
61
|
return (0, utils_validation_1.validateFrontMatter)(frontMatter, BlogFrontMatterSchema);
|
|
61
62
|
}
|
package/lib/index.js
CHANGED
|
@@ -15,6 +15,7 @@ const blogUtils_1 = require("./blogUtils");
|
|
|
15
15
|
const footnoteIDFixer_1 = tslib_1.__importDefault(require("./remark/footnoteIDFixer"));
|
|
16
16
|
const translations_1 = require("./translations");
|
|
17
17
|
const feed_1 = require("./feed");
|
|
18
|
+
const props_1 = require("./props");
|
|
18
19
|
async function pluginContentBlog(context, options) {
|
|
19
20
|
const { siteDir, siteConfig, generatedFilesDir, localizationDir, i18n: { currentLocale }, } = context;
|
|
20
21
|
const { onBrokenMarkdownLinks, baseUrl } = siteConfig;
|
|
@@ -50,6 +51,7 @@ async function pluginContentBlog(context, options) {
|
|
|
50
51
|
const baseBlogUrl = (0, utils_1.normalizeUrl)([baseUrl, routeBasePath]);
|
|
51
52
|
const blogTagsListPath = (0, utils_1.normalizeUrl)([baseBlogUrl, tagsBasePath]);
|
|
52
53
|
const blogPosts = await (0, blogUtils_1.generateBlogPosts)(contentPaths, context, options);
|
|
54
|
+
const listedBlogPosts = blogPosts.filter(blogUtils_1.shouldBeListed);
|
|
53
55
|
if (!blogPosts.length) {
|
|
54
56
|
return {
|
|
55
57
|
blogSidebarTitle,
|
|
@@ -61,15 +63,17 @@ async function pluginContentBlog(context, options) {
|
|
|
61
63
|
};
|
|
62
64
|
}
|
|
63
65
|
// Colocate next and prev metadata.
|
|
64
|
-
|
|
65
|
-
const prevItem = index > 0 ?
|
|
66
|
+
listedBlogPosts.forEach((blogPost, index) => {
|
|
67
|
+
const prevItem = index > 0 ? listedBlogPosts[index - 1] : null;
|
|
66
68
|
if (prevItem) {
|
|
67
69
|
blogPost.metadata.prevItem = {
|
|
68
70
|
title: prevItem.metadata.title,
|
|
69
71
|
permalink: prevItem.metadata.permalink,
|
|
70
72
|
};
|
|
71
73
|
}
|
|
72
|
-
const nextItem = index <
|
|
74
|
+
const nextItem = index < listedBlogPosts.length - 1
|
|
75
|
+
? listedBlogPosts[index + 1]
|
|
76
|
+
: null;
|
|
73
77
|
if (nextItem) {
|
|
74
78
|
blogPost.metadata.nextItem = {
|
|
75
79
|
title: nextItem.metadata.title,
|
|
@@ -78,7 +82,7 @@ async function pluginContentBlog(context, options) {
|
|
|
78
82
|
}
|
|
79
83
|
});
|
|
80
84
|
const blogListPaginated = (0, blogUtils_1.paginateBlogPosts)({
|
|
81
|
-
blogPosts,
|
|
85
|
+
blogPosts: listedBlogPosts,
|
|
82
86
|
blogTitle,
|
|
83
87
|
blogDescription,
|
|
84
88
|
postsPerPageOption,
|
|
@@ -146,6 +150,7 @@ async function pluginContentBlog(context, options) {
|
|
|
146
150
|
items: sidebarBlogPosts.map((blogPost) => ({
|
|
147
151
|
title: blogPost.metadata.title,
|
|
148
152
|
permalink: blogPost.metadata.permalink,
|
|
153
|
+
unlisted: blogPost.metadata.unlisted,
|
|
149
154
|
})),
|
|
150
155
|
}, null, 2));
|
|
151
156
|
// Create routes for blog entries.
|
|
@@ -187,12 +192,7 @@ async function pluginContentBlog(context, options) {
|
|
|
187
192
|
return;
|
|
188
193
|
}
|
|
189
194
|
async function createTagsListPage() {
|
|
190
|
-
const
|
|
191
|
-
label: tag.label,
|
|
192
|
-
permalink: tag.permalink,
|
|
193
|
-
count: tag.items.length,
|
|
194
|
-
}));
|
|
195
|
-
const tagsPropPath = await createData(`${(0, utils_1.docuHash)(`${blogTagsListPath}-tags`)}.json`, JSON.stringify(tagsProp, null, 2));
|
|
195
|
+
const tagsPropPath = await createData(`${(0, utils_1.docuHash)(`${blogTagsListPath}-tags`)}.json`, JSON.stringify((0, props_1.toTagsProp)({ blogTags }), null, 2));
|
|
196
196
|
addRoute({
|
|
197
197
|
path: blogTagsListPath,
|
|
198
198
|
component: blogTagsListComponent,
|
|
@@ -206,13 +206,7 @@ async function pluginContentBlog(context, options) {
|
|
|
206
206
|
async function createTagPostsListPage(tag) {
|
|
207
207
|
await Promise.all(tag.pages.map(async (blogPaginated) => {
|
|
208
208
|
const { metadata, items } = blogPaginated;
|
|
209
|
-
const
|
|
210
|
-
label: tag.label,
|
|
211
|
-
permalink: tag.permalink,
|
|
212
|
-
allTagsPath: blogTagsListPath,
|
|
213
|
-
count: tag.items.length,
|
|
214
|
-
};
|
|
215
|
-
const tagPropPath = await createData(`${(0, utils_1.docuHash)(metadata.permalink)}.json`, JSON.stringify(tagProp, null, 2));
|
|
209
|
+
const tagPropPath = await createData(`${(0, utils_1.docuHash)(metadata.permalink)}.json`, JSON.stringify((0, props_1.toTagProp)({ tag, blogTagsListPath }), null, 2));
|
|
216
210
|
const listMetadataPath = await createData(`${(0, utils_1.docuHash)(metadata.permalink)}-list.json`, JSON.stringify(metadata, null, 2));
|
|
217
211
|
addRoute({
|
|
218
212
|
path: metadata.permalink,
|
|
@@ -233,7 +227,7 @@ async function pluginContentBlog(context, options) {
|
|
|
233
227
|
translateContent({ content, translationFiles }) {
|
|
234
228
|
return (0, translations_1.translateContent)(content, translationFiles);
|
|
235
229
|
},
|
|
236
|
-
configureWebpack(_config, isServer,
|
|
230
|
+
configureWebpack(_config, isServer, utils, content) {
|
|
237
231
|
const { admonitions, rehypePlugins, remarkPlugins, truncateMarker, beforeDefaultRemarkPlugins, beforeDefaultRehypePlugins, } = options;
|
|
238
232
|
const markdownLoaderOptions = {
|
|
239
233
|
siteDir,
|
|
@@ -262,7 +256,6 @@ async function pluginContentBlog(context, options) {
|
|
|
262
256
|
// Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
|
|
263
257
|
.map(utils_1.addTrailingPathSeparator),
|
|
264
258
|
use: [
|
|
265
|
-
getJSLoader({ isServer }),
|
|
266
259
|
{
|
|
267
260
|
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
268
261
|
options: {
|
package/lib/options.js
CHANGED
|
@@ -10,11 +10,11 @@ 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,
|
|
17
|
-
truncateMarker: /<!--\s*truncate\s
|
|
17
|
+
truncateMarker: /<!--\s*truncate\s*-->|\{\/\*\s*truncate\s*\*\/\}/,
|
|
18
18
|
rehypePlugins: [],
|
|
19
19
|
remarkPlugins: [],
|
|
20
20
|
showReadingTime: true,
|
|
@@ -44,10 +44,7 @@ const PluginOptionSchema = utils_validation_1.Joi.object({
|
|
|
44
44
|
archiveBasePath: utils_validation_1.Joi.string()
|
|
45
45
|
.default(exports.DEFAULT_OPTIONS.archiveBasePath)
|
|
46
46
|
.allow(null),
|
|
47
|
-
routeBasePath: utils_validation_1.
|
|
48
|
-
// '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
|
|
49
|
-
// .allow('')
|
|
50
|
-
.default(exports.DEFAULT_OPTIONS.routeBasePath),
|
|
47
|
+
routeBasePath: utils_validation_1.RouteBasePathSchema.default(exports.DEFAULT_OPTIONS.routeBasePath),
|
|
51
48
|
tagsBasePath: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.tagsBasePath),
|
|
52
49
|
include: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()).default(exports.DEFAULT_OPTIONS.include),
|
|
53
50
|
exclude: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()).default(exports.DEFAULT_OPTIONS.exclude),
|
|
@@ -95,6 +92,9 @@ const PluginOptionSchema = utils_validation_1.Joi.object({
|
|
|
95
92
|
}),
|
|
96
93
|
language: utils_validation_1.Joi.string(),
|
|
97
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),
|
|
98
98
|
}).default(exports.DEFAULT_OPTIONS.feedOptions),
|
|
99
99
|
authorsMapPath: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.authorsMapPath),
|
|
100
100
|
readingTime: utils_validation_1.Joi.function().default(() => exports.DEFAULT_OPTIONS.readingTime),
|
package/lib/props.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { TagsListItem, TagModule } from '@docusaurus/utils';
|
|
8
|
+
import type { BlogTag, BlogTags } from '@docusaurus/plugin-content-blog';
|
|
9
|
+
export declare function toTagsProp({ blogTags }: {
|
|
10
|
+
blogTags: BlogTags;
|
|
11
|
+
}): TagsListItem[];
|
|
12
|
+
export declare function toTagProp({ blogTagsListPath, tag, }: {
|
|
13
|
+
blogTagsListPath: string;
|
|
14
|
+
tag: BlogTag;
|
|
15
|
+
}): TagModule;
|
package/lib/props.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toTagProp = exports.toTagsProp = void 0;
|
|
4
|
+
function toTagsProp({ blogTags }) {
|
|
5
|
+
return Object.values(blogTags)
|
|
6
|
+
.filter((tag) => !tag.unlisted)
|
|
7
|
+
.map((tag) => ({
|
|
8
|
+
label: tag.label,
|
|
9
|
+
permalink: tag.permalink,
|
|
10
|
+
count: tag.items.length,
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
exports.toTagsProp = toTagsProp;
|
|
14
|
+
function toTagProp({ blogTagsListPath, tag, }) {
|
|
15
|
+
return {
|
|
16
|
+
label: tag.label,
|
|
17
|
+
permalink: tag.permalink,
|
|
18
|
+
allTagsPath: blogTagsListPath,
|
|
19
|
+
count: tag.items.length,
|
|
20
|
+
unlisted: tag.unlisted,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.toTagProp = toTagProp;
|
package/lib/types.d.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { BrokenMarkdownLink, ContentPaths } from '@docusaurus/utils';
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
8
|
+
export type BlogContentPaths = ContentPaths;
|
|
9
|
+
export type BlogBrokenMarkdownLink = BrokenMarkdownLink<BlogContentPaths>;
|
|
10
|
+
export type BlogMarkdownLoaderOptions = {
|
|
11
11
|
siteDir: string;
|
|
12
12
|
contentPaths: BlogContentPaths;
|
|
13
13
|
truncateMarker: RegExp;
|