@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.
- package/lib/authors.d.ts +22 -0
- package/lib/authors.js +122 -0
- package/lib/blogUtils.d.ts +27 -7
- package/lib/blogUtils.js +214 -141
- package/lib/feed.d.ts +15 -0
- package/lib/feed.js +102 -0
- package/lib/frontMatter.d.ts +10 -0
- package/lib/frontMatter.js +62 -0
- package/lib/index.d.ts +4 -4
- package/lib/index.js +179 -205
- package/lib/markdownLoader.d.ts +3 -6
- package/lib/markdownLoader.js +6 -7
- package/lib/options.d.ts +10 -0
- package/lib/{pluginOptionSchema.js → options.js} +44 -14
- package/lib/remark/footnoteIDFixer.d.ts +14 -0
- package/lib/remark/footnoteIDFixer.js +29 -0
- package/lib/translations.d.ts +10 -0
- package/lib/translations.js +53 -0
- package/lib/types.d.ts +4 -109
- package/package.json +23 -18
- package/src/authors.ts +168 -0
- package/src/blogUtils.ts +316 -196
- package/src/feed.ts +171 -0
- package/src/frontMatter.ts +81 -0
- package/src/index.ts +246 -268
- package/src/markdownLoader.ts +11 -16
- package/src/{pluginOptionSchema.ts → options.ts} +57 -16
- package/src/plugin-content-blog.d.ts +587 -0
- package/src/remark/footnoteIDFixer.ts +29 -0
- package/src/translations.ts +69 -0
- package/src/types.ts +2 -128
- package/index.d.ts +0 -138
- package/lib/.tsbuildinfo +0 -4415
- package/lib/blogFrontMatter.d.ts +0 -28
- package/lib/blogFrontMatter.js +0 -50
- package/lib/pluginOptionSchema.d.ts +0 -33
- package/src/__tests__/__fixtures__/website/blog/2018-12-14-Happy-First-Birthday-Slash.md +0 -5
- 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/simple-slug.md +0 -7
- 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 -5
- package/src/__tests__/__fixtures__/website-blog-without-date/blog/no date.md +0 -1
- package/src/__tests__/__snapshots__/generateBlogFeed.test.ts.snap +0 -101
- package/src/__tests__/__snapshots__/linkify.test.ts.snap +0 -24
- package/src/__tests__/__snapshots__/pluginOptionSchema.test.ts.snap +0 -5
- package/src/__tests__/blogFrontMatter.test.ts +0 -265
- package/src/__tests__/generateBlogFeed.test.ts +0 -100
- package/src/__tests__/index.test.ts +0 -336
- package/src/__tests__/linkify.test.ts +0 -93
- package/src/__tests__/pluginOptionSchema.test.ts +0 -150
- package/src/blogFrontMatter.ts +0 -87
- package/tsconfig.json +0 -9
- package/types.d.ts +0 -13
package/src/markdownLoader.ts
CHANGED
|
@@ -6,20 +6,17 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import {truncate, linkify} from './blogUtils';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import type {BlogMarkdownLoaderOptions} from './types';
|
|
10
|
+
import type {LoaderContext} from 'webpack';
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
17
|
+
const fileString = source;
|
|
21
18
|
const callback = this.async();
|
|
22
|
-
const markdownLoaderOptions = this.getOptions()
|
|
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
|
-
? !!
|
|
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
|
|
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
|
-
admonitions:
|
|
21
|
-
truncateMarker: /<!--\s*
|
|
27
|
+
admonitions: true,
|
|
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: ['
|
|
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
|
-
|
|
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
|
-
|
|
48
|
-
|
|
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
|
-
|
|
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
|
+
}
|