@docusaurus/plugin-content-blog 2.0.0-beta.1ec2c95e3 → 2.0.0-beta.21

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 (57) 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 +166 -192
  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} +43 -13
  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 +22 -18
  21. package/src/authors.ts +168 -0
  22. package/src/blogUtils.ts +306 -204
  23. package/{types.d.ts → src/deps.d.ts} +1 -1
  24. package/src/feed.ts +171 -0
  25. package/src/frontMatter.ts +81 -0
  26. package/src/index.ts +227 -256
  27. package/src/markdownLoader.ts +11 -16
  28. package/src/{pluginOptionSchema.ts → options.ts} +56 -15
  29. package/src/plugin-content-blog.d.ts +580 -0
  30. package/src/remark/footnoteIDFixer.ts +29 -0
  31. package/src/translations.ts +69 -0
  32. package/src/types.ts +2 -128
  33. package/index.d.ts +0 -138
  34. package/lib/.tsbuildinfo +0 -1
  35. package/lib/blogFrontMatter.d.ts +0 -28
  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 -76
  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 -317
  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 -88
  57. package/tsconfig.json +0 -9
@@ -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
+ }
@@ -12,13 +12,20 @@ import {
12
12
  AdmonitionsSchema,
13
13
  URISchema,
14
14
  } from '@docusaurus/utils-validation';
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';
15
22
 
16
- export const DEFAULT_OPTIONS = {
17
- feedOptions: {type: ['rss', 'atom']},
23
+ export const DEFAULT_OPTIONS: PluginOptions = {
24
+ feedOptions: {type: ['rss', 'atom'], copyright: ''},
18
25
  beforeDefaultRehypePlugins: [],
19
26
  beforeDefaultRemarkPlugins: [],
20
27
  admonitions: {},
21
- truncateMarker: /<!--\s*(truncate)\s*-->/,
28
+ truncateMarker: /<!--\s*truncate\s*-->/,
22
29
  rehypePlugins: [],
23
30
  remarkPlugins: [],
24
31
  showReadingTime: true,
@@ -26,27 +33,38 @@ export const DEFAULT_OPTIONS = {
26
33
  blogTagsListComponent: '@theme/BlogTagsListPage',
27
34
  blogPostComponent: '@theme/BlogPostPage',
28
35
  blogListComponent: '@theme/BlogListPage',
36
+ blogArchiveComponent: '@theme/BlogArchivePage',
29
37
  blogDescription: 'Blog',
30
38
  blogTitle: 'Blog',
31
39
  blogSidebarCount: 5,
32
40
  blogSidebarTitle: 'Recent posts',
33
41
  postsPerPage: 10,
34
- include: ['*.md', '*.mdx'],
42
+ include: ['**/*.{md,mdx}'],
43
+ exclude: GlobExcludeDefault,
35
44
  routeBasePath: 'blog',
45
+ tagsBasePath: 'tags',
46
+ archiveBasePath: 'archive',
36
47
  path: 'blog',
37
48
  editLocalizedFiles: false,
49
+ authorsMapPath: 'authors.yml',
50
+ readingTime: ({content, defaultReadingTime}) => defaultReadingTime({content}),
51
+ sortPosts: 'descending',
38
52
  };
39
53
 
40
- export const PluginOptionSchema = Joi.object({
54
+ const PluginOptionSchema = Joi.object<PluginOptions>({
41
55
  path: Joi.string().default(DEFAULT_OPTIONS.path),
56
+ archiveBasePath: Joi.string()
57
+ .default(DEFAULT_OPTIONS.archiveBasePath)
58
+ .allow(null),
42
59
  routeBasePath: Joi.string()
43
60
  // '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
44
61
  // .allow('')
45
62
  .default(DEFAULT_OPTIONS.routeBasePath),
63
+ tagsBasePath: Joi.string().default(DEFAULT_OPTIONS.tagsBasePath),
46
64
  include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
47
- postsPerPage: Joi.number()
48
- .integer()
49
- .min(1)
65
+ exclude: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.exclude),
66
+ postsPerPage: Joi.alternatives()
67
+ .try(Joi.equal('ALL').required(), Joi.number().integer().min(1).required())
50
68
  .default(DEFAULT_OPTIONS.postsPerPage),
51
69
  blogListComponent: Joi.string().default(DEFAULT_OPTIONS.blogListComponent),
52
70
  blogPostComponent: Joi.string().default(DEFAULT_OPTIONS.blogPostComponent),
@@ -56,12 +74,15 @@ export const PluginOptionSchema = Joi.object({
56
74
  blogTagsPostsComponent: Joi.string().default(
57
75
  DEFAULT_OPTIONS.blogTagsPostsComponent,
58
76
  ),
77
+ blogArchiveComponent: Joi.string().default(
78
+ DEFAULT_OPTIONS.blogArchiveComponent,
79
+ ),
59
80
  blogTitle: Joi.string().allow('').default(DEFAULT_OPTIONS.blogTitle),
60
81
  blogDescription: Joi.string()
61
82
  .allow('')
62
83
  .default(DEFAULT_OPTIONS.blogDescription),
63
84
  blogSidebarCount: Joi.alternatives()
64
- .try(Joi.equal('ALL').required(), Joi.number().required())
85
+ .try(Joi.equal('ALL').required(), Joi.number().integer().min(0).required())
65
86
  .default(DEFAULT_OPTIONS.blogSidebarCount),
66
87
  blogSidebarTitle: Joi.string().default(DEFAULT_OPTIONS.blogSidebarTitle),
67
88
  showReadingTime: Joi.bool().default(DEFAULT_OPTIONS.showReadingTime),
@@ -80,12 +101,12 @@ export const PluginOptionSchema = Joi.object({
80
101
  feedOptions: Joi.object({
81
102
  type: Joi.alternatives()
82
103
  .try(
83
- Joi.array().items(Joi.string()),
104
+ Joi.array().items(Joi.string().equal('rss', 'atom', 'json')),
84
105
  Joi.alternatives().conditional(
85
- Joi.string().equal('all', 'rss', 'atom'),
106
+ Joi.string().equal('all', 'rss', 'atom', 'json'),
86
107
  {
87
- then: Joi.custom((val) =>
88
- val === 'all' ? ['rss', 'atom'] : [val],
108
+ then: Joi.custom((val: FeedType | 'all') =>
109
+ val === 'all' ? ['rss', 'atom', 'json'] : [val],
89
110
  ),
90
111
  },
91
112
  ),
@@ -94,7 +115,27 @@ export const PluginOptionSchema = Joi.object({
94
115
  .default(DEFAULT_OPTIONS.feedOptions.type),
95
116
  title: Joi.string().allow(''),
96
117
  description: Joi.string().allow(''),
97
- 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
+ }),
98
126
  language: Joi.string(),
99
127
  }).default(DEFAULT_OPTIONS.feedOptions),
100
- });
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
+ }