@docusaurus/plugin-content-blog 2.0.0-beta.1 → 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/lib/.tsbuildinfo +1 -1
- package/lib/authors.d.ts +23 -0
- package/lib/authors.js +147 -0
- package/lib/blogFrontMatter.d.ts +19 -6
- package/lib/blogFrontMatter.js +35 -23
- package/lib/blogUtils.d.ts +10 -4
- package/lib/blogUtils.js +141 -136
- package/lib/feed.d.ts +20 -0
- package/lib/feed.js +90 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +109 -112
- package/lib/markdownLoader.d.ts +3 -6
- package/lib/markdownLoader.js +5 -5
- package/lib/pluginOptionSchema.d.ts +3 -26
- package/lib/pluginOptionSchema.js +28 -7
- package/lib/translations.d.ts +10 -0
- package/lib/translations.js +53 -0
- package/lib/types.d.ts +54 -14
- package/package.json +19 -13
- package/src/__tests__/__fixtures__/authorsMapFiles/authors.json +29 -0
- package/src/__tests__/__fixtures__/authorsMapFiles/authors.yml +27 -0
- package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad1.json +5 -0
- package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad1.yml +3 -0
- package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad2.json +3 -0
- package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad2.yml +2 -0
- package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad3.json +8 -0
- package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad3.yml +3 -0
- package/src/__tests__/__fixtures__/component/Typography.tsx +6 -0
- package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathEmpty/empty +0 -0
- package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathJson1/authors.json +0 -0
- package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathJson2/authors.json +0 -0
- package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathNestedYml/sub/folder/authors.yml +0 -0
- package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathYml1/authors.yml +0 -0
- package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathYml2/authors.yml +0 -0
- package/src/__tests__/__fixtures__/website/blog/2018-12-14-Happy-First-Birthday-Slash.md +3 -0
- package/src/__tests__/__fixtures__/website/blog/_partials/somePartial.md +3 -0
- package/src/__tests__/__fixtures__/website/blog/_partials/subfolder/somePartial.md +3 -0
- package/src/__tests__/__fixtures__/website/blog/_somePartial.md +3 -0
- package/src/__tests__/__fixtures__/website/blog/authors.yml +4 -0
- package/src/__tests__/__fixtures__/website/blog/mdx-blog-post.mdx +36 -0
- package/src/__tests__/__fixtures__/website/blog/mdx-require-blog-post.mdx +14 -0
- package/src/__tests__/__fixtures__/website/blog/simple-slug.md +4 -0
- package/src/__tests__/__fixtures__/website/i18n/en/docusaurus-plugin-content-blog/2018-12-14-Happy-First-Birthday-Slash.md +3 -0
- package/src/__tests__/__fixtures__/website/i18n/en/docusaurus-plugin-content-blog/authors.yml +5 -0
- package/src/__tests__/__fixtures__/website/static/img/docusaurus.png +0 -0
- package/src/__tests__/__snapshots__/feed.test.ts.snap +164 -0
- package/src/__tests__/__snapshots__/translations.test.ts.snap +64 -0
- package/src/__tests__/authors.test.ts +608 -0
- package/src/__tests__/blogFrontMatter.test.ts +165 -36
- package/src/__tests__/blogUtils.test.ts +94 -0
- package/src/__tests__/{generateBlogFeed.test.ts → feed.test.ts} +35 -9
- package/src/__tests__/index.test.ts +84 -12
- package/src/__tests__/pluginOptionSchema.test.ts +3 -3
- package/src/__tests__/translations.test.ts +92 -0
- package/src/authors.ts +198 -0
- package/src/blogFrontMatter.ts +76 -37
- package/src/blogUtils.ts +202 -179
- package/{types.d.ts → src/deps.d.ts} +0 -0
- package/src/feed.ts +129 -0
- package/src/index.ts +131 -112
- package/src/markdownLoader.ts +8 -12
- package/{index.d.ts → src/plugin-content-blog.d.ts} +35 -31
- package/src/pluginOptionSchema.ts +31 -9
- package/src/translations.ts +63 -0
- package/src/types.ts +69 -16
- package/src/__tests__/__snapshots__/generateBlogFeed.test.ts.snap +0 -76
|
@@ -9,7 +9,10 @@ import {
|
|
|
9
9
|
BlogPostFrontMatter,
|
|
10
10
|
validateBlogPostFrontMatter,
|
|
11
11
|
} from '../blogFrontMatter';
|
|
12
|
+
import escapeStringRegexp from 'escape-string-regexp';
|
|
12
13
|
|
|
14
|
+
// TODO this abstraction reduce verbosity but it makes it harder to debug
|
|
15
|
+
// It would be preferable to just expose helper methods
|
|
13
16
|
function testField(params: {
|
|
14
17
|
fieldName: keyof BlogPostFrontMatter;
|
|
15
18
|
validFrontMatters: BlogPostFrontMatter[];
|
|
@@ -41,7 +44,20 @@ function testField(params: {
|
|
|
41
44
|
|
|
42
45
|
test('throw error for values', () => {
|
|
43
46
|
params.invalidFrontMatters?.forEach(([frontMatter, message]) => {
|
|
44
|
-
|
|
47
|
+
try {
|
|
48
|
+
validateBlogPostFrontMatter(frontMatter);
|
|
49
|
+
fail(
|
|
50
|
+
new Error(
|
|
51
|
+
`Blog frontmatter is expected to be rejected, but was accepted successfully:\n ${JSON.stringify(
|
|
52
|
+
frontMatter,
|
|
53
|
+
null,
|
|
54
|
+
2,
|
|
55
|
+
)}`,
|
|
56
|
+
),
|
|
57
|
+
);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
expect(e.message).toMatch(new RegExp(escapeStringRegexp(message)));
|
|
60
|
+
}
|
|
45
61
|
});
|
|
46
62
|
});
|
|
47
63
|
});
|
|
@@ -57,7 +73,9 @@ describe('validateBlogPostFrontMatter', () => {
|
|
|
57
73
|
const frontMatter = {abc: '1'};
|
|
58
74
|
expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
|
|
59
75
|
});
|
|
76
|
+
});
|
|
60
77
|
|
|
78
|
+
describe('validateBlogPostFrontMatter description', () => {
|
|
61
79
|
testField({
|
|
62
80
|
fieldName: 'description',
|
|
63
81
|
validFrontMatters: [
|
|
@@ -66,7 +84,9 @@ describe('validateBlogPostFrontMatter', () => {
|
|
|
66
84
|
{description: 'description'},
|
|
67
85
|
],
|
|
68
86
|
});
|
|
87
|
+
});
|
|
69
88
|
|
|
89
|
+
describe('validateBlogPostFrontMatter title', () => {
|
|
70
90
|
testField({
|
|
71
91
|
fieldName: 'title',
|
|
72
92
|
validFrontMatters: [
|
|
@@ -75,48 +95,110 @@ describe('validateBlogPostFrontMatter', () => {
|
|
|
75
95
|
{title: 'title'},
|
|
76
96
|
],
|
|
77
97
|
});
|
|
98
|
+
});
|
|
78
99
|
|
|
100
|
+
describe('validateBlogPostFrontMatter id', () => {
|
|
79
101
|
testField({
|
|
80
102
|
fieldName: 'id',
|
|
81
103
|
validFrontMatters: [{id: '123'}, {id: 'id'}],
|
|
82
|
-
invalidFrontMatters: [[{id: ''}, '
|
|
104
|
+
invalidFrontMatters: [[{id: ''}, 'not allowed to be empty']],
|
|
83
105
|
});
|
|
106
|
+
});
|
|
84
107
|
|
|
108
|
+
describe('validateBlogPostFrontMatter handles legacy/new author frontmatter', () => {
|
|
109
|
+
test('allow legacy author frontmatter', () => {
|
|
110
|
+
const frontMatter: BlogPostFrontMatter = {
|
|
111
|
+
author: 'Sebastien',
|
|
112
|
+
author_url: 'https://sebastienlorber.com',
|
|
113
|
+
author_title: 'maintainer',
|
|
114
|
+
author_image_url: 'https://github.com/slorber.png',
|
|
115
|
+
};
|
|
116
|
+
expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('allow new authors frontmatter', () => {
|
|
120
|
+
const frontMatter: BlogPostFrontMatter = {
|
|
121
|
+
authors: [
|
|
122
|
+
'slorber',
|
|
123
|
+
{name: 'Yangshun'},
|
|
124
|
+
{key: 'JMarcey', title: 'creator', random: '42'},
|
|
125
|
+
],
|
|
126
|
+
};
|
|
127
|
+
expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('validateBlogPostFrontMatter author', () => {
|
|
85
132
|
testField({
|
|
86
133
|
fieldName: 'author',
|
|
87
134
|
validFrontMatters: [{author: '123'}, {author: 'author'}],
|
|
88
|
-
invalidFrontMatters: [[{author: ''}, '
|
|
135
|
+
invalidFrontMatters: [[{author: ''}, 'not allowed to be empty']],
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe('validateBlogPostFrontMatter author_title', () => {
|
|
140
|
+
testField({
|
|
141
|
+
fieldName: 'author_title',
|
|
142
|
+
validFrontMatters: [
|
|
143
|
+
{author: '123', author_title: '123'},
|
|
144
|
+
{author: '123', author_title: 'author_title'},
|
|
145
|
+
],
|
|
146
|
+
invalidFrontMatters: [[{author_title: ''}, 'not allowed to be empty']],
|
|
89
147
|
});
|
|
90
148
|
|
|
91
149
|
testField({
|
|
92
150
|
fieldName: 'authorTitle',
|
|
93
151
|
validFrontMatters: [{authorTitle: '123'}, {authorTitle: 'authorTitle'}],
|
|
94
|
-
invalidFrontMatters: [[{authorTitle: ''}, '
|
|
152
|
+
invalidFrontMatters: [[{authorTitle: ''}, 'not allowed to be empty']],
|
|
95
153
|
});
|
|
154
|
+
});
|
|
96
155
|
|
|
156
|
+
describe('validateBlogPostFrontMatter author_url', () => {
|
|
97
157
|
testField({
|
|
98
|
-
fieldName: '
|
|
99
|
-
validFrontMatters: [
|
|
100
|
-
|
|
158
|
+
fieldName: 'author_url',
|
|
159
|
+
validFrontMatters: [
|
|
160
|
+
{author_url: 'https://docusaurus.io'},
|
|
161
|
+
{author_url: '../../relative'},
|
|
162
|
+
{author_url: '/absolute'},
|
|
163
|
+
],
|
|
164
|
+
invalidFrontMatters: [
|
|
165
|
+
[
|
|
166
|
+
{author_url: ''},
|
|
167
|
+
'"author_url" does not look like a valid url (value=\'\')',
|
|
168
|
+
],
|
|
169
|
+
],
|
|
101
170
|
});
|
|
102
171
|
|
|
103
172
|
testField({
|
|
104
173
|
fieldName: 'authorURL',
|
|
105
|
-
validFrontMatters: [
|
|
174
|
+
validFrontMatters: [
|
|
175
|
+
{authorURL: 'https://docusaurus.io'},
|
|
176
|
+
{authorURL: '../../relative'},
|
|
177
|
+
{authorURL: '/absolute'},
|
|
178
|
+
],
|
|
179
|
+
|
|
106
180
|
invalidFrontMatters: [
|
|
107
|
-
[
|
|
108
|
-
|
|
109
|
-
|
|
181
|
+
[
|
|
182
|
+
{authorURL: ''},
|
|
183
|
+
'"authorURL" does not look like a valid url (value=\'\')',
|
|
184
|
+
],
|
|
110
185
|
],
|
|
111
186
|
});
|
|
187
|
+
});
|
|
112
188
|
|
|
189
|
+
describe('validateBlogPostFrontMatter author_image_url', () => {
|
|
113
190
|
testField({
|
|
114
|
-
fieldName: '
|
|
115
|
-
validFrontMatters: [
|
|
191
|
+
fieldName: 'author_image_url',
|
|
192
|
+
validFrontMatters: [
|
|
193
|
+
{author_image_url: 'https://docusaurus.io/asset/image.png'},
|
|
194
|
+
{author_image_url: '../../relative'},
|
|
195
|
+
{author_image_url: '/absolute'},
|
|
196
|
+
],
|
|
116
197
|
invalidFrontMatters: [
|
|
117
|
-
[
|
|
118
|
-
|
|
119
|
-
|
|
198
|
+
[
|
|
199
|
+
{author_image_url: ''},
|
|
200
|
+
'"author_image_url" does not look like a valid url (value=\'\')',
|
|
201
|
+
],
|
|
120
202
|
],
|
|
121
203
|
});
|
|
122
204
|
|
|
@@ -124,26 +206,67 @@ describe('validateBlogPostFrontMatter', () => {
|
|
|
124
206
|
fieldName: 'authorImageURL',
|
|
125
207
|
validFrontMatters: [
|
|
126
208
|
{authorImageURL: 'https://docusaurus.io/asset/image.png'},
|
|
209
|
+
{authorImageURL: '../../relative'},
|
|
210
|
+
{authorImageURL: '/absolute'},
|
|
127
211
|
],
|
|
128
212
|
invalidFrontMatters: [
|
|
129
|
-
[
|
|
130
|
-
|
|
131
|
-
|
|
213
|
+
[
|
|
214
|
+
{authorImageURL: ''},
|
|
215
|
+
'"authorImageURL" does not look like a valid url (value=\'\')',
|
|
216
|
+
],
|
|
132
217
|
],
|
|
133
218
|
});
|
|
219
|
+
});
|
|
134
220
|
|
|
221
|
+
describe('validateBlogPostFrontMatter authors', () => {
|
|
135
222
|
testField({
|
|
136
|
-
fieldName: '
|
|
223
|
+
fieldName: 'author',
|
|
137
224
|
validFrontMatters: [
|
|
138
|
-
{
|
|
225
|
+
{authors: []},
|
|
226
|
+
{authors: 'authorKey'},
|
|
227
|
+
{authors: ['authorKey1', 'authorKey2']},
|
|
228
|
+
{
|
|
229
|
+
authors: {
|
|
230
|
+
name: 'Author Name',
|
|
231
|
+
imageURL: '/absolute',
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
authors: {
|
|
236
|
+
key: 'authorKey',
|
|
237
|
+
title: 'Author title',
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
authors: [
|
|
242
|
+
'authorKey1',
|
|
243
|
+
{key: 'authorKey3'},
|
|
244
|
+
'authorKey3',
|
|
245
|
+
{name: 'Author Name 4'},
|
|
246
|
+
{key: 'authorKey5'},
|
|
247
|
+
],
|
|
248
|
+
},
|
|
139
249
|
],
|
|
250
|
+
|
|
140
251
|
invalidFrontMatters: [
|
|
141
|
-
[{
|
|
142
|
-
[
|
|
143
|
-
|
|
252
|
+
[{authors: ''}, '"authors" is not allowed to be empty'],
|
|
253
|
+
[
|
|
254
|
+
{authors: [undefined]},
|
|
255
|
+
'"authors[0]" does not look like a valid blog post author. Please use an author key or an author object (with a key and/or name).',
|
|
256
|
+
],
|
|
257
|
+
[
|
|
258
|
+
{authors: [null]},
|
|
259
|
+
'"authors[0]" does not look like a valid blog post author. Please use an author key or an author object (with a key and/or name).',
|
|
260
|
+
],
|
|
261
|
+
[
|
|
262
|
+
{authors: [{}]},
|
|
263
|
+
'"authors[0]" does not look like a valid blog post author. Please use an author key or an author object (with a key and/or name).',
|
|
264
|
+
],
|
|
144
265
|
],
|
|
145
266
|
});
|
|
267
|
+
});
|
|
146
268
|
|
|
269
|
+
describe('validateBlogPostFrontMatter slug', () => {
|
|
147
270
|
testField({
|
|
148
271
|
fieldName: 'slug',
|
|
149
272
|
validFrontMatters: [
|
|
@@ -156,12 +279,15 @@ describe('validateBlogPostFrontMatter', () => {
|
|
|
156
279
|
{slug: '/api/plugins/@docusaurus/plugin-debug'},
|
|
157
280
|
{slug: '@site/api/asset/image.png'},
|
|
158
281
|
],
|
|
159
|
-
invalidFrontMatters: [[{slug: ''}, '
|
|
282
|
+
invalidFrontMatters: [[{slug: ''}, 'not allowed to be empty']],
|
|
160
283
|
});
|
|
284
|
+
});
|
|
161
285
|
|
|
286
|
+
describe('validateBlogPostFrontMatter image', () => {
|
|
162
287
|
testField({
|
|
163
288
|
fieldName: 'image',
|
|
164
289
|
validFrontMatters: [
|
|
290
|
+
{image: 'https://docusaurus.io/image.png'},
|
|
165
291
|
{image: 'blog/'},
|
|
166
292
|
{image: '/blog'},
|
|
167
293
|
{image: '/blog/'},
|
|
@@ -172,15 +298,12 @@ describe('validateBlogPostFrontMatter', () => {
|
|
|
172
298
|
{image: '@site/api/asset/image.png'},
|
|
173
299
|
],
|
|
174
300
|
invalidFrontMatters: [
|
|
175
|
-
[{image: ''}, '
|
|
176
|
-
[{image: 'https://docusaurus.io'}, 'must be a valid relative uri'],
|
|
177
|
-
[
|
|
178
|
-
{image: 'https://docusaurus.io/blog/image.png'},
|
|
179
|
-
'must be a valid relative uri',
|
|
180
|
-
],
|
|
301
|
+
[{image: ''}, '"image" does not look like a valid url (value=\'\')'],
|
|
181
302
|
],
|
|
182
303
|
});
|
|
304
|
+
});
|
|
183
305
|
|
|
306
|
+
describe('validateBlogPostFrontMatter tags', () => {
|
|
184
307
|
testField({
|
|
185
308
|
fieldName: 'tags',
|
|
186
309
|
validFrontMatters: [
|
|
@@ -191,8 +314,8 @@ describe('validateBlogPostFrontMatter', () => {
|
|
|
191
314
|
{tags: ['hello', {label: 'tagLabel', permalink: '/tagPermalink'}]},
|
|
192
315
|
],
|
|
193
316
|
invalidFrontMatters: [
|
|
194
|
-
[{tags: ''}, '
|
|
195
|
-
[{tags: ['']}, '
|
|
317
|
+
[{tags: ''}, '"tags" does not look like a valid FrontMatter Yaml array.'],
|
|
318
|
+
[{tags: ['']}, 'not allowed to be empty'],
|
|
196
319
|
],
|
|
197
320
|
// See https://github.com/facebook/docusaurus/issues/4642
|
|
198
321
|
convertibleFrontMatter: [
|
|
@@ -203,7 +326,9 @@ describe('validateBlogPostFrontMatter', () => {
|
|
|
203
326
|
],
|
|
204
327
|
],
|
|
205
328
|
});
|
|
329
|
+
});
|
|
206
330
|
|
|
331
|
+
describe('validateBlogPostFrontMatter keywords', () => {
|
|
207
332
|
testField({
|
|
208
333
|
fieldName: 'keywords',
|
|
209
334
|
validFrontMatters: [
|
|
@@ -214,11 +339,13 @@ describe('validateBlogPostFrontMatter', () => {
|
|
|
214
339
|
],
|
|
215
340
|
invalidFrontMatters: [
|
|
216
341
|
[{keywords: ''}, 'must be an array'],
|
|
217
|
-
[{keywords: ['']}, '
|
|
342
|
+
[{keywords: ['']}, 'not allowed to be empty'],
|
|
218
343
|
[{keywords: []}, 'does not contain 1 required value(s)'],
|
|
219
344
|
],
|
|
220
345
|
});
|
|
346
|
+
});
|
|
221
347
|
|
|
348
|
+
describe('validateBlogPostFrontMatter draft', () => {
|
|
222
349
|
testField({
|
|
223
350
|
fieldName: 'draft',
|
|
224
351
|
validFrontMatters: [{draft: true}, {draft: false}],
|
|
@@ -231,7 +358,9 @@ describe('validateBlogPostFrontMatter', () => {
|
|
|
231
358
|
[{draft: 'no'}, 'must be a boolean'],
|
|
232
359
|
],
|
|
233
360
|
});
|
|
361
|
+
});
|
|
234
362
|
|
|
363
|
+
describe('validateBlogPostFrontMatter hide_table_of_contents', () => {
|
|
235
364
|
testField({
|
|
236
365
|
fieldName: 'hide_table_of_contents',
|
|
237
366
|
validFrontMatters: [
|
|
@@ -247,14 +376,14 @@ describe('validateBlogPostFrontMatter', () => {
|
|
|
247
376
|
[{hide_table_of_contents: 'no'}, 'must be a boolean'],
|
|
248
377
|
],
|
|
249
378
|
});
|
|
379
|
+
});
|
|
250
380
|
|
|
381
|
+
describe('validateBlogPostFrontMatter date', () => {
|
|
251
382
|
testField({
|
|
252
383
|
fieldName: 'date',
|
|
253
384
|
validFrontMatters: [
|
|
254
385
|
{date: new Date('2020-01-01')},
|
|
255
|
-
// @ts-expect-error: string for test
|
|
256
386
|
{date: '2020-01-01'},
|
|
257
|
-
// @ts-expect-error: string for test
|
|
258
387
|
{date: '2020'},
|
|
259
388
|
],
|
|
260
389
|
invalidFrontMatters: [
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
|
|
8
|
+
import {parseBlogFileName} from '../blogUtils';
|
|
9
|
+
|
|
10
|
+
describe('parseBlogFileName', () => {
|
|
11
|
+
test('parse file', () => {
|
|
12
|
+
expect(parseBlogFileName('some-post.md')).toEqual({
|
|
13
|
+
date: undefined,
|
|
14
|
+
text: 'some-post',
|
|
15
|
+
slug: '/some-post',
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('parse folder', () => {
|
|
20
|
+
expect(parseBlogFileName('some-post/index.md')).toEqual({
|
|
21
|
+
date: undefined,
|
|
22
|
+
text: 'some-post',
|
|
23
|
+
slug: '/some-post',
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('parse nested file', () => {
|
|
28
|
+
expect(parseBlogFileName('some-post/some-file.md')).toEqual({
|
|
29
|
+
date: undefined,
|
|
30
|
+
text: 'some-post/some-file',
|
|
31
|
+
slug: '/some-post/some-file',
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('parse nested folder', () => {
|
|
36
|
+
expect(parseBlogFileName('some-post/some-subfolder/index.md')).toEqual({
|
|
37
|
+
date: undefined,
|
|
38
|
+
text: 'some-post/some-subfolder',
|
|
39
|
+
slug: '/some-post/some-subfolder',
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('parse file respecting date convention', () => {
|
|
44
|
+
expect(
|
|
45
|
+
parseBlogFileName('2021-05-12-announcing-docusaurus-two-beta.md'),
|
|
46
|
+
).toEqual({
|
|
47
|
+
date: new Date('2021-05-12Z'),
|
|
48
|
+
text: 'announcing-docusaurus-two-beta',
|
|
49
|
+
slug: '/2021/05/12/announcing-docusaurus-two-beta',
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('parse folder name respecting date convention', () => {
|
|
54
|
+
expect(
|
|
55
|
+
parseBlogFileName('2021-05-12-announcing-docusaurus-two-beta/index.md'),
|
|
56
|
+
).toEqual({
|
|
57
|
+
date: new Date('2021-05-12Z'),
|
|
58
|
+
text: 'announcing-docusaurus-two-beta',
|
|
59
|
+
slug: '/2021/05/12/announcing-docusaurus-two-beta',
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('parse folder tree respecting date convention', () => {
|
|
64
|
+
expect(
|
|
65
|
+
parseBlogFileName('2021/05/12/announcing-docusaurus-two-beta/index.md'),
|
|
66
|
+
).toEqual({
|
|
67
|
+
date: new Date('2021-05-12Z'),
|
|
68
|
+
text: 'announcing-docusaurus-two-beta',
|
|
69
|
+
slug: '/2021/05/12/announcing-docusaurus-two-beta',
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('parse folder name/tree (mixed) respecting date convention', () => {
|
|
74
|
+
expect(
|
|
75
|
+
parseBlogFileName('2021/05-12-announcing-docusaurus-two-beta/index.md'),
|
|
76
|
+
).toEqual({
|
|
77
|
+
date: new Date('2021-05-12Z'),
|
|
78
|
+
text: 'announcing-docusaurus-two-beta',
|
|
79
|
+
slug: '/2021/05/12/announcing-docusaurus-two-beta',
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('parse nested folder tree respecting date convention', () => {
|
|
84
|
+
expect(
|
|
85
|
+
parseBlogFileName(
|
|
86
|
+
'2021/05/12/announcing-docusaurus-two-beta/subfolder/subfile.md',
|
|
87
|
+
),
|
|
88
|
+
).toEqual({
|
|
89
|
+
date: new Date('2021-05-12Z'),
|
|
90
|
+
text: 'announcing-docusaurus-two-beta/subfolder/subfile',
|
|
91
|
+
slug: '/2021/05/12/announcing-docusaurus-two-beta/subfolder/subfile',
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -6,9 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import path from 'path';
|
|
9
|
-
import {generateBlogFeed} from '../
|
|
9
|
+
import {generateBlogFeed} from '../feed';
|
|
10
10
|
import {LoadContext, I18n} from '@docusaurus/types';
|
|
11
11
|
import {PluginOptions, BlogContentPaths} from '../types';
|
|
12
|
+
import {DEFAULT_OPTIONS} from '../pluginOptionSchema';
|
|
13
|
+
import {generateBlogPosts} from '../blogUtils';
|
|
14
|
+
import {Feed} from 'feed';
|
|
12
15
|
|
|
13
16
|
const DefaultI18N: I18n = {
|
|
14
17
|
currentLocale: 'en',
|
|
@@ -29,6 +32,23 @@ function getBlogContentPaths(siteDir: string): BlogContentPaths {
|
|
|
29
32
|
};
|
|
30
33
|
}
|
|
31
34
|
|
|
35
|
+
async function testGenerateFeeds(
|
|
36
|
+
context: LoadContext,
|
|
37
|
+
options: PluginOptions,
|
|
38
|
+
): Promise<Feed | null> {
|
|
39
|
+
const blogPosts = await generateBlogPosts(
|
|
40
|
+
getBlogContentPaths(context.siteDir),
|
|
41
|
+
context,
|
|
42
|
+
options,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return generateBlogFeed({
|
|
46
|
+
blogPosts,
|
|
47
|
+
options,
|
|
48
|
+
siteConfig: context.siteConfig,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
32
52
|
describe('blogFeed', () => {
|
|
33
53
|
(['atom', 'rss'] as const).forEach((feedType) => {
|
|
34
54
|
describe(`${feedType}`, () => {
|
|
@@ -41,8 +61,7 @@ describe('blogFeed', () => {
|
|
|
41
61
|
favicon: 'image/favicon.ico',
|
|
42
62
|
};
|
|
43
63
|
|
|
44
|
-
const feed = await
|
|
45
|
-
getBlogContentPaths(siteDir),
|
|
64
|
+
const feed = await testGenerateFeeds(
|
|
46
65
|
{
|
|
47
66
|
siteDir,
|
|
48
67
|
siteConfig,
|
|
@@ -51,16 +70,19 @@ describe('blogFeed', () => {
|
|
|
51
70
|
{
|
|
52
71
|
path: 'invalid-blog-path',
|
|
53
72
|
routeBasePath: 'blog',
|
|
73
|
+
tagsBasePath: 'tags',
|
|
74
|
+
authorsMapPath: 'authors.yml',
|
|
54
75
|
include: ['*.md', '*.mdx'],
|
|
55
76
|
feedOptions: {
|
|
56
77
|
type: [feedType],
|
|
57
78
|
copyright: 'Copyright',
|
|
58
79
|
},
|
|
80
|
+
readingTime: ({content, defaultReadingTime}) =>
|
|
81
|
+
defaultReadingTime({content}),
|
|
59
82
|
} as PluginOptions,
|
|
60
83
|
);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
expect(feedContent).toMatchSnapshot();
|
|
84
|
+
|
|
85
|
+
expect(feed).toEqual(null);
|
|
64
86
|
});
|
|
65
87
|
|
|
66
88
|
test('shows feed item for each post', async () => {
|
|
@@ -73,8 +95,7 @@ describe('blogFeed', () => {
|
|
|
73
95
|
favicon: 'image/favicon.ico',
|
|
74
96
|
};
|
|
75
97
|
|
|
76
|
-
const feed = await
|
|
77
|
-
getBlogContentPaths(siteDir),
|
|
98
|
+
const feed = await testGenerateFeeds(
|
|
78
99
|
{
|
|
79
100
|
siteDir,
|
|
80
101
|
siteConfig,
|
|
@@ -84,11 +105,16 @@ describe('blogFeed', () => {
|
|
|
84
105
|
{
|
|
85
106
|
path: 'blog',
|
|
86
107
|
routeBasePath: 'blog',
|
|
87
|
-
|
|
108
|
+
tagsBasePath: 'tags',
|
|
109
|
+
authorsMapPath: 'authors.yml',
|
|
110
|
+
include: DEFAULT_OPTIONS.include,
|
|
111
|
+
exclude: DEFAULT_OPTIONS.exclude,
|
|
88
112
|
feedOptions: {
|
|
89
113
|
type: [feedType],
|
|
90
114
|
copyright: 'Copyright',
|
|
91
115
|
},
|
|
116
|
+
readingTime: ({content, defaultReadingTime}) =>
|
|
117
|
+
defaultReadingTime({content}),
|
|
92
118
|
} as PluginOptions,
|
|
93
119
|
);
|
|
94
120
|
const feedContent =
|