@docusaurus/plugin-content-blog 2.0.0-beta.fc64c12e4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) 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 +201 -145
  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/{blogFrontMatter.js → frontMatter.js} +31 -19
  9. package/lib/index.d.ts +4 -4
  10. package/lib/index.js +163 -194
  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} +41 -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 -110
  20. package/package.json +23 -19
  21. package/src/authors.ts +168 -0
  22. package/src/blogUtils.ts +305 -205
  23. package/src/feed.ts +171 -0
  24. package/src/frontMatter.ts +81 -0
  25. package/src/index.ts +223 -258
  26. package/src/markdownLoader.ts +11 -16
  27. package/src/{pluginOptionSchema.ts → options.ts} +54 -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 -129
  32. package/index.d.ts +0 -138
  33. package/lib/.tsbuildinfo +0 -1
  34. package/lib/blogFrontMatter.d.ts +0 -28
  35. package/lib/pluginOptionSchema.d.ts +0 -34
  36. package/src/__tests__/__fixtures__/website/blog/2018-12-14-Happy-First-Birthday-Slash.md +0 -5
  37. package/src/__tests__/__fixtures__/website/blog/_partials/somePartial.md +0 -3
  38. package/src/__tests__/__fixtures__/website/blog/_partials/subfolder/somePartial.md +0 -3
  39. package/src/__tests__/__fixtures__/website/blog/_somePartial.md +0 -3
  40. package/src/__tests__/__fixtures__/website/blog/complex-slug.md +0 -7
  41. package/src/__tests__/__fixtures__/website/blog/date-matter.md +0 -5
  42. package/src/__tests__/__fixtures__/website/blog/draft.md +0 -6
  43. package/src/__tests__/__fixtures__/website/blog/heading-as-title.md +0 -5
  44. package/src/__tests__/__fixtures__/website/blog/simple-slug.md +0 -7
  45. package/src/__tests__/__fixtures__/website/blog-with-ref/2018-12-14-Happy-First-Birthday-Slash.md +0 -5
  46. package/src/__tests__/__fixtures__/website/blog-with-ref/post-with-broken-links.md +0 -11
  47. package/src/__tests__/__fixtures__/website/blog-with-ref/post.md +0 -5
  48. package/src/__tests__/__fixtures__/website/i18n/en/docusaurus-plugin-content-blog/2018-12-14-Happy-First-Birthday-Slash.md +0 -5
  49. package/src/__tests__/__fixtures__/website-blog-without-date/blog/no date.md +0 -1
  50. package/src/__tests__/__snapshots__/generateBlogFeed.test.ts.snap +0 -116
  51. package/src/__tests__/__snapshots__/linkify.test.ts.snap +0 -24
  52. package/src/__tests__/__snapshots__/pluginOptionSchema.test.ts.snap +0 -5
  53. package/src/__tests__/blogFrontMatter.test.ts +0 -317
  54. package/src/__tests__/generateBlogFeed.test.ts +0 -102
  55. package/src/__tests__/index.test.ts +0 -336
  56. package/src/__tests__/linkify.test.ts +0 -93
  57. package/src/__tests__/pluginOptionSchema.test.ts +0 -150
  58. package/src/blogFrontMatter.ts +0 -88
  59. package/tsconfig.json +0 -9
  60. package/types.d.ts +0 -13
@@ -6,20 +6,17 @@
6
6
  */
7
7
 
8
8
  import {truncate, linkify} from './blogUtils';
9
- import {parseQuery} from 'loader-utils';
10
- import {BlogMarkdownLoaderOptions} from './types';
9
+ import type {BlogMarkdownLoaderOptions} from './types';
10
+ import type {LoaderContext} from 'webpack';
11
11
 
12
- // TODO temporary until Webpack5 export this type
13
- // see https://github.com/webpack/webpack/issues/11630
14
- interface Loader extends Function {
15
- (this: any, source: string): string | Buffer | void | undefined;
16
- }
17
-
18
- const markdownLoader: Loader = function (source) {
12
+ export default function markdownLoader(
13
+ this: LoaderContext<BlogMarkdownLoaderOptions>,
14
+ source: string,
15
+ ): void {
19
16
  const filePath = this.resourcePath;
20
- const fileString = source as string;
17
+ const fileString = source;
21
18
  const callback = this.async();
22
- const markdownLoaderOptions = this.getOptions() as BlogMarkdownLoaderOptions;
19
+ const markdownLoaderOptions = this.getOptions();
23
20
 
24
21
  // Linkify blog posts
25
22
  let finalContent = linkify({
@@ -30,14 +27,12 @@ const markdownLoader: Loader = function (source) {
30
27
 
31
28
  // Truncate content if requested (e.g: file.md?truncated=true).
32
29
  const truncated: boolean | undefined = this.resourceQuery
33
- ? !!parseQuery(this.resourceQuery).truncated
30
+ ? !!new URLSearchParams(this.resourceQuery.slice(1)).get('truncated')
34
31
  : undefined;
35
32
 
36
33
  if (truncated) {
37
34
  finalContent = truncate(finalContent, markdownLoaderOptions.truncateMarker);
38
35
  }
39
36
 
40
- return callback && callback(null, finalContent);
41
- };
42
-
43
- export default markdownLoader;
37
+ return callback(null, finalContent);
38
+ }
@@ -13,13 +13,19 @@ import {
13
13
  URISchema,
14
14
  } from '@docusaurus/utils-validation';
15
15
  import {GlobExcludeDefault} from '@docusaurus/utils';
16
+ import type {
17
+ PluginOptions,
18
+ Options,
19
+ FeedType,
20
+ } from '@docusaurus/plugin-content-blog';
21
+ import type {OptionValidationContext} from '@docusaurus/types';
16
22
 
17
- export const DEFAULT_OPTIONS = {
18
- feedOptions: {type: ['rss', 'atom']},
23
+ export const DEFAULT_OPTIONS: PluginOptions = {
24
+ feedOptions: {type: ['rss', 'atom'], copyright: ''},
19
25
  beforeDefaultRehypePlugins: [],
20
26
  beforeDefaultRemarkPlugins: [],
21
- admonitions: {},
22
- truncateMarker: /<!--\s*(truncate)\s*-->/,
27
+ admonitions: true,
28
+ truncateMarker: /<!--\s*truncate\s*-->/,
23
29
  rehypePlugins: [],
24
30
  remarkPlugins: [],
25
31
  showReadingTime: true,
@@ -27,29 +33,38 @@ export const DEFAULT_OPTIONS = {
27
33
  blogTagsListComponent: '@theme/BlogTagsListPage',
28
34
  blogPostComponent: '@theme/BlogPostPage',
29
35
  blogListComponent: '@theme/BlogListPage',
36
+ blogArchiveComponent: '@theme/BlogArchivePage',
30
37
  blogDescription: 'Blog',
31
38
  blogTitle: 'Blog',
32
39
  blogSidebarCount: 5,
33
40
  blogSidebarTitle: 'Recent posts',
34
41
  postsPerPage: 10,
35
- include: ['*.md', '*.mdx'],
42
+ include: ['**/*.{md,mdx}'],
36
43
  exclude: GlobExcludeDefault,
37
44
  routeBasePath: 'blog',
45
+ tagsBasePath: 'tags',
46
+ archiveBasePath: 'archive',
38
47
  path: 'blog',
39
48
  editLocalizedFiles: false,
49
+ authorsMapPath: 'authors.yml',
50
+ readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}),
51
+ sortPosts: 'descending',
40
52
  };
41
53
 
42
- export const PluginOptionSchema = Joi.object({
54
+ const PluginOptionSchema = Joi.object<PluginOptions>({
43
55
  path: Joi.string().default(DEFAULT_OPTIONS.path),
56
+ archiveBasePath: Joi.string()
57
+ .default(DEFAULT_OPTIONS.archiveBasePath)
58
+ .allow(null),
44
59
  routeBasePath: Joi.string()
45
60
  // '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
46
61
  // .allow('')
47
62
  .default(DEFAULT_OPTIONS.routeBasePath),
63
+ tagsBasePath: Joi.string().default(DEFAULT_OPTIONS.tagsBasePath),
48
64
  include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
49
65
  exclude: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.exclude),
50
- postsPerPage: Joi.number()
51
- .integer()
52
- .min(1)
66
+ postsPerPage: Joi.alternatives()
67
+ .try(Joi.equal('ALL').required(), Joi.number().integer().min(1).required())
53
68
  .default(DEFAULT_OPTIONS.postsPerPage),
54
69
  blogListComponent: Joi.string().default(DEFAULT_OPTIONS.blogListComponent),
55
70
  blogPostComponent: Joi.string().default(DEFAULT_OPTIONS.blogPostComponent),
@@ -59,12 +74,15 @@ export const PluginOptionSchema = Joi.object({
59
74
  blogTagsPostsComponent: Joi.string().default(
60
75
  DEFAULT_OPTIONS.blogTagsPostsComponent,
61
76
  ),
77
+ blogArchiveComponent: Joi.string().default(
78
+ DEFAULT_OPTIONS.blogArchiveComponent,
79
+ ),
62
80
  blogTitle: Joi.string().allow('').default(DEFAULT_OPTIONS.blogTitle),
63
81
  blogDescription: Joi.string()
64
82
  .allow('')
65
83
  .default(DEFAULT_OPTIONS.blogDescription),
66
84
  blogSidebarCount: Joi.alternatives()
67
- .try(Joi.equal('ALL').required(), Joi.number().required())
85
+ .try(Joi.equal('ALL').required(), Joi.number().integer().min(0).required())
68
86
  .default(DEFAULT_OPTIONS.blogSidebarCount),
69
87
  blogSidebarTitle: Joi.string().default(DEFAULT_OPTIONS.blogSidebarTitle),
70
88
  showReadingTime: Joi.bool().default(DEFAULT_OPTIONS.showReadingTime),
@@ -83,12 +101,12 @@ export const PluginOptionSchema = Joi.object({
83
101
  feedOptions: Joi.object({
84
102
  type: Joi.alternatives()
85
103
  .try(
86
- Joi.array().items(Joi.string()),
104
+ Joi.array().items(Joi.string().equal('rss', 'atom', 'json')),
87
105
  Joi.alternatives().conditional(
88
- Joi.string().equal('all', 'rss', 'atom'),
106
+ Joi.string().equal('all', 'rss', 'atom', 'json'),
89
107
  {
90
- then: Joi.custom((val) =>
91
- val === 'all' ? ['rss', 'atom'] : [val],
108
+ then: Joi.custom((val: FeedType | 'all') =>
109
+ val === 'all' ? ['rss', 'atom', 'json'] : [val],
92
110
  ),
93
111
  },
94
112
  ),
@@ -97,7 +115,27 @@ export const PluginOptionSchema = Joi.object({
97
115
  .default(DEFAULT_OPTIONS.feedOptions.type),
98
116
  title: Joi.string().allow(''),
99
117
  description: Joi.string().allow(''),
100
- copyright: Joi.string(),
118
+ // Only add default value when user actually wants a feed (type is not null)
119
+ copyright: Joi.when('type', {
120
+ is: Joi.any().valid(null),
121
+ then: Joi.string().optional(),
122
+ otherwise: Joi.string()
123
+ .allow('')
124
+ .default(DEFAULT_OPTIONS.feedOptions.copyright),
125
+ }),
101
126
  language: Joi.string(),
102
127
  }).default(DEFAULT_OPTIONS.feedOptions),
103
- });
128
+ authorsMapPath: Joi.string().default(DEFAULT_OPTIONS.authorsMapPath),
129
+ readingTime: Joi.function().default(() => DEFAULT_OPTIONS.readingTime),
130
+ sortPosts: Joi.string()
131
+ .valid('descending', 'ascending')
132
+ .default(DEFAULT_OPTIONS.sortPosts),
133
+ }).default(DEFAULT_OPTIONS);
134
+
135
+ export function validateOptions({
136
+ validate,
137
+ options,
138
+ }: OptionValidationContext<Options | undefined, PluginOptions>): PluginOptions {
139
+ const validatedOptions = validate(PluginOptionSchema, options);
140
+ return validatedOptions;
141
+ }