@docusaurus/plugin-content-blog 2.0.0-beta.ff31de0ff → 2.0.1

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.
Files changed (58) hide show
  1. package/lib/authors.d.ts +22 -0
  2. package/lib/authors.js +122 -0
  3. package/lib/blogUtils.d.ts +27 -7
  4. package/lib/blogUtils.js +214 -141
  5. package/lib/feed.d.ts +15 -0
  6. package/lib/feed.js +102 -0
  7. package/lib/frontMatter.d.ts +10 -0
  8. package/lib/frontMatter.js +62 -0
  9. package/lib/index.d.ts +4 -4
  10. package/lib/index.js +179 -205
  11. package/lib/markdownLoader.d.ts +3 -6
  12. package/lib/markdownLoader.js +6 -7
  13. package/lib/options.d.ts +10 -0
  14. package/lib/{pluginOptionSchema.js → options.js} +44 -14
  15. package/lib/remark/footnoteIDFixer.d.ts +14 -0
  16. package/lib/remark/footnoteIDFixer.js +29 -0
  17. package/lib/translations.d.ts +10 -0
  18. package/lib/translations.js +53 -0
  19. package/lib/types.d.ts +4 -109
  20. package/package.json +23 -18
  21. package/src/authors.ts +168 -0
  22. package/src/blogUtils.ts +316 -196
  23. package/src/feed.ts +171 -0
  24. package/src/frontMatter.ts +81 -0
  25. package/src/index.ts +246 -268
  26. package/src/markdownLoader.ts +11 -16
  27. package/src/{pluginOptionSchema.ts → options.ts} +57 -16
  28. package/src/plugin-content-blog.d.ts +587 -0
  29. package/src/remark/footnoteIDFixer.ts +29 -0
  30. package/src/translations.ts +69 -0
  31. package/src/types.ts +2 -128
  32. package/index.d.ts +0 -138
  33. package/lib/.tsbuildinfo +0 -4415
  34. package/lib/blogFrontMatter.d.ts +0 -28
  35. package/lib/blogFrontMatter.js +0 -50
  36. package/lib/pluginOptionSchema.d.ts +0 -33
  37. package/src/__tests__/__fixtures__/website/blog/2018-12-14-Happy-First-Birthday-Slash.md +0 -5
  38. package/src/__tests__/__fixtures__/website/blog/complex-slug.md +0 -7
  39. package/src/__tests__/__fixtures__/website/blog/date-matter.md +0 -5
  40. package/src/__tests__/__fixtures__/website/blog/draft.md +0 -6
  41. package/src/__tests__/__fixtures__/website/blog/heading-as-title.md +0 -5
  42. package/src/__tests__/__fixtures__/website/blog/simple-slug.md +0 -7
  43. package/src/__tests__/__fixtures__/website/blog-with-ref/2018-12-14-Happy-First-Birthday-Slash.md +0 -5
  44. package/src/__tests__/__fixtures__/website/blog-with-ref/post-with-broken-links.md +0 -11
  45. package/src/__tests__/__fixtures__/website/blog-with-ref/post.md +0 -5
  46. package/src/__tests__/__fixtures__/website/i18n/en/docusaurus-plugin-content-blog/2018-12-14-Happy-First-Birthday-Slash.md +0 -5
  47. package/src/__tests__/__fixtures__/website-blog-without-date/blog/no date.md +0 -1
  48. package/src/__tests__/__snapshots__/generateBlogFeed.test.ts.snap +0 -101
  49. package/src/__tests__/__snapshots__/linkify.test.ts.snap +0 -24
  50. package/src/__tests__/__snapshots__/pluginOptionSchema.test.ts.snap +0 -5
  51. package/src/__tests__/blogFrontMatter.test.ts +0 -265
  52. package/src/__tests__/generateBlogFeed.test.ts +0 -100
  53. package/src/__tests__/index.test.ts +0 -336
  54. package/src/__tests__/linkify.test.ts +0 -93
  55. package/src/__tests__/pluginOptionSchema.test.ts +0 -150
  56. package/src/blogFrontMatter.ts +0 -87
  57. package/tsconfig.json +0 -9
  58. package/types.d.ts +0 -13
@@ -1,28 +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
- import { Tag } from './types';
8
- export declare type BlogPostFrontMatter = {
9
- id?: string;
10
- title?: string;
11
- description?: string;
12
- tags?: (string | Tag)[];
13
- slug?: string;
14
- draft?: boolean;
15
- date?: Date;
16
- author?: string;
17
- author_title?: string;
18
- author_url?: string;
19
- author_image_url?: string;
20
- image?: string;
21
- keywords?: string[];
22
- hide_table_of_contents?: boolean;
23
- /** @deprecated */
24
- authorTitle?: string;
25
- authorURL?: string;
26
- authorImageURL?: string;
27
- };
28
- export declare function validateBlogPostFrontMatter(frontMatter: Record<string, unknown>): BlogPostFrontMatter;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Facebook, Inc. and its affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.validateBlogPostFrontMatter = void 0;
10
- /* eslint-disable camelcase */
11
- const utils_validation_1 = require("@docusaurus/utils-validation");
12
- // NOTE: we don't add any default value on purpose here
13
- // We don't want default values to magically appear in doc metadatas and props
14
- // While the user did not provide those values explicitly
15
- // We use default values in code instead
16
- const BlogTagSchema = utils_validation_1.JoiFrontMatter.alternatives().try(utils_validation_1.JoiFrontMatter.string().required(), utils_validation_1.JoiFrontMatter.object({
17
- label: utils_validation_1.JoiFrontMatter.string().required(),
18
- permalink: utils_validation_1.JoiFrontMatter.string().required(),
19
- }));
20
- const BlogFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
21
- id: utils_validation_1.JoiFrontMatter.string(),
22
- title: utils_validation_1.JoiFrontMatter.string().allow(''),
23
- description: utils_validation_1.JoiFrontMatter.string().allow(''),
24
- tags: utils_validation_1.JoiFrontMatter.array().items(BlogTagSchema),
25
- draft: utils_validation_1.JoiFrontMatter.boolean(),
26
- date: utils_validation_1.JoiFrontMatter.date().raw(),
27
- author: utils_validation_1.JoiFrontMatter.string(),
28
- author_title: utils_validation_1.JoiFrontMatter.string(),
29
- author_url: utils_validation_1.JoiFrontMatter.string().uri(),
30
- author_image_url: utils_validation_1.JoiFrontMatter.string().uri(),
31
- slug: utils_validation_1.JoiFrontMatter.string(),
32
- image: utils_validation_1.JoiFrontMatter.string().uri({ relativeOnly: true }),
33
- keywords: utils_validation_1.JoiFrontMatter.array().items(utils_validation_1.JoiFrontMatter.string().required()),
34
- hide_table_of_contents: utils_validation_1.JoiFrontMatter.boolean(),
35
- // TODO re-enable warnings later, our v1 blog posts use those older frontmatter fields
36
- authorURL: utils_validation_1.JoiFrontMatter.string().uri(),
37
- // .warning('deprecate.error', { alternative: '"author_url"'}),
38
- authorTitle: utils_validation_1.JoiFrontMatter.string(),
39
- // .warning('deprecate.error', { alternative: '"author_title"'}),
40
- authorImageURL: utils_validation_1.JoiFrontMatter.string().uri(),
41
- // .warning('deprecate.error', { alternative: '"author_image_url"'}),
42
- })
43
- .unknown()
44
- .messages({
45
- 'deprecate.error': '{#label} blog frontMatter field is deprecated. Please use {#alternative} instead.',
46
- });
47
- function validateBlogPostFrontMatter(frontMatter) {
48
- return utils_validation_1.validateFrontMatter(frontMatter, BlogFrontMatterSchema);
49
- }
50
- exports.validateBlogPostFrontMatter = validateBlogPostFrontMatter;
@@ -1,33 +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
- import { Joi } from '@docusaurus/utils-validation';
8
- export declare const DEFAULT_OPTIONS: {
9
- feedOptions: {
10
- type: string[];
11
- };
12
- beforeDefaultRehypePlugins: never[];
13
- beforeDefaultRemarkPlugins: never[];
14
- admonitions: {};
15
- truncateMarker: RegExp;
16
- rehypePlugins: never[];
17
- remarkPlugins: never[];
18
- showReadingTime: boolean;
19
- blogTagsPostsComponent: string;
20
- blogTagsListComponent: string;
21
- blogPostComponent: string;
22
- blogListComponent: string;
23
- blogDescription: string;
24
- blogTitle: string;
25
- blogSidebarCount: number;
26
- blogSidebarTitle: string;
27
- postsPerPage: number;
28
- include: string[];
29
- routeBasePath: string;
30
- path: string;
31
- editLocalizedFiles: boolean;
32
- };
33
- export declare const PluginOptionSchema: Joi.ObjectSchema<any>;
@@ -1,5 +0,0 @@
1
- ---
2
- title: Happy 1st Birthday Slash!
3
- ---
4
-
5
- Happy birthday!
@@ -1,7 +0,0 @@
1
- ---
2
- slug: /hey/my super path/héllô
3
- title: Complex Slug
4
- date: 2020-08-16
5
- ---
6
-
7
- complex url slug
@@ -1,5 +0,0 @@
1
- ---
2
- date: 2019-01-01
3
- ---
4
-
5
- date inside front matter
@@ -1,6 +0,0 @@
1
- ---
2
- date: 2020-02-27
3
- draft: true
4
- ---
5
-
6
- this post should not be published yet
@@ -1,5 +0,0 @@
1
- ---
2
- date: 2019-01-02
3
- ---
4
-
5
- # some heading
@@ -1,7 +0,0 @@
1
- ---
2
- slug: /simple/slug
3
- title: Simple Slug
4
- date: 2020-08-15
5
- ---
6
-
7
- simple url slug
@@ -1,5 +0,0 @@
1
- ---
2
- title: Happy 1st Birthday Slash!
3
- ---
4
-
5
- pattern name
@@ -1,11 +0,0 @@
1
- ---
2
- title: This post links to another one!
3
- ---
4
-
5
- [Good link 1](2018-12-14-Happy-First-Birthday-Slash.md)
6
-
7
- [Good link 2](./2018-12-14-Happy-First-Birthday-Slash.md)
8
-
9
- [Bad link 1](postNotExist1.md)
10
-
11
- [Bad link 1](./postNotExist2.mdx)
@@ -1,5 +0,0 @@
1
- ---
2
- title: This post links to another one!
3
- ---
4
-
5
- [Linked post](2018-12-14-Happy-First-Birthday-Slash.md)
@@ -1,5 +0,0 @@
1
- ---
2
- title: Happy 1st Birthday Slash! (translated)
3
- ---
4
-
5
- Happy birthday! (translated)
@@ -1,101 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`blogFeed atom can show feed without posts 1`] = `
4
- "<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
5
- <feed xmlns=\\"http://www.w3.org/2005/Atom\\">
6
- <id>https://docusaurus.io/blog</id>
7
- <title>Hello Blog</title>
8
- <updated>2015-10-25T23:29:00.000Z</updated>
9
- <generator>https://github.com/jpmonette/feed</generator>
10
- <link rel=\\"alternate\\" href=\\"https://docusaurus.io/blog\\"/>
11
- <subtitle>Hello Blog</subtitle>
12
- <icon>https://docusaurus.io/image/favicon.ico</icon>
13
- <rights>Copyright</rights>
14
- </feed>"
15
- `;
16
-
17
- exports[`blogFeed atom shows feed item for each post 1`] = `
18
- "<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
19
- <feed xmlns=\\"http://www.w3.org/2005/Atom\\">
20
- <id>https://docusaurus.io/blog</id>
21
- <title>Hello Blog</title>
22
- <updated>2020-02-27T00:00:00.000Z</updated>
23
- <generator>https://github.com/jpmonette/feed</generator>
24
- <link rel=\\"alternate\\" href=\\"https://docusaurus.io/blog\\"/>
25
- <subtitle>Hello Blog</subtitle>
26
- <icon>https://docusaurus.io/image/favicon.ico</icon>
27
- <rights>Copyright</rights>
28
- <entry>
29
- <title type=\\"html\\"><![CDATA[draft]]></title>
30
- <id>draft</id>
31
- <link href=\\"https://docusaurus.io/blog/draft\\"/>
32
- <updated>2020-02-27T00:00:00.000Z</updated>
33
- <summary type=\\"html\\"><![CDATA[this post should not be published yet]]></summary>
34
- </entry>
35
- <entry>
36
- <title type=\\"html\\"><![CDATA[date-matter]]></title>
37
- <id>date-matter</id>
38
- <link href=\\"https://docusaurus.io/blog/date-matter\\"/>
39
- <updated>2019-01-01T00:00:00.000Z</updated>
40
- <summary type=\\"html\\"><![CDATA[date inside front matter]]></summary>
41
- </entry>
42
- <entry>
43
- <title type=\\"html\\"><![CDATA[Happy 1st Birthday Slash! (translated)]]></title>
44
- <id>Happy 1st Birthday Slash! (translated)</id>
45
- <link href=\\"https://docusaurus.io/blog/2018/12/14/Happy-First-Birthday-Slash\\"/>
46
- <updated>2018-12-14T00:00:00.000Z</updated>
47
- <summary type=\\"html\\"><![CDATA[Happy birthday! (translated)]]></summary>
48
- </entry>
49
- </feed>"
50
- `;
51
-
52
- exports[`blogFeed rss can show feed without posts 1`] = `
53
- "<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
54
- <rss version=\\"2.0\\">
55
- <channel>
56
- <title>Hello Blog</title>
57
- <link>https://docusaurus.io/blog</link>
58
- <description>Hello Blog</description>
59
- <lastBuildDate>Sun, 25 Oct 2015 23:29:00 GMT</lastBuildDate>
60
- <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
61
- <generator>https://github.com/jpmonette/feed</generator>
62
- <copyright>Copyright</copyright>
63
- </channel>
64
- </rss>"
65
- `;
66
-
67
- exports[`blogFeed rss shows feed item for each post 1`] = `
68
- "<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
69
- <rss version=\\"2.0\\">
70
- <channel>
71
- <title>Hello Blog</title>
72
- <link>https://docusaurus.io/blog</link>
73
- <description>Hello Blog</description>
74
- <lastBuildDate>Thu, 27 Feb 2020 00:00:00 GMT</lastBuildDate>
75
- <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
76
- <generator>https://github.com/jpmonette/feed</generator>
77
- <copyright>Copyright</copyright>
78
- <item>
79
- <title><![CDATA[draft]]></title>
80
- <link>https://docusaurus.io/blog/draft</link>
81
- <guid>draft</guid>
82
- <pubDate>Thu, 27 Feb 2020 00:00:00 GMT</pubDate>
83
- <description><![CDATA[this post should not be published yet]]></description>
84
- </item>
85
- <item>
86
- <title><![CDATA[date-matter]]></title>
87
- <link>https://docusaurus.io/blog/date-matter</link>
88
- <guid>date-matter</guid>
89
- <pubDate>Tue, 01 Jan 2019 00:00:00 GMT</pubDate>
90
- <description><![CDATA[date inside front matter]]></description>
91
- </item>
92
- <item>
93
- <title><![CDATA[Happy 1st Birthday Slash! (translated)]]></title>
94
- <link>https://docusaurus.io/blog/2018/12/14/Happy-First-Birthday-Slash</link>
95
- <guid>Happy 1st Birthday Slash! (translated)</guid>
96
- <pubDate>Fri, 14 Dec 2018 00:00:00 GMT</pubDate>
97
- <description><![CDATA[Happy birthday! (translated)]]></description>
98
- </item>
99
- </channel>
100
- </rss>"
101
- `;
@@ -1,24 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`report broken markdown links 1`] = `
4
- "---
5
- title: This post links to another one!
6
- ---
7
-
8
- [Good link 1](/blog/2018/12/14/Happy-First-Birthday-Slash)
9
-
10
- [Good link 2](/blog/2018/12/14/Happy-First-Birthday-Slash)
11
-
12
- [Bad link 1](postNotExist1.md)
13
-
14
- [Bad link 1](./postNotExist2.mdx)
15
- "
16
- `;
17
-
18
- exports[`transform to correct link 1`] = `
19
- "---
20
- title: This post links to another one!
21
- ---
22
-
23
- [Linked post](/blog/2018/12/14/Happy-First-Birthday-Slash)"
24
- `;
@@ -1,5 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`should throw Error in case of invalid feedtype 1`] = `[ValidationError: "feedOptions.type" does not match any of the allowed types]`;
4
-
5
- exports[`should throw Error in case of invalid options 1`] = `[ValidationError: "postsPerPage" must be greater than or equal to 1]`;
@@ -1,265 +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
-
13
- function testField(params: {
14
- fieldName: keyof BlogPostFrontMatter;
15
- validFrontMatters: BlogPostFrontMatter[];
16
- convertibleFrontMatter?: [
17
- ConvertableFrontMatter: Record<string, unknown>,
18
- ConvertedFrontMatter: BlogPostFrontMatter,
19
- ][];
20
- invalidFrontMatters?: [
21
- InvalidFrontMatter: Record<string, unknown>,
22
- ErrorMessage: string,
23
- ][];
24
- }) {
25
- describe(`"${params.fieldName}" field`, () => {
26
- test('accept valid values', () => {
27
- params.validFrontMatters.forEach((frontMatter) => {
28
- expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
29
- });
30
- });
31
-
32
- test('convert valid values', () => {
33
- params.convertibleFrontMatter?.forEach(
34
- ([convertibleFrontMatter, convertedFrontMatter]) => {
35
- expect(validateBlogPostFrontMatter(convertibleFrontMatter)).toEqual(
36
- convertedFrontMatter,
37
- );
38
- },
39
- );
40
- });
41
-
42
- test('throw error for values', () => {
43
- params.invalidFrontMatters?.forEach(([frontMatter, message]) => {
44
- expect(() => validateBlogPostFrontMatter(frontMatter)).toThrow(message);
45
- });
46
- });
47
- });
48
- }
49
-
50
- describe('validateBlogPostFrontMatter', () => {
51
- test('accept empty object', () => {
52
- const frontMatter = {};
53
- expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
54
- });
55
-
56
- test('accept unknown field', () => {
57
- const frontMatter = {abc: '1'};
58
- expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
59
- });
60
-
61
- testField({
62
- fieldName: 'description',
63
- validFrontMatters: [
64
- // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
65
- {description: ''},
66
- {description: 'description'},
67
- ],
68
- });
69
-
70
- testField({
71
- fieldName: 'title',
72
- validFrontMatters: [
73
- // See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
74
- {title: ''},
75
- {title: 'title'},
76
- ],
77
- });
78
-
79
- testField({
80
- fieldName: 'id',
81
- validFrontMatters: [{id: '123'}, {id: 'id'}],
82
- invalidFrontMatters: [[{id: ''}, 'is not allowed to be empty']],
83
- });
84
-
85
- testField({
86
- fieldName: 'author',
87
- validFrontMatters: [{author: '123'}, {author: 'author'}],
88
- invalidFrontMatters: [[{author: ''}, 'is not allowed to be empty']],
89
- });
90
-
91
- testField({
92
- fieldName: 'authorTitle',
93
- validFrontMatters: [{authorTitle: '123'}, {authorTitle: 'authorTitle'}],
94
- invalidFrontMatters: [[{authorTitle: ''}, 'is not allowed to be empty']],
95
- });
96
-
97
- testField({
98
- fieldName: 'author_title',
99
- validFrontMatters: [{author_title: '123'}, {author_title: 'author_title'}],
100
- invalidFrontMatters: [[{author_title: ''}, 'is not allowed to be empty']],
101
- });
102
-
103
- testField({
104
- fieldName: 'authorURL',
105
- validFrontMatters: [{authorURL: 'https://docusaurus.io'}],
106
- invalidFrontMatters: [
107
- [{authorURL: ''}, 'is not allowed to be empty'],
108
- [{authorURL: '@site/api/author'}, 'must be a valid uri'],
109
- [{authorURL: '../../api/author'}, 'must be a valid uri'],
110
- ],
111
- });
112
-
113
- testField({
114
- fieldName: 'author_url',
115
- validFrontMatters: [{author_url: 'https://docusaurus.io'}],
116
- invalidFrontMatters: [
117
- [{author_url: ''}, 'is not allowed to be empty'],
118
- [{author_url: '@site/api/author'}, 'must be a valid uri'],
119
- [{author_url: '../../api/author'}, 'must be a valid uri'],
120
- ],
121
- });
122
-
123
- testField({
124
- fieldName: 'authorImageURL',
125
- validFrontMatters: [
126
- {authorImageURL: 'https://docusaurus.io/asset/image.png'},
127
- ],
128
- invalidFrontMatters: [
129
- [{authorImageURL: ''}, 'is not allowed to be empty'],
130
- [{authorImageURL: '@site/api/asset/image.png'}, 'must be a valid uri'],
131
- [{authorImageURL: '../../api/asset/image.png'}, 'must be a valid uri'],
132
- ],
133
- });
134
-
135
- testField({
136
- fieldName: 'author_image_url',
137
- validFrontMatters: [
138
- {author_image_url: 'https://docusaurus.io/asset/image.png'},
139
- ],
140
- invalidFrontMatters: [
141
- [{author_image_url: ''}, 'is not allowed to be empty'],
142
- [{author_image_url: '@site/api/asset/image.png'}, 'must be a valid uri'],
143
- [{author_image_url: '../../api/asset/image.png'}, 'must be a valid uri'],
144
- ],
145
- });
146
-
147
- testField({
148
- fieldName: 'slug',
149
- validFrontMatters: [
150
- {slug: 'blog/'},
151
- {slug: '/blog'},
152
- {slug: '/blog/'},
153
- {slug: './blog'},
154
- {slug: '../blog'},
155
- {slug: '../../blog'},
156
- {slug: '/api/plugins/@docusaurus/plugin-debug'},
157
- {slug: '@site/api/asset/image.png'},
158
- ],
159
- invalidFrontMatters: [[{slug: ''}, 'is not allowed to be empty']],
160
- });
161
-
162
- testField({
163
- fieldName: 'image',
164
- validFrontMatters: [
165
- {image: 'blog/'},
166
- {image: '/blog'},
167
- {image: '/blog/'},
168
- {image: './blog'},
169
- {image: '../blog'},
170
- {image: '../../blog'},
171
- {image: '/api/plugins/@docusaurus/plugin-debug'},
172
- {image: '@site/api/asset/image.png'},
173
- ],
174
- invalidFrontMatters: [
175
- [{image: ''}, 'is not allowed to be empty'],
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
- ],
181
- ],
182
- });
183
-
184
- testField({
185
- fieldName: 'tags',
186
- validFrontMatters: [
187
- {tags: []},
188
- {tags: ['hello']},
189
- {tags: ['hello', 'world']},
190
- {tags: ['hello', 'world']},
191
- {tags: ['hello', {label: 'tagLabel', permalink: '/tagPermalink'}]},
192
- ],
193
- invalidFrontMatters: [
194
- [{tags: ''}, 'must be an array'],
195
- [{tags: ['']}, 'is not allowed to be empty'],
196
- ],
197
- // See https://github.com/facebook/docusaurus/issues/4642
198
- convertibleFrontMatter: [
199
- [{tags: [42]}, {tags: ['42']}],
200
- [
201
- {tags: [{label: 84, permalink: '/tagPermalink'}]},
202
- {tags: [{label: '84', permalink: '/tagPermalink'}]},
203
- ],
204
- ],
205
- });
206
-
207
- testField({
208
- fieldName: 'keywords',
209
- validFrontMatters: [
210
- {keywords: ['hello']},
211
- {keywords: ['hello', 'world']},
212
- {keywords: ['hello', 'world']},
213
- {keywords: ['hello']},
214
- ],
215
- invalidFrontMatters: [
216
- [{keywords: ''}, 'must be an array'],
217
- [{keywords: ['']}, 'is not allowed to be empty'],
218
- [{keywords: []}, 'does not contain 1 required value(s)'],
219
- ],
220
- });
221
-
222
- testField({
223
- fieldName: 'draft',
224
- validFrontMatters: [{draft: true}, {draft: false}],
225
- convertibleFrontMatter: [
226
- [{draft: 'true'}, {draft: true}],
227
- [{draft: 'false'}, {draft: false}],
228
- ],
229
- invalidFrontMatters: [
230
- [{draft: 'yes'}, 'must be a boolean'],
231
- [{draft: 'no'}, 'must be a boolean'],
232
- ],
233
- });
234
-
235
- testField({
236
- fieldName: 'hide_table_of_contents',
237
- validFrontMatters: [
238
- {hide_table_of_contents: true},
239
- {hide_table_of_contents: false},
240
- ],
241
- convertibleFrontMatter: [
242
- [{hide_table_of_contents: 'true'}, {hide_table_of_contents: true}],
243
- [{hide_table_of_contents: 'false'}, {hide_table_of_contents: false}],
244
- ],
245
- invalidFrontMatters: [
246
- [{hide_table_of_contents: 'yes'}, 'must be a boolean'],
247
- [{hide_table_of_contents: 'no'}, 'must be a boolean'],
248
- ],
249
- });
250
-
251
- testField({
252
- fieldName: 'date',
253
- validFrontMatters: [
254
- {date: new Date('2020-01-01')},
255
- // @ts-expect-error: string for test
256
- {date: '2020-01-01'},
257
- // @ts-expect-error: string for test
258
- {date: '2020'},
259
- ],
260
- invalidFrontMatters: [
261
- [{date: 'abc'}, 'must be a valid date'],
262
- [{date: ''}, 'must be a valid date'],
263
- ],
264
- });
265
- });