@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.
Files changed (76) hide show
  1. package/lib/authors.d.ts +5 -8
  2. package/lib/authors.js +15 -53
  3. package/lib/blogFrontMatter.d.ts +1 -34
  4. package/lib/blogFrontMatter.js +3 -3
  5. package/lib/blogUtils.d.ts +3 -3
  6. package/lib/blogUtils.js +28 -22
  7. package/lib/feed.d.ts +3 -8
  8. package/lib/feed.js +46 -35
  9. package/lib/index.d.ts +4 -3
  10. package/lib/index.js +33 -28
  11. package/lib/markdownLoader.d.ts +1 -1
  12. package/lib/markdownLoader.js +1 -2
  13. package/lib/pluginOptionSchema.d.ts +1 -1
  14. package/lib/pluginOptionSchema.js +5 -3
  15. package/lib/translations.d.ts +2 -1
  16. package/lib/translations.js +3 -3
  17. package/lib/types.d.ts +2 -79
  18. package/package.json +11 -12
  19. package/src/authors.ts +22 -69
  20. package/src/blogFrontMatter.ts +5 -50
  21. package/src/blogUtils.ts +38 -34
  22. package/src/feed.ts +80 -37
  23. package/src/index.ts +48 -44
  24. package/src/markdownLoader.ts +2 -3
  25. package/src/plugin-content-blog.d.ts +147 -4
  26. package/src/pluginOptionSchema.ts +7 -5
  27. package/src/translations.ts +5 -4
  28. package/src/types.ts +5 -97
  29. package/lib/.tsbuildinfo +0 -1
  30. package/src/__tests__/__fixtures__/authorsMapFiles/authors.json +0 -29
  31. package/src/__tests__/__fixtures__/authorsMapFiles/authors.yml +0 -27
  32. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad1.json +0 -5
  33. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad1.yml +0 -3
  34. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad2.json +0 -3
  35. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad2.yml +0 -2
  36. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad3.json +0 -8
  37. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad3.yml +0 -3
  38. package/src/__tests__/__fixtures__/component/Typography.tsx +0 -6
  39. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathEmpty/empty +0 -0
  40. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathJson1/authors.json +0 -0
  41. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathJson2/authors.json +0 -0
  42. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathNestedYml/sub/folder/authors.yml +0 -0
  43. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathYml1/authors.yml +0 -0
  44. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathYml2/authors.yml +0 -0
  45. package/src/__tests__/__fixtures__/website/blog/2018-12-14-Happy-First-Birthday-Slash.md +0 -8
  46. package/src/__tests__/__fixtures__/website/blog/_partials/somePartial.md +0 -3
  47. package/src/__tests__/__fixtures__/website/blog/_partials/subfolder/somePartial.md +0 -3
  48. package/src/__tests__/__fixtures__/website/blog/_somePartial.md +0 -3
  49. package/src/__tests__/__fixtures__/website/blog/authors.yml +0 -4
  50. package/src/__tests__/__fixtures__/website/blog/complex-slug.md +0 -7
  51. package/src/__tests__/__fixtures__/website/blog/date-matter.md +0 -5
  52. package/src/__tests__/__fixtures__/website/blog/draft.md +0 -6
  53. package/src/__tests__/__fixtures__/website/blog/heading-as-title.md +0 -5
  54. package/src/__tests__/__fixtures__/website/blog/mdx-blog-post.mdx +0 -36
  55. package/src/__tests__/__fixtures__/website/blog/mdx-require-blog-post.mdx +0 -14
  56. package/src/__tests__/__fixtures__/website/blog/simple-slug.md +0 -11
  57. package/src/__tests__/__fixtures__/website/blog-with-ref/2018-12-14-Happy-First-Birthday-Slash.md +0 -5
  58. package/src/__tests__/__fixtures__/website/blog-with-ref/post-with-broken-links.md +0 -11
  59. package/src/__tests__/__fixtures__/website/blog-with-ref/post.md +0 -5
  60. package/src/__tests__/__fixtures__/website/i18n/en/docusaurus-plugin-content-blog/2018-12-14-Happy-First-Birthday-Slash.md +0 -8
  61. package/src/__tests__/__fixtures__/website/i18n/en/docusaurus-plugin-content-blog/authors.yml +0 -5
  62. package/src/__tests__/__fixtures__/website/static/img/docusaurus.png +0 -0
  63. package/src/__tests__/__fixtures__/website-blog-without-date/blog/no date.md +0 -1
  64. package/src/__tests__/__snapshots__/feed.test.ts.snap +0 -164
  65. package/src/__tests__/__snapshots__/linkify.test.ts.snap +0 -24
  66. package/src/__tests__/__snapshots__/pluginOptionSchema.test.ts.snap +0 -5
  67. package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -64
  68. package/src/__tests__/authors.test.ts +0 -608
  69. package/src/__tests__/blogFrontMatter.test.ts +0 -394
  70. package/src/__tests__/blogUtils.test.ts +0 -94
  71. package/src/__tests__/feed.test.ts +0 -126
  72. package/src/__tests__/index.test.ts +0 -408
  73. package/src/__tests__/linkify.test.ts +0 -93
  74. package/src/__tests__/pluginOptionSchema.test.ts +0 -150
  75. package/src/__tests__/translations.test.ts +0 -92
  76. package/tsconfig.json +0 -9
@@ -1,408 +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 fs from 'fs-extra';
9
- import path from 'path';
10
- import pluginContentBlog from '../index';
11
- import {DocusaurusConfig, LoadContext, I18n} from '@docusaurus/types';
12
- import {PluginOptionSchema} from '../pluginOptionSchema';
13
- import {PluginOptions, EditUrlFunction, BlogPost} from '../types';
14
- import {Joi} from '@docusaurus/utils-validation';
15
- import {posixPath} from '@docusaurus/utils';
16
-
17
- function findByTitle(
18
- blogPosts: BlogPost[],
19
- title: string,
20
- ): BlogPost | undefined {
21
- return blogPosts.find((v) => v.metadata.title === title);
22
- }
23
- function getByTitle(blogPosts: BlogPost[], title: string): BlogPost {
24
- const post = findByTitle(blogPosts, title);
25
- if (!post) {
26
- throw new Error(`can't find blog post with title ${title}.
27
- Available blog post titles are:\n- ${blogPosts
28
- .map((p) => p.metadata.title)
29
- .join('\n- ')}`);
30
- }
31
- return post;
32
- }
33
-
34
- function getI18n(locale: string): I18n {
35
- return {
36
- currentLocale: locale,
37
- locales: [locale],
38
- defaultLocale: locale,
39
- localeConfigs: {},
40
- };
41
- }
42
-
43
- const DefaultI18N: I18n = getI18n('en');
44
-
45
- function validateAndNormalize(
46
- schema: Joi.ObjectSchema,
47
- options: Partial<PluginOptions>,
48
- ) {
49
- const {value, error} = schema.validate(options);
50
- if (error) {
51
- throw error;
52
- } else {
53
- return value;
54
- }
55
- }
56
-
57
- describe('loadBlog', () => {
58
- const PluginPath = 'blog';
59
-
60
- const BaseEditUrl = 'https://baseEditUrl.com/edit';
61
-
62
- const getPlugin = async (
63
- siteDir: string,
64
- pluginOptions: Partial<PluginOptions> = {},
65
- i18n: I18n = DefaultI18N,
66
- ) => {
67
- const generatedFilesDir: string = path.resolve(siteDir, '.docusaurus');
68
- const siteConfig = {
69
- title: 'Hello',
70
- baseUrl: '/',
71
- url: 'https://docusaurus.io',
72
- } as DocusaurusConfig;
73
- return pluginContentBlog(
74
- {
75
- siteDir,
76
- siteConfig,
77
- generatedFilesDir,
78
- i18n,
79
- } as LoadContext,
80
- validateAndNormalize(PluginOptionSchema, {
81
- path: PluginPath,
82
- editUrl: BaseEditUrl,
83
- ...pluginOptions,
84
- }),
85
- );
86
- };
87
-
88
- const getBlogPosts = async (
89
- siteDir: string,
90
- pluginOptions: Partial<PluginOptions> = {},
91
- i18n: I18n = DefaultI18N,
92
- ) => {
93
- const plugin = await getPlugin(siteDir, pluginOptions, i18n);
94
- const {blogPosts} = (await plugin.loadContent!())!;
95
- return blogPosts;
96
- };
97
-
98
- test('getPathsToWatch', async () => {
99
- const siteDir = path.join(__dirname, '__fixtures__', 'website');
100
- const plugin = await getPlugin(siteDir);
101
- const pathsToWatch = plugin.getPathsToWatch!();
102
- const relativePathsToWatch = pathsToWatch.map((p) =>
103
- posixPath(path.relative(siteDir, p)),
104
- );
105
- expect(relativePathsToWatch).toEqual([
106
- 'blog/authors.yml',
107
- 'i18n/en/docusaurus-plugin-content-blog/**/*.{md,mdx}',
108
- 'blog/**/*.{md,mdx}',
109
- ]);
110
- });
111
-
112
- test('simple website', async () => {
113
- const siteDir = path.join(__dirname, '__fixtures__', 'website');
114
- const blogPosts = await getBlogPosts(siteDir);
115
-
116
- expect({
117
- ...getByTitle(blogPosts, 'date-matter').metadata,
118
- ...{prevItem: undefined},
119
- }).toEqual({
120
- editUrl: `${BaseEditUrl}/blog/date-matter.md`,
121
- permalink: '/blog/date-matter',
122
- readingTime: 0.02,
123
- source: path.posix.join('@site', PluginPath, 'date-matter.md'),
124
- title: 'date-matter',
125
- description: `date inside front matter`,
126
- authors: [],
127
- date: new Date('2019-01-01'),
128
- formattedDate: 'January 1, 2019',
129
- prevItem: undefined,
130
- tags: [],
131
- nextItem: {
132
- permalink: '/blog/2018/12/14/Happy-First-Birthday-Slash',
133
- title: 'Happy 1st Birthday Slash! (translated)',
134
- },
135
- truncated: false,
136
- });
137
-
138
- expect(
139
- getByTitle(blogPosts, 'Happy 1st Birthday Slash! (translated)').metadata,
140
- ).toEqual({
141
- editUrl: `${BaseEditUrl}/blog/2018-12-14-Happy-First-Birthday-Slash.md`,
142
- permalink: '/blog/2018/12/14/Happy-First-Birthday-Slash',
143
- readingTime: 0.015,
144
- source: path.posix.join(
145
- '@site',
146
- // pluginPath,
147
- path.posix.join('i18n', 'en', 'docusaurus-plugin-content-blog'),
148
- '2018-12-14-Happy-First-Birthday-Slash.md',
149
- ),
150
- title: 'Happy 1st Birthday Slash! (translated)',
151
- description: `Happy birthday! (translated)`,
152
- authors: [
153
- {
154
- name: 'Yangshun Tay (translated)',
155
- },
156
- {
157
- key: 'slorber',
158
- name: 'Sébastien Lorber (translated)',
159
- title: 'Docusaurus maintainer (translated)',
160
- },
161
- ],
162
- date: new Date('2018-12-14'),
163
- formattedDate: 'December 14, 2018',
164
- tags: [],
165
- prevItem: {
166
- permalink: '/blog/date-matter',
167
- title: 'date-matter',
168
- },
169
- truncated: false,
170
- });
171
-
172
- expect({
173
- ...getByTitle(blogPosts, 'Complex Slug').metadata,
174
- ...{prevItem: undefined},
175
- }).toEqual({
176
- editUrl: `${BaseEditUrl}/blog/complex-slug.md`,
177
- permalink: '/blog/hey/my super path/héllô',
178
- readingTime: 0.015,
179
- source: path.posix.join('@site', PluginPath, 'complex-slug.md'),
180
- title: 'Complex Slug',
181
- description: `complex url slug`,
182
- authors: [],
183
- prevItem: undefined,
184
- nextItem: {
185
- permalink: '/blog/simple/slug',
186
- title: 'Simple Slug',
187
- },
188
- date: new Date('2020-08-16'),
189
- formattedDate: 'August 16, 2020',
190
- tags: [],
191
- truncated: false,
192
- });
193
-
194
- expect({
195
- ...getByTitle(blogPosts, 'Simple Slug').metadata,
196
- ...{prevItem: undefined},
197
- }).toEqual({
198
- editUrl: `${BaseEditUrl}/blog/simple-slug.md`,
199
- permalink: '/blog/simple/slug',
200
- readingTime: 0.015,
201
- source: path.posix.join('@site', PluginPath, 'simple-slug.md'),
202
- title: 'Simple Slug',
203
- description: `simple url slug`,
204
- authors: [
205
- {
206
- name: 'Sébastien Lorber',
207
- title: 'Docusaurus maintainer',
208
- url: 'https://sebastienlorber.com',
209
- imageURL: undefined,
210
- },
211
- ],
212
- prevItem: undefined,
213
- nextItem: {
214
- permalink: '/blog/draft',
215
- title: 'draft',
216
- },
217
- date: new Date('2020-08-15'),
218
- formattedDate: 'August 15, 2020',
219
- tags: [],
220
- truncated: false,
221
- });
222
-
223
- expect({
224
- ...getByTitle(blogPosts, 'some heading').metadata,
225
- prevItem: undefined,
226
- }).toEqual({
227
- editUrl: `${BaseEditUrl}/blog/heading-as-title.md`,
228
- permalink: '/blog/heading-as-title',
229
- readingTime: 0,
230
- source: path.posix.join('@site', PluginPath, 'heading-as-title.md'),
231
- title: 'some heading',
232
- description: '',
233
- authors: [],
234
- date: new Date('2019-01-02'),
235
- formattedDate: 'January 2, 2019',
236
- prevItem: undefined,
237
- tags: [],
238
- nextItem: {
239
- permalink: '/blog/date-matter',
240
- title: 'date-matter',
241
- },
242
- truncated: false,
243
- });
244
- });
245
-
246
- test('simple website blog dates localized', async () => {
247
- const siteDir = path.join(__dirname, '__fixtures__', 'website');
248
- const blogPostsFrench = await getBlogPosts(siteDir, {}, getI18n('fr'));
249
- expect(blogPostsFrench).toHaveLength(8);
250
- expect(blogPostsFrench[0].metadata.formattedDate).toMatchInlineSnapshot(
251
- `"6 mars 2021"`,
252
- );
253
- expect(blogPostsFrench[1].metadata.formattedDate).toMatchInlineSnapshot(
254
- `"5 mars 2021"`,
255
- );
256
- expect(blogPostsFrench[2].metadata.formattedDate).toMatchInlineSnapshot(
257
- `"16 août 2020"`,
258
- );
259
- expect(blogPostsFrench[3].metadata.formattedDate).toMatchInlineSnapshot(
260
- `"15 août 2020"`,
261
- );
262
- expect(blogPostsFrench[4].metadata.formattedDate).toMatchInlineSnapshot(
263
- `"27 février 2020"`,
264
- );
265
- expect(blogPostsFrench[5].metadata.formattedDate).toMatchInlineSnapshot(
266
- `"2 janvier 2019"`,
267
- );
268
- expect(blogPostsFrench[6].metadata.formattedDate).toMatchInlineSnapshot(
269
- `"1 janvier 2019"`,
270
- );
271
- expect(blogPostsFrench[7].metadata.formattedDate).toMatchInlineSnapshot(
272
- `"14 décembre 2018"`,
273
- );
274
- });
275
-
276
- test('edit url with editLocalizedBlogs true', async () => {
277
- const siteDir = path.join(__dirname, '__fixtures__', 'website');
278
- const blogPosts = await getBlogPosts(siteDir, {editLocalizedFiles: true});
279
-
280
- const localizedBlogPost = blogPosts.find(
281
- (v) => v.metadata.title === 'Happy 1st Birthday Slash! (translated)',
282
- )!;
283
-
284
- expect(localizedBlogPost.metadata.editUrl).toEqual(
285
- `${BaseEditUrl}/i18n/en/docusaurus-plugin-content-blog/2018-12-14-Happy-First-Birthday-Slash.md`,
286
- );
287
- });
288
-
289
- test('edit url with editUrl function', async () => {
290
- const siteDir = path.join(__dirname, '__fixtures__', 'website');
291
-
292
- const hardcodedEditUrl = 'hardcoded-edit-url';
293
- const editUrlFunction: EditUrlFunction = jest.fn(() => hardcodedEditUrl);
294
-
295
- const blogPosts = await getBlogPosts(siteDir, {editUrl: editUrlFunction});
296
-
297
- blogPosts.forEach((blogPost) => {
298
- expect(blogPost.metadata.editUrl).toEqual(hardcodedEditUrl);
299
- });
300
-
301
- expect(editUrlFunction).toHaveBeenCalledTimes(8);
302
-
303
- expect(editUrlFunction).toHaveBeenCalledWith({
304
- blogDirPath: 'blog',
305
- blogPath: 'date-matter.md',
306
- permalink: '/blog/date-matter',
307
- locale: 'en',
308
- });
309
- expect(editUrlFunction).toHaveBeenCalledWith({
310
- blogDirPath: 'blog',
311
- blogPath: 'draft.md',
312
- permalink: '/blog/draft',
313
- locale: 'en',
314
- });
315
- expect(editUrlFunction).toHaveBeenCalledWith({
316
- blogDirPath: 'blog',
317
- blogPath: 'mdx-blog-post.mdx',
318
- permalink: '/blog/mdx-blog-post',
319
- locale: 'en',
320
- });
321
- expect(editUrlFunction).toHaveBeenCalledWith({
322
- blogDirPath: 'blog',
323
- blogPath: 'mdx-require-blog-post.mdx',
324
- permalink: '/blog/mdx-require-blog-post',
325
- locale: 'en',
326
- });
327
- expect(editUrlFunction).toHaveBeenCalledWith({
328
- blogDirPath: 'blog',
329
- blogPath: 'complex-slug.md',
330
- permalink: '/blog/hey/my super path/héllô',
331
- locale: 'en',
332
- });
333
- expect(editUrlFunction).toHaveBeenCalledWith({
334
- blogDirPath: 'blog',
335
- blogPath: 'simple-slug.md',
336
- permalink: '/blog/simple/slug',
337
- locale: 'en',
338
- });
339
- expect(editUrlFunction).toHaveBeenCalledWith({
340
- blogDirPath: 'i18n/en/docusaurus-plugin-content-blog',
341
- blogPath: '2018-12-14-Happy-First-Birthday-Slash.md',
342
- permalink: '/blog/2018/12/14/Happy-First-Birthday-Slash',
343
- locale: 'en',
344
- });
345
- expect(editUrlFunction).toHaveBeenCalledWith({
346
- blogDirPath: 'blog',
347
- blogPath: 'heading-as-title.md',
348
- locale: 'en',
349
- permalink: '/blog/heading-as-title',
350
- });
351
- });
352
-
353
- test('draft blog post not exists in production build', async () => {
354
- process.env.NODE_ENV = 'production';
355
- const siteDir = path.join(__dirname, '__fixtures__', 'website');
356
- const blogPosts = await getBlogPosts(siteDir);
357
-
358
- expect(blogPosts.find((v) => v.metadata.title === 'draft')).toBeUndefined();
359
- });
360
-
361
- test('create blog post without date', async () => {
362
- const siteDir = path.join(
363
- __dirname,
364
- '__fixtures__',
365
- 'website-blog-without-date',
366
- );
367
- const blogPosts = await getBlogPosts(siteDir);
368
- const noDateSource = path.posix.join('@site', PluginPath, 'no date.md');
369
- const noDateSourceBirthTime = (
370
- await fs.stat(noDateSource.replace('@site', siteDir))
371
- ).birthtime;
372
- const formattedDate = Intl.DateTimeFormat('en', {
373
- day: 'numeric',
374
- month: 'long',
375
- year: 'numeric',
376
- }).format(noDateSourceBirthTime);
377
-
378
- expect({
379
- ...getByTitle(blogPosts, 'no date').metadata,
380
- ...{prevItem: undefined},
381
- }).toEqual({
382
- editUrl: `${BaseEditUrl}/blog/no date.md`,
383
- permalink: '/blog/no date',
384
- readingTime: 0.01,
385
- source: noDateSource,
386
- title: 'no date',
387
- description: `no date`,
388
- authors: [],
389
- date: noDateSourceBirthTime,
390
- formattedDate,
391
- tags: [],
392
- prevItem: undefined,
393
- nextItem: undefined,
394
- truncated: false,
395
- });
396
- });
397
-
398
- test('test ascending sort direction of blog post', async () => {
399
- const siteDir = path.join(__dirname, '__fixtures__', 'website');
400
- const normalOrder = await getBlogPosts(siteDir);
401
- const reversedOrder = await getBlogPosts(siteDir, {
402
- sortPosts: 'ascending',
403
- });
404
- expect(normalOrder.reverse().map((x) => x.metadata.date)).toEqual(
405
- reversedOrder.map((x) => x.metadata.date),
406
- );
407
- });
408
- });
@@ -1,93 +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 fs from 'fs-extra';
9
- import path from 'path';
10
- import {linkify, LinkifyParams, getSourceToPermalink} from '../blogUtils';
11
- import {BlogBrokenMarkdownLink, BlogContentPaths, BlogPost} from '../types';
12
-
13
- const siteDir = path.join(__dirname, '__fixtures__', 'website');
14
- const contentPaths: BlogContentPaths = {
15
- contentPath: path.join(siteDir, 'blog-with-ref'),
16
- contentPathLocalized: path.join(siteDir, 'blog-with-ref-localized'),
17
- };
18
- const pluginDir = 'blog-with-ref';
19
- const blogPosts: BlogPost[] = [
20
- {
21
- id: 'Happy 1st Birthday Slash!',
22
- metadata: {
23
- permalink: '/blog/2018/12/14/Happy-First-Birthday-Slash',
24
- source: path.posix.join(
25
- '@site',
26
- pluginDir,
27
- '2018-12-14-Happy-First-Birthday-Slash.md',
28
- ),
29
- title: 'Happy 1st Birthday Slash!',
30
- description: `pattern name`,
31
- date: new Date('2018-12-14'),
32
- tags: [],
33
- prevItem: {
34
- permalink: '/blog/2019/01/01/date-matter',
35
- title: 'date-matter',
36
- },
37
- truncated: false,
38
- },
39
- },
40
- ];
41
-
42
- const transform = (filePath: string, options?: Partial<LinkifyParams>) => {
43
- const fileContent = fs.readFileSync(filePath, 'utf-8');
44
- const transformedContent = linkify({
45
- filePath,
46
- fileString: fileContent,
47
- siteDir,
48
- contentPaths,
49
- sourceToPermalink: getSourceToPermalink(blogPosts),
50
- onBrokenMarkdownLink: (brokenMarkdownLink) => {
51
- throw new Error(
52
- `Broken markdown link found: ${JSON.stringify(brokenMarkdownLink)}`,
53
- );
54
- },
55
- ...options,
56
- });
57
- return [fileContent, transformedContent];
58
- };
59
-
60
- test('transform to correct link', () => {
61
- const post = path.join(contentPaths.contentPath, 'post.md');
62
- const [content, transformedContent] = transform(post);
63
- expect(transformedContent).toMatchSnapshot();
64
- expect(transformedContent).toContain(
65
- '](/blog/2018/12/14/Happy-First-Birthday-Slash',
66
- );
67
- expect(transformedContent).not.toContain(
68
- '](2018-12-14-Happy-First-Birthday-Slash.md)',
69
- );
70
- expect(content).not.toEqual(transformedContent);
71
- });
72
-
73
- test('report broken markdown links', () => {
74
- const filePath = 'post-with-broken-links.md';
75
- const folderPath = contentPaths.contentPath;
76
- const postWithBrokenLinks = path.join(folderPath, filePath);
77
- const onBrokenMarkdownLink = jest.fn();
78
- const [, transformedContent] = transform(postWithBrokenLinks, {
79
- onBrokenMarkdownLink,
80
- });
81
- expect(transformedContent).toMatchSnapshot();
82
- expect(onBrokenMarkdownLink).toHaveBeenCalledTimes(2);
83
- expect(onBrokenMarkdownLink).toHaveBeenNthCalledWith(1, {
84
- filePath: path.resolve(folderPath, filePath),
85
- contentPaths,
86
- link: 'postNotExist1.md',
87
- } as BlogBrokenMarkdownLink);
88
- expect(onBrokenMarkdownLink).toHaveBeenNthCalledWith(2, {
89
- filePath: path.resolve(folderPath, filePath),
90
- contentPaths,
91
- link: './postNotExist2.mdx',
92
- } as BlogBrokenMarkdownLink);
93
- });
@@ -1,150 +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 {PluginOptionSchema, DEFAULT_OPTIONS} from '../pluginOptionSchema';
9
-
10
- // the type of remark/rehype plugins can be either function, object or array
11
- const markdownPluginsFunctionStub = () => {};
12
- const markdownPluginsObjectStub = {};
13
-
14
- test('should normalize options', () => {
15
- const {value, error} = PluginOptionSchema.validate({});
16
- expect(value).toEqual(DEFAULT_OPTIONS);
17
- expect(error).toBe(undefined);
18
- });
19
-
20
- test('should accept correctly defined user options', () => {
21
- const userOptions = {
22
- ...DEFAULT_OPTIONS,
23
- feedOptions: {type: 'rss', title: 'myTitle'},
24
- path: 'not_blog',
25
- routeBasePath: 'myBlog',
26
- postsPerPage: 5,
27
- include: ['api/*', 'docs/*'],
28
- };
29
- const {value, error} = PluginOptionSchema.validate(userOptions);
30
- expect(value).toEqual({
31
- ...userOptions,
32
- feedOptions: {type: ['rss'], title: 'myTitle', copyright: ''},
33
- });
34
- expect(error).toBe(undefined);
35
- });
36
-
37
- test('should accept valid user options', async () => {
38
- const userOptions = {
39
- ...DEFAULT_OPTIONS,
40
- routeBasePath: 'myBlog',
41
- beforeDefaultRemarkPlugins: [],
42
- beforeDefaultRehypePlugins: [markdownPluginsFunctionStub],
43
- remarkPlugins: [[markdownPluginsFunctionStub, {option1: '42'}]],
44
- rehypePlugins: [
45
- markdownPluginsObjectStub,
46
- [markdownPluginsFunctionStub, {option1: '42'}],
47
- ],
48
- };
49
- const {value, error} = await PluginOptionSchema.validate(userOptions);
50
- expect(value).toEqual(userOptions);
51
- expect(error).toBe(undefined);
52
- });
53
-
54
- test('should throw Error in case of invalid options', () => {
55
- const {error} = PluginOptionSchema.validate({
56
- path: 'not_blog',
57
- postsPerPage: -1,
58
- include: ['api/*', 'docs/*'],
59
- routeBasePath: 'not_blog',
60
- });
61
-
62
- expect(error).toMatchSnapshot();
63
- });
64
-
65
- test('should throw Error in case of invalid feedtype', () => {
66
- const {error} = PluginOptionSchema.validate({
67
- feedOptions: {
68
- type: 'none',
69
- },
70
- });
71
-
72
- expect(error).toMatchSnapshot();
73
- });
74
-
75
- test('should convert all feed type to array with other feed type', () => {
76
- const {value} = PluginOptionSchema.validate({
77
- feedOptions: {type: 'all'},
78
- });
79
- expect(value).toEqual({
80
- ...DEFAULT_OPTIONS,
81
- feedOptions: {type: ['rss', 'atom'], copyright: ''},
82
- });
83
- });
84
-
85
- test('should accept null type and return same', () => {
86
- const {value, error} = PluginOptionSchema.validate({
87
- feedOptions: {type: null},
88
- });
89
- expect(value).toEqual({
90
- ...DEFAULT_OPTIONS,
91
- feedOptions: {type: null},
92
- });
93
- expect(error).toBe(undefined);
94
- });
95
-
96
- test('should contain array with rss + atom for missing feed type', () => {
97
- const {value} = PluginOptionSchema.validate({
98
- feedOptions: {},
99
- });
100
- expect(value).toEqual(DEFAULT_OPTIONS);
101
- });
102
-
103
- test('should have array with rss + atom, title for missing feed type', () => {
104
- const {value} = PluginOptionSchema.validate({
105
- feedOptions: {title: 'title'},
106
- });
107
- expect(value).toEqual({
108
- ...DEFAULT_OPTIONS,
109
- feedOptions: {type: ['rss', 'atom'], title: 'title', copyright: ''},
110
- });
111
- });
112
-
113
- describe('blog sidebar', () => {
114
- test('should accept 0 sidebar count', () => {
115
- const userOptions = {blogSidebarCount: 0};
116
- const {value, error} = PluginOptionSchema.validate(userOptions);
117
- expect(value).toEqual({...DEFAULT_OPTIONS, ...userOptions});
118
- expect(error).toBe(undefined);
119
- });
120
-
121
- test('should accept "ALL" sidebar count', () => {
122
- const userOptions = {blogSidebarCount: 'ALL'};
123
- const {value, error} = PluginOptionSchema.validate(userOptions);
124
- expect(value).toEqual({...DEFAULT_OPTIONS, ...userOptions});
125
- expect(error).toBe(undefined);
126
- });
127
-
128
- test('should reject "abcdef" sidebar count', () => {
129
- const userOptions = {blogSidebarCount: 'abcdef'};
130
- const {error} = PluginOptionSchema.validate(userOptions);
131
- expect(error).toMatchInlineSnapshot(
132
- `[ValidationError: "blogSidebarCount" must be one of [ALL, number]]`,
133
- );
134
- });
135
-
136
- test('should accept "all posts" sidebar title', () => {
137
- const userOptions = {blogSidebarTitle: 'all posts'};
138
- const {value, error} = PluginOptionSchema.validate(userOptions);
139
- expect(value).toEqual({...DEFAULT_OPTIONS, ...userOptions});
140
- expect(error).toBe(undefined);
141
- });
142
-
143
- test('should reject 42 sidebar title', () => {
144
- const userOptions = {blogSidebarTitle: 42};
145
- const {error} = PluginOptionSchema.validate(userOptions);
146
- expect(error).toMatchInlineSnapshot(
147
- `[ValidationError: "blogSidebarTitle" must be a string]`,
148
- );
149
- });
150
- });