@docusaurus/plugin-content-blog 2.0.0-beta.13 → 2.0.0-beta.15
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/authors.d.ts +5 -8
- package/lib/authors.js +15 -53
- package/lib/blogFrontMatter.d.ts +1 -34
- package/lib/blogFrontMatter.js +3 -3
- package/lib/blogUtils.d.ts +3 -3
- package/lib/blogUtils.js +28 -22
- package/lib/feed.d.ts +3 -8
- package/lib/feed.js +46 -35
- package/lib/index.d.ts +4 -3
- package/lib/index.js +33 -28
- package/lib/markdownLoader.d.ts +1 -1
- package/lib/markdownLoader.js +1 -2
- package/lib/pluginOptionSchema.d.ts +1 -1
- package/lib/pluginOptionSchema.js +5 -3
- package/lib/translations.d.ts +2 -1
- package/lib/translations.js +3 -3
- package/lib/types.d.ts +2 -79
- package/package.json +11 -12
- package/src/authors.ts +22 -69
- package/src/blogFrontMatter.ts +5 -50
- package/src/blogUtils.ts +38 -34
- package/src/feed.ts +80 -37
- package/src/index.ts +48 -44
- package/src/markdownLoader.ts +2 -3
- package/src/plugin-content-blog.d.ts +147 -4
- package/src/pluginOptionSchema.ts +7 -5
- package/src/translations.ts +5 -4
- package/src/types.ts +5 -97
- package/lib/.tsbuildinfo +0 -1
- package/src/__tests__/__fixtures__/authorsMapFiles/authors.json +0 -29
- package/src/__tests__/__fixtures__/authorsMapFiles/authors.yml +0 -27
- package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad1.json +0 -5
- package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad1.yml +0 -3
- package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad2.json +0 -3
- package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad2.yml +0 -2
- package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad3.json +0 -8
- package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad3.yml +0 -3
- package/src/__tests__/__fixtures__/component/Typography.tsx +0 -6
- 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 +0 -8
- package/src/__tests__/__fixtures__/website/blog/_partials/somePartial.md +0 -3
- package/src/__tests__/__fixtures__/website/blog/_partials/subfolder/somePartial.md +0 -3
- package/src/__tests__/__fixtures__/website/blog/_somePartial.md +0 -3
- package/src/__tests__/__fixtures__/website/blog/authors.yml +0 -4
- package/src/__tests__/__fixtures__/website/blog/complex-slug.md +0 -7
- package/src/__tests__/__fixtures__/website/blog/date-matter.md +0 -5
- package/src/__tests__/__fixtures__/website/blog/draft.md +0 -6
- package/src/__tests__/__fixtures__/website/blog/heading-as-title.md +0 -5
- package/src/__tests__/__fixtures__/website/blog/mdx-blog-post.mdx +0 -36
- package/src/__tests__/__fixtures__/website/blog/mdx-require-blog-post.mdx +0 -14
- package/src/__tests__/__fixtures__/website/blog/simple-slug.md +0 -11
- package/src/__tests__/__fixtures__/website/blog-with-ref/2018-12-14-Happy-First-Birthday-Slash.md +0 -5
- package/src/__tests__/__fixtures__/website/blog-with-ref/post-with-broken-links.md +0 -11
- package/src/__tests__/__fixtures__/website/blog-with-ref/post.md +0 -5
- package/src/__tests__/__fixtures__/website/i18n/en/docusaurus-plugin-content-blog/2018-12-14-Happy-First-Birthday-Slash.md +0 -8
- package/src/__tests__/__fixtures__/website/i18n/en/docusaurus-plugin-content-blog/authors.yml +0 -5
- package/src/__tests__/__fixtures__/website/static/img/docusaurus.png +0 -0
- package/src/__tests__/__fixtures__/website-blog-without-date/blog/no date.md +0 -1
- package/src/__tests__/__snapshots__/feed.test.ts.snap +0 -164
- package/src/__tests__/__snapshots__/linkify.test.ts.snap +0 -24
- package/src/__tests__/__snapshots__/pluginOptionSchema.test.ts.snap +0 -5
- package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -64
- package/src/__tests__/authors.test.ts +0 -608
- package/src/__tests__/blogFrontMatter.test.ts +0 -394
- package/src/__tests__/blogUtils.test.ts +0 -94
- package/src/__tests__/feed.test.ts +0 -126
- package/src/__tests__/index.test.ts +0 -408
- package/src/__tests__/linkify.test.ts +0 -93
- package/src/__tests__/pluginOptionSchema.test.ts +0 -150
- package/src/__tests__/translations.test.ts +0 -92
- package/tsconfig.json +0 -9
|
@@ -1,394 +0,0 @@
|
|
|
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 {
|
|
9
|
-
BlogPostFrontMatter,
|
|
10
|
-
validateBlogPostFrontMatter,
|
|
11
|
-
} from '../blogFrontMatter';
|
|
12
|
-
import escapeStringRegexp from 'escape-string-regexp';
|
|
13
|
-
|
|
14
|
-
// TODO this abstraction reduce verbosity but it makes it harder to debug
|
|
15
|
-
// It would be preferable to just expose helper methods
|
|
16
|
-
function testField(params: {
|
|
17
|
-
fieldName: keyof BlogPostFrontMatter;
|
|
18
|
-
validFrontMatters: BlogPostFrontMatter[];
|
|
19
|
-
convertibleFrontMatter?: [
|
|
20
|
-
ConvertableFrontMatter: Record<string, unknown>,
|
|
21
|
-
ConvertedFrontMatter: BlogPostFrontMatter,
|
|
22
|
-
][];
|
|
23
|
-
invalidFrontMatters?: [
|
|
24
|
-
InvalidFrontMatter: Record<string, unknown>,
|
|
25
|
-
ErrorMessage: string,
|
|
26
|
-
][];
|
|
27
|
-
}) {
|
|
28
|
-
describe(`"${params.fieldName}" field`, () => {
|
|
29
|
-
test('accept valid values', () => {
|
|
30
|
-
params.validFrontMatters.forEach((frontMatter) => {
|
|
31
|
-
expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('convert valid values', () => {
|
|
36
|
-
params.convertibleFrontMatter?.forEach(
|
|
37
|
-
([convertibleFrontMatter, convertedFrontMatter]) => {
|
|
38
|
-
expect(validateBlogPostFrontMatter(convertibleFrontMatter)).toEqual(
|
|
39
|
-
convertedFrontMatter,
|
|
40
|
-
);
|
|
41
|
-
},
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('throw error for values', () => {
|
|
46
|
-
params.invalidFrontMatters?.forEach(([frontMatter, message]) => {
|
|
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
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
describe('validateBlogPostFrontMatter', () => {
|
|
67
|
-
test('accept empty object', () => {
|
|
68
|
-
const frontMatter = {};
|
|
69
|
-
expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('accept unknown field', () => {
|
|
73
|
-
const frontMatter = {abc: '1'};
|
|
74
|
-
expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe('validateBlogPostFrontMatter description', () => {
|
|
79
|
-
testField({
|
|
80
|
-
fieldName: 'description',
|
|
81
|
-
validFrontMatters: [
|
|
82
|
-
// See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
|
|
83
|
-
{description: ''},
|
|
84
|
-
{description: 'description'},
|
|
85
|
-
],
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('validateBlogPostFrontMatter title', () => {
|
|
90
|
-
testField({
|
|
91
|
-
fieldName: 'title',
|
|
92
|
-
validFrontMatters: [
|
|
93
|
-
// See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
|
|
94
|
-
{title: ''},
|
|
95
|
-
{title: 'title'},
|
|
96
|
-
],
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe('validateBlogPostFrontMatter id', () => {
|
|
101
|
-
testField({
|
|
102
|
-
fieldName: 'id',
|
|
103
|
-
validFrontMatters: [{id: '123'}, {id: 'id'}],
|
|
104
|
-
invalidFrontMatters: [[{id: ''}, 'not allowed to be empty']],
|
|
105
|
-
});
|
|
106
|
-
});
|
|
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', () => {
|
|
132
|
-
testField({
|
|
133
|
-
fieldName: 'author',
|
|
134
|
-
validFrontMatters: [{author: '123'}, {author: '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']],
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
testField({
|
|
150
|
-
fieldName: 'authorTitle',
|
|
151
|
-
validFrontMatters: [{authorTitle: '123'}, {authorTitle: 'authorTitle'}],
|
|
152
|
-
invalidFrontMatters: [[{authorTitle: ''}, 'not allowed to be empty']],
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe('validateBlogPostFrontMatter author_url', () => {
|
|
157
|
-
testField({
|
|
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
|
-
],
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
testField({
|
|
173
|
-
fieldName: 'authorURL',
|
|
174
|
-
validFrontMatters: [
|
|
175
|
-
{authorURL: 'https://docusaurus.io'},
|
|
176
|
-
{authorURL: '../../relative'},
|
|
177
|
-
{authorURL: '/absolute'},
|
|
178
|
-
],
|
|
179
|
-
|
|
180
|
-
invalidFrontMatters: [
|
|
181
|
-
[
|
|
182
|
-
{authorURL: ''},
|
|
183
|
-
'"authorURL" does not look like a valid url (value=\'\')',
|
|
184
|
-
],
|
|
185
|
-
],
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
describe('validateBlogPostFrontMatter author_image_url', () => {
|
|
190
|
-
testField({
|
|
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
|
-
],
|
|
197
|
-
invalidFrontMatters: [
|
|
198
|
-
[
|
|
199
|
-
{author_image_url: ''},
|
|
200
|
-
'"author_image_url" does not look like a valid url (value=\'\')',
|
|
201
|
-
],
|
|
202
|
-
],
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
testField({
|
|
206
|
-
fieldName: 'authorImageURL',
|
|
207
|
-
validFrontMatters: [
|
|
208
|
-
{authorImageURL: 'https://docusaurus.io/asset/image.png'},
|
|
209
|
-
{authorImageURL: '../../relative'},
|
|
210
|
-
{authorImageURL: '/absolute'},
|
|
211
|
-
],
|
|
212
|
-
invalidFrontMatters: [
|
|
213
|
-
[
|
|
214
|
-
{authorImageURL: ''},
|
|
215
|
-
'"authorImageURL" does not look like a valid url (value=\'\')',
|
|
216
|
-
],
|
|
217
|
-
],
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
describe('validateBlogPostFrontMatter authors', () => {
|
|
222
|
-
testField({
|
|
223
|
-
fieldName: 'author',
|
|
224
|
-
validFrontMatters: [
|
|
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
|
-
},
|
|
249
|
-
],
|
|
250
|
-
|
|
251
|
-
invalidFrontMatters: [
|
|
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
|
-
],
|
|
265
|
-
],
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
describe('validateBlogPostFrontMatter slug', () => {
|
|
270
|
-
testField({
|
|
271
|
-
fieldName: 'slug',
|
|
272
|
-
validFrontMatters: [
|
|
273
|
-
{slug: 'blog/'},
|
|
274
|
-
{slug: '/blog'},
|
|
275
|
-
{slug: '/blog/'},
|
|
276
|
-
{slug: './blog'},
|
|
277
|
-
{slug: '../blog'},
|
|
278
|
-
{slug: '../../blog'},
|
|
279
|
-
{slug: '/api/plugins/@docusaurus/plugin-debug'},
|
|
280
|
-
{slug: '@site/api/asset/image.png'},
|
|
281
|
-
],
|
|
282
|
-
invalidFrontMatters: [[{slug: ''}, 'not allowed to be empty']],
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
describe('validateBlogPostFrontMatter image', () => {
|
|
287
|
-
testField({
|
|
288
|
-
fieldName: 'image',
|
|
289
|
-
validFrontMatters: [
|
|
290
|
-
{image: 'https://docusaurus.io/image.png'},
|
|
291
|
-
{image: 'blog/'},
|
|
292
|
-
{image: '/blog'},
|
|
293
|
-
{image: '/blog/'},
|
|
294
|
-
{image: './blog'},
|
|
295
|
-
{image: '../blog'},
|
|
296
|
-
{image: '../../blog'},
|
|
297
|
-
{image: '/api/plugins/@docusaurus/plugin-debug'},
|
|
298
|
-
{image: '@site/api/asset/image.png'},
|
|
299
|
-
],
|
|
300
|
-
invalidFrontMatters: [
|
|
301
|
-
[{image: ''}, '"image" does not look like a valid url (value=\'\')'],
|
|
302
|
-
],
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
describe('validateBlogPostFrontMatter tags', () => {
|
|
307
|
-
testField({
|
|
308
|
-
fieldName: 'tags',
|
|
309
|
-
validFrontMatters: [
|
|
310
|
-
{tags: []},
|
|
311
|
-
{tags: ['hello']},
|
|
312
|
-
{tags: ['hello', 'world']},
|
|
313
|
-
{tags: ['hello', 'world']},
|
|
314
|
-
{tags: ['hello', {label: 'tagLabel', permalink: '/tagPermalink'}]},
|
|
315
|
-
],
|
|
316
|
-
invalidFrontMatters: [
|
|
317
|
-
[{tags: ''}, '"tags" does not look like a valid FrontMatter Yaml array.'],
|
|
318
|
-
[{tags: ['']}, 'not allowed to be empty'],
|
|
319
|
-
],
|
|
320
|
-
// See https://github.com/facebook/docusaurus/issues/4642
|
|
321
|
-
convertibleFrontMatter: [
|
|
322
|
-
[{tags: [42]}, {tags: ['42']}],
|
|
323
|
-
[
|
|
324
|
-
{tags: [{label: 84, permalink: '/tagPermalink'}]},
|
|
325
|
-
{tags: [{label: '84', permalink: '/tagPermalink'}]},
|
|
326
|
-
],
|
|
327
|
-
],
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
describe('validateBlogPostFrontMatter keywords', () => {
|
|
332
|
-
testField({
|
|
333
|
-
fieldName: 'keywords',
|
|
334
|
-
validFrontMatters: [
|
|
335
|
-
{keywords: ['hello']},
|
|
336
|
-
{keywords: ['hello', 'world']},
|
|
337
|
-
{keywords: ['hello', 'world']},
|
|
338
|
-
{keywords: ['hello']},
|
|
339
|
-
],
|
|
340
|
-
invalidFrontMatters: [
|
|
341
|
-
[{keywords: ''}, 'must be an array'],
|
|
342
|
-
[{keywords: ['']}, 'not allowed to be empty'],
|
|
343
|
-
[{keywords: []}, 'does not contain 1 required value(s)'],
|
|
344
|
-
],
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
describe('validateBlogPostFrontMatter draft', () => {
|
|
349
|
-
testField({
|
|
350
|
-
fieldName: 'draft',
|
|
351
|
-
validFrontMatters: [{draft: true}, {draft: false}],
|
|
352
|
-
convertibleFrontMatter: [
|
|
353
|
-
[{draft: 'true'}, {draft: true}],
|
|
354
|
-
[{draft: 'false'}, {draft: false}],
|
|
355
|
-
],
|
|
356
|
-
invalidFrontMatters: [
|
|
357
|
-
[{draft: 'yes'}, 'must be a boolean'],
|
|
358
|
-
[{draft: 'no'}, 'must be a boolean'],
|
|
359
|
-
],
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
describe('validateBlogPostFrontMatter hide_table_of_contents', () => {
|
|
364
|
-
testField({
|
|
365
|
-
fieldName: 'hide_table_of_contents',
|
|
366
|
-
validFrontMatters: [
|
|
367
|
-
{hide_table_of_contents: true},
|
|
368
|
-
{hide_table_of_contents: false},
|
|
369
|
-
],
|
|
370
|
-
convertibleFrontMatter: [
|
|
371
|
-
[{hide_table_of_contents: 'true'}, {hide_table_of_contents: true}],
|
|
372
|
-
[{hide_table_of_contents: 'false'}, {hide_table_of_contents: false}],
|
|
373
|
-
],
|
|
374
|
-
invalidFrontMatters: [
|
|
375
|
-
[{hide_table_of_contents: 'yes'}, 'must be a boolean'],
|
|
376
|
-
[{hide_table_of_contents: 'no'}, 'must be a boolean'],
|
|
377
|
-
],
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
describe('validateBlogPostFrontMatter date', () => {
|
|
382
|
-
testField({
|
|
383
|
-
fieldName: 'date',
|
|
384
|
-
validFrontMatters: [
|
|
385
|
-
{date: new Date('2020-01-01')},
|
|
386
|
-
{date: '2020-01-01'},
|
|
387
|
-
{date: '2020'},
|
|
388
|
-
],
|
|
389
|
-
invalidFrontMatters: [
|
|
390
|
-
[{date: 'abc'}, 'must be a valid date'],
|
|
391
|
-
[{date: ''}, 'must be a valid date'],
|
|
392
|
-
],
|
|
393
|
-
});
|
|
394
|
-
});
|
|
@@ -1,94 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,126 +0,0 @@
|
|
|
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 path from 'path';
|
|
9
|
-
import {generateBlogFeed} from '../feed';
|
|
10
|
-
import {LoadContext, I18n} from '@docusaurus/types';
|
|
11
|
-
import {PluginOptions, BlogContentPaths} from '../types';
|
|
12
|
-
import {DEFAULT_OPTIONS} from '../pluginOptionSchema';
|
|
13
|
-
import {generateBlogPosts} from '../blogUtils';
|
|
14
|
-
import {Feed} from 'feed';
|
|
15
|
-
|
|
16
|
-
const DefaultI18N: I18n = {
|
|
17
|
-
currentLocale: 'en',
|
|
18
|
-
locales: ['en'],
|
|
19
|
-
defaultLocale: 'en',
|
|
20
|
-
localeConfigs: {},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
function getBlogContentPaths(siteDir: string): BlogContentPaths {
|
|
24
|
-
return {
|
|
25
|
-
contentPath: path.resolve(siteDir, 'blog'),
|
|
26
|
-
contentPathLocalized: path.resolve(
|
|
27
|
-
siteDir,
|
|
28
|
-
'i18n',
|
|
29
|
-
'en',
|
|
30
|
-
'docusaurus-plugin-content-blog',
|
|
31
|
-
),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
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
|
-
|
|
52
|
-
describe('blogFeed', () => {
|
|
53
|
-
(['atom', 'rss'] as const).forEach((feedType) => {
|
|
54
|
-
describe(`${feedType}`, () => {
|
|
55
|
-
test('should not show feed without posts', async () => {
|
|
56
|
-
const siteDir = __dirname;
|
|
57
|
-
const siteConfig = {
|
|
58
|
-
title: 'Hello',
|
|
59
|
-
baseUrl: '/',
|
|
60
|
-
url: 'https://docusaurus.io',
|
|
61
|
-
favicon: 'image/favicon.ico',
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const feed = await testGenerateFeeds(
|
|
65
|
-
{
|
|
66
|
-
siteDir,
|
|
67
|
-
siteConfig,
|
|
68
|
-
i18n: DefaultI18N,
|
|
69
|
-
} as LoadContext,
|
|
70
|
-
{
|
|
71
|
-
path: 'invalid-blog-path',
|
|
72
|
-
routeBasePath: 'blog',
|
|
73
|
-
tagsBasePath: 'tags',
|
|
74
|
-
authorsMapPath: 'authors.yml',
|
|
75
|
-
include: ['*.md', '*.mdx'],
|
|
76
|
-
feedOptions: {
|
|
77
|
-
type: [feedType],
|
|
78
|
-
copyright: 'Copyright',
|
|
79
|
-
},
|
|
80
|
-
readingTime: ({content, defaultReadingTime}) =>
|
|
81
|
-
defaultReadingTime({content}),
|
|
82
|
-
} as PluginOptions,
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
expect(feed).toEqual(null);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test('shows feed item for each post', async () => {
|
|
89
|
-
const siteDir = path.join(__dirname, '__fixtures__', 'website');
|
|
90
|
-
const generatedFilesDir = path.resolve(siteDir, '.docusaurus');
|
|
91
|
-
const siteConfig = {
|
|
92
|
-
title: 'Hello',
|
|
93
|
-
baseUrl: '/myBaseUrl/',
|
|
94
|
-
url: 'https://docusaurus.io',
|
|
95
|
-
favicon: 'image/favicon.ico',
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const feed = await testGenerateFeeds(
|
|
99
|
-
{
|
|
100
|
-
siteDir,
|
|
101
|
-
siteConfig,
|
|
102
|
-
generatedFilesDir,
|
|
103
|
-
i18n: DefaultI18N,
|
|
104
|
-
} as LoadContext,
|
|
105
|
-
{
|
|
106
|
-
path: 'blog',
|
|
107
|
-
routeBasePath: 'blog',
|
|
108
|
-
tagsBasePath: 'tags',
|
|
109
|
-
authorsMapPath: 'authors.yml',
|
|
110
|
-
include: DEFAULT_OPTIONS.include,
|
|
111
|
-
exclude: DEFAULT_OPTIONS.exclude,
|
|
112
|
-
feedOptions: {
|
|
113
|
-
type: [feedType],
|
|
114
|
-
copyright: 'Copyright',
|
|
115
|
-
},
|
|
116
|
-
readingTime: ({content, defaultReadingTime}) =>
|
|
117
|
-
defaultReadingTime({content}),
|
|
118
|
-
} as PluginOptions,
|
|
119
|
-
);
|
|
120
|
-
const feedContent =
|
|
121
|
-
feed && (feedType === 'rss' ? feed.rss2() : feed.atom1());
|
|
122
|
-
expect(feedContent).toMatchSnapshot();
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
});
|