@docusaurus/plugin-content-blog 2.0.0-beta.17 → 2.0.0-beta.18
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 +3 -1
- package/lib/authors.js +10 -2
- package/lib/blogUtils.d.ts +3 -1
- package/lib/blogUtils.js +9 -7
- package/lib/feed.d.ts +2 -1
- package/lib/feed.js +9 -8
- package/lib/{blogFrontMatter.d.ts → frontMatter.d.ts} +3 -1
- package/lib/{blogFrontMatter.js → frontMatter.js} +0 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +6 -14
- package/lib/markdownLoader.js +1 -1
- package/lib/options.d.ts +10 -0
- package/lib/{pluginOptionSchema.js → options.js} +8 -3
- package/lib/translations.js +4 -4
- package/lib/types.d.ts +7 -49
- package/package.json +10 -10
- package/src/authors.ts +29 -18
- package/src/blogUtils.ts +14 -12
- package/src/deps.d.ts +1 -1
- package/src/feed.ts +11 -6
- package/src/{blogFrontMatter.ts → frontMatter.ts} +3 -3
- package/src/index.ts +17 -34
- package/src/markdownLoader.ts +1 -1
- package/src/{pluginOptionSchema.ts → options.ts} +15 -3
- package/src/plugin-content-blog.d.ts +390 -69
- package/src/translations.ts +6 -4
- package/src/types.ts +5 -61
- package/lib/pluginOptionSchema.d.ts +0 -10
package/src/feed.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
mapAsyncSequential,
|
|
14
14
|
readOutputHTMLFile,
|
|
15
15
|
} from '@docusaurus/utils';
|
|
16
|
-
import
|
|
16
|
+
import {load as cheerioLoad} from 'cheerio';
|
|
17
17
|
import type {DocusaurusConfig} from '@docusaurus/types';
|
|
18
18
|
import path from 'path';
|
|
19
19
|
import fs from 'fs-extra';
|
|
@@ -29,11 +29,13 @@ async function generateBlogFeed({
|
|
|
29
29
|
options,
|
|
30
30
|
siteConfig,
|
|
31
31
|
outDir,
|
|
32
|
+
locale,
|
|
32
33
|
}: {
|
|
33
34
|
blogPosts: BlogPost[];
|
|
34
35
|
options: PluginOptions;
|
|
35
36
|
siteConfig: DocusaurusConfig;
|
|
36
37
|
outDir: string;
|
|
38
|
+
locale: string;
|
|
37
39
|
}): Promise<Feed | null> {
|
|
38
40
|
if (!blogPosts.length) {
|
|
39
41
|
return null;
|
|
@@ -43,15 +45,15 @@ async function generateBlogFeed({
|
|
|
43
45
|
const {url: siteUrl, baseUrl, title, favicon} = siteConfig;
|
|
44
46
|
const blogBaseUrl = normalizeUrl([siteUrl, baseUrl, routeBasePath]);
|
|
45
47
|
|
|
46
|
-
const updated = blogPosts[0]
|
|
48
|
+
const updated = blogPosts[0]?.metadata.date;
|
|
47
49
|
|
|
48
50
|
const feed = new Feed({
|
|
49
51
|
id: blogBaseUrl,
|
|
50
|
-
title: feedOptions.title
|
|
52
|
+
title: feedOptions.title ?? `${title} Blog`,
|
|
51
53
|
updated,
|
|
52
|
-
language: feedOptions.language,
|
|
54
|
+
language: feedOptions.language ?? locale,
|
|
53
55
|
link: blogBaseUrl,
|
|
54
|
-
description: feedOptions.description
|
|
56
|
+
description: feedOptions.description ?? `${siteConfig.title} Blog`,
|
|
55
57
|
favicon: favicon ? normalizeUrl([siteUrl, baseUrl, favicon]) : undefined,
|
|
56
58
|
copyright: feedOptions.copyright,
|
|
57
59
|
});
|
|
@@ -78,7 +80,7 @@ async function generateBlogFeed({
|
|
|
78
80
|
outDir,
|
|
79
81
|
siteConfig.trailingSlash,
|
|
80
82
|
);
|
|
81
|
-
const $ =
|
|
83
|
+
const $ = cheerioLoad(content);
|
|
82
84
|
|
|
83
85
|
const feedItem: FeedItem = {
|
|
84
86
|
title: metadataTitle,
|
|
@@ -140,17 +142,20 @@ export async function createBlogFeedFiles({
|
|
|
140
142
|
options,
|
|
141
143
|
siteConfig,
|
|
142
144
|
outDir,
|
|
145
|
+
locale,
|
|
143
146
|
}: {
|
|
144
147
|
blogPosts: BlogPost[];
|
|
145
148
|
options: PluginOptions;
|
|
146
149
|
siteConfig: DocusaurusConfig;
|
|
147
150
|
outDir: string;
|
|
151
|
+
locale: string;
|
|
148
152
|
}): Promise<void> {
|
|
149
153
|
const feed = await generateBlogFeed({
|
|
150
154
|
blogPosts,
|
|
151
155
|
options,
|
|
152
156
|
siteConfig,
|
|
153
157
|
outDir,
|
|
158
|
+
locale,
|
|
154
159
|
});
|
|
155
160
|
|
|
156
161
|
const feedTypes = options.feedOptions.type;
|
|
@@ -74,8 +74,8 @@ const BlogFrontMatterSchema = Joi.object<BlogPostFrontMatter>({
|
|
|
74
74
|
'{#label} blog frontMatter field is deprecated. Please use {#alternative} instead.',
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
-
export function validateBlogPostFrontMatter(
|
|
78
|
-
|
|
79
|
-
): BlogPostFrontMatter {
|
|
77
|
+
export function validateBlogPostFrontMatter(frontMatter: {
|
|
78
|
+
[key: string]: unknown;
|
|
79
|
+
}): BlogPostFrontMatter {
|
|
80
80
|
return validateFrontMatter(frontMatter, BlogFrontMatterSchema);
|
|
81
81
|
}
|
package/src/index.ts
CHANGED
|
@@ -26,22 +26,11 @@ import type {
|
|
|
26
26
|
BlogTag,
|
|
27
27
|
BlogTags,
|
|
28
28
|
BlogContent,
|
|
29
|
-
BlogItemsToMetadata,
|
|
30
|
-
TagsModule,
|
|
31
29
|
BlogPaginated,
|
|
32
30
|
BlogContentPaths,
|
|
33
31
|
BlogMarkdownLoaderOptions,
|
|
34
|
-
MetaData,
|
|
35
|
-
TagModule,
|
|
36
32
|
} from './types';
|
|
37
|
-
import {
|
|
38
|
-
import type {
|
|
39
|
-
LoadContext,
|
|
40
|
-
Plugin,
|
|
41
|
-
HtmlTags,
|
|
42
|
-
OptionValidationContext,
|
|
43
|
-
ValidationResult,
|
|
44
|
-
} from '@docusaurus/types';
|
|
33
|
+
import type {LoadContext, Plugin, HtmlTags} from '@docusaurus/types';
|
|
45
34
|
import {
|
|
46
35
|
generateBlogPosts,
|
|
47
36
|
getSourceToPermalink,
|
|
@@ -52,7 +41,9 @@ import {createBlogFeedFiles} from './feed';
|
|
|
52
41
|
import type {
|
|
53
42
|
PluginOptions,
|
|
54
43
|
BlogPostFrontMatter,
|
|
44
|
+
BlogPostMetadata,
|
|
55
45
|
Assets,
|
|
46
|
+
TagModule,
|
|
56
47
|
} from '@docusaurus/plugin-content-blog';
|
|
57
48
|
|
|
58
49
|
export default async function pluginContentBlog(
|
|
@@ -214,14 +205,14 @@ export default async function pluginContentBlog(
|
|
|
214
205
|
blogTagsListPath,
|
|
215
206
|
} = blogContents;
|
|
216
207
|
|
|
217
|
-
const blogItemsToMetadata:
|
|
208
|
+
const blogItemsToMetadata: {[postId: string]: BlogPostMetadata} = {};
|
|
218
209
|
|
|
219
210
|
const sidebarBlogPosts =
|
|
220
211
|
options.blogSidebarCount === 'ALL'
|
|
221
212
|
? blogPosts
|
|
222
213
|
: blogPosts.slice(0, options.blogSidebarCount);
|
|
223
214
|
|
|
224
|
-
if (archiveBasePath) {
|
|
215
|
+
if (archiveBasePath && blogPosts.length) {
|
|
225
216
|
const archiveUrl = normalizeUrl([
|
|
226
217
|
baseUrl,
|
|
227
218
|
routeBasePath,
|
|
@@ -307,7 +298,7 @@ export default async function pluginContentBlog(
|
|
|
307
298
|
({
|
|
308
299
|
content: {
|
|
309
300
|
__import: true,
|
|
310
|
-
path: blogItemsToMetadata[postID]
|
|
301
|
+
path: blogItemsToMetadata[postID]!.source,
|
|
311
302
|
query: {
|
|
312
303
|
truncated: true,
|
|
313
304
|
},
|
|
@@ -325,11 +316,10 @@ export default async function pluginContentBlog(
|
|
|
325
316
|
return;
|
|
326
317
|
}
|
|
327
318
|
|
|
328
|
-
const tagsModule:
|
|
329
|
-
Object.entries(blogTags).map(([
|
|
319
|
+
const tagsModule: {[tagName: string]: TagModule} = Object.fromEntries(
|
|
320
|
+
Object.entries(blogTags).map(([, tag]) => {
|
|
330
321
|
const tagModule: TagModule = {
|
|
331
322
|
allTagsPath: blogTagsListPath,
|
|
332
|
-
slug: tagKey,
|
|
333
323
|
name: tag.name,
|
|
334
324
|
count: tag.items.length,
|
|
335
325
|
permalink: tag.permalink,
|
|
@@ -359,7 +349,7 @@ export default async function pluginContentBlog(
|
|
|
359
349
|
modules: {
|
|
360
350
|
sidebar: aliasedSource(sidebarProp),
|
|
361
351
|
items: items.map((postID) => {
|
|
362
|
-
const blogPostMetadata = blogItemsToMetadata[postID]
|
|
352
|
+
const blogPostMetadata = blogItemsToMetadata[postID]!;
|
|
363
353
|
return {
|
|
364
354
|
content: {
|
|
365
355
|
__import: true,
|
|
@@ -479,7 +469,7 @@ export default async function pluginContentBlog(
|
|
|
479
469
|
metadata,
|
|
480
470
|
}: {
|
|
481
471
|
frontMatter: BlogPostFrontMatter;
|
|
482
|
-
metadata:
|
|
472
|
+
metadata: BlogPostMetadata;
|
|
483
473
|
}): Assets => ({
|
|
484
474
|
image: frontMatter.image,
|
|
485
475
|
authorsImageUrls: metadata.authors.map(
|
|
@@ -512,6 +502,7 @@ export default async function pluginContentBlog(
|
|
|
512
502
|
options,
|
|
513
503
|
outDir,
|
|
514
504
|
siteConfig,
|
|
505
|
+
locale: currentLocale,
|
|
515
506
|
});
|
|
516
507
|
},
|
|
517
508
|
|
|
@@ -546,13 +537,11 @@ export default async function pluginContentBlog(
|
|
|
546
537
|
const headTags: HtmlTags = [];
|
|
547
538
|
|
|
548
539
|
feedTypes.forEach((feedType) => {
|
|
549
|
-
const
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
const {type, path: feedConfigPath, title: feedConfigTitle} = feedConfig;
|
|
540
|
+
const {
|
|
541
|
+
type,
|
|
542
|
+
path: feedConfigPath,
|
|
543
|
+
title: feedConfigTitle,
|
|
544
|
+
} = feedsConfig[feedType];
|
|
556
545
|
|
|
557
546
|
headTags.push({
|
|
558
547
|
tagName: 'link',
|
|
@@ -576,10 +565,4 @@ export default async function pluginContentBlog(
|
|
|
576
565
|
};
|
|
577
566
|
}
|
|
578
567
|
|
|
579
|
-
export
|
|
580
|
-
validate,
|
|
581
|
-
options,
|
|
582
|
-
}: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions> {
|
|
583
|
-
const validatedOptions = validate(PluginOptionSchema, options);
|
|
584
|
-
return validatedOptions;
|
|
585
|
-
}
|
|
568
|
+
export {validateOptions} from './options';
|
package/src/markdownLoader.ts
CHANGED
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
URISchema,
|
|
14
14
|
} from '@docusaurus/utils-validation';
|
|
15
15
|
import {GlobExcludeDefault} from '@docusaurus/utils';
|
|
16
|
-
import type {PluginOptions} from '@docusaurus/plugin-content-blog';
|
|
16
|
+
import type {PluginOptions, Options} from '@docusaurus/plugin-content-blog';
|
|
17
|
+
import type {OptionValidationContext} from '@docusaurus/types';
|
|
17
18
|
|
|
18
19
|
export const DEFAULT_OPTIONS: PluginOptions = {
|
|
19
20
|
feedOptions: {type: ['rss', 'atom'], copyright: ''},
|
|
@@ -46,7 +47,7 @@ export const DEFAULT_OPTIONS: PluginOptions = {
|
|
|
46
47
|
sortPosts: 'descending',
|
|
47
48
|
};
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
const PluginOptionSchema = Joi.object<PluginOptions>({
|
|
50
51
|
path: Joi.string().default(DEFAULT_OPTIONS.path),
|
|
51
52
|
archiveBasePath: Joi.string()
|
|
52
53
|
.default(DEFAULT_OPTIONS.archiveBasePath)
|
|
@@ -125,4 +126,15 @@ export const PluginOptionSchema = Joi.object<PluginOptions>({
|
|
|
125
126
|
sortPosts: Joi.string()
|
|
126
127
|
.valid('descending', 'ascending')
|
|
127
128
|
.default(DEFAULT_OPTIONS.sortPosts),
|
|
128
|
-
});
|
|
129
|
+
}).default(DEFAULT_OPTIONS);
|
|
130
|
+
|
|
131
|
+
export function validateOptions({
|
|
132
|
+
validate,
|
|
133
|
+
options,
|
|
134
|
+
}: OptionValidationContext<Options, PluginOptions>): PluginOptions {
|
|
135
|
+
const validatedOptions = validate(
|
|
136
|
+
PluginOptionSchema,
|
|
137
|
+
options,
|
|
138
|
+
) as PluginOptions;
|
|
139
|
+
return validatedOptions;
|
|
140
|
+
}
|