@docusaurus/plugin-content-blog 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17
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 +20 -0
- package/lib/authors.js +110 -0
- package/lib/blogFrontMatter.d.ts +1 -21
- package/lib/blogFrontMatter.js +31 -19
- package/lib/blogUtils.d.ts +24 -6
- package/lib/blogUtils.js +196 -143
- package/lib/feed.d.ts +15 -0
- package/lib/feed.js +99 -0
- package/lib/index.d.ts +4 -3
- package/lib/index.js +149 -163
- package/lib/markdownLoader.d.ts +3 -6
- package/lib/markdownLoader.js +5 -6
- package/lib/pluginOptionSchema.d.ts +3 -26
- package/lib/pluginOptionSchema.js +35 -10
- package/lib/translations.d.ts +11 -0
- package/lib/translations.js +53 -0
- package/lib/types.d.ts +10 -46
- package/package.json +21 -18
- package/src/authors.ts +153 -0
- package/src/blogFrontMatter.ts +44 -51
- package/src/blogUtils.ts +289 -195
- package/{types.d.ts → src/deps.d.ts} +0 -0
- package/src/feed.ts +170 -0
- package/src/index.ts +197 -194
- package/src/markdownLoader.ts +10 -15
- package/src/plugin-content-blog.d.ts +270 -0
- package/src/pluginOptionSchema.ts +41 -13
- package/src/translations.ts +64 -0
- package/src/types.ts +19 -53
- package/index.d.ts +0 -138
- package/lib/.tsbuildinfo +0 -1
- 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 -76
- 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 -317
- 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/tsconfig.json +0 -9
package/lib/authors.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
import type { BlogContentPaths } from './types';
|
|
8
|
+
import type { Author, BlogPostFrontMatter } from '@docusaurus/plugin-content-blog';
|
|
9
|
+
export declare type AuthorsMap = Record<string, Author>;
|
|
10
|
+
export declare function validateAuthorsMap(content: unknown): AuthorsMap;
|
|
11
|
+
export declare function getAuthorsMap(params: {
|
|
12
|
+
authorsMapPath: string;
|
|
13
|
+
contentPaths: BlogContentPaths;
|
|
14
|
+
}): Promise<AuthorsMap | undefined>;
|
|
15
|
+
declare type AuthorsParam = {
|
|
16
|
+
frontMatter: BlogPostFrontMatter;
|
|
17
|
+
authorsMap: AuthorsMap | undefined;
|
|
18
|
+
};
|
|
19
|
+
export declare function getBlogPostAuthors(params: AuthorsParam): Author[];
|
|
20
|
+
export {};
|
package/lib/authors.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getBlogPostAuthors = exports.getAuthorsMap = exports.validateAuthorsMap = void 0;
|
|
10
|
+
const utils_1 = require("@docusaurus/utils");
|
|
11
|
+
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
12
|
+
const AuthorsMapSchema = utils_validation_1.Joi.object().pattern(utils_validation_1.Joi.string(), utils_validation_1.Joi.object({
|
|
13
|
+
name: utils_validation_1.Joi.string(),
|
|
14
|
+
url: utils_validation_1.URISchema,
|
|
15
|
+
imageURL: utils_validation_1.URISchema,
|
|
16
|
+
title: utils_validation_1.Joi.string(),
|
|
17
|
+
email: utils_validation_1.Joi.string(),
|
|
18
|
+
})
|
|
19
|
+
.rename('image_url', 'imageURL')
|
|
20
|
+
.or('name', 'imageURL')
|
|
21
|
+
.unknown()
|
|
22
|
+
.required());
|
|
23
|
+
function validateAuthorsMap(content) {
|
|
24
|
+
return utils_validation_1.Joi.attempt(content, AuthorsMapSchema);
|
|
25
|
+
}
|
|
26
|
+
exports.validateAuthorsMap = validateAuthorsMap;
|
|
27
|
+
async function getAuthorsMap(params) {
|
|
28
|
+
return (0, utils_1.getDataFileData)({
|
|
29
|
+
filePath: params.authorsMapPath,
|
|
30
|
+
contentPaths: params.contentPaths,
|
|
31
|
+
fileType: 'authors map',
|
|
32
|
+
}, validateAuthorsMap);
|
|
33
|
+
}
|
|
34
|
+
exports.getAuthorsMap = getAuthorsMap;
|
|
35
|
+
// Legacy v1/early-v2 front matter fields
|
|
36
|
+
// We may want to deprecate those in favor of using only frontMatter.authors
|
|
37
|
+
function getFrontMatterAuthorLegacy(frontMatter) {
|
|
38
|
+
const name = frontMatter.author;
|
|
39
|
+
const title = frontMatter.author_title ?? frontMatter.authorTitle;
|
|
40
|
+
const url = frontMatter.author_url ?? frontMatter.authorURL;
|
|
41
|
+
const imageURL = frontMatter.author_image_url ?? frontMatter.authorImageURL;
|
|
42
|
+
if (name || title || url || imageURL) {
|
|
43
|
+
return {
|
|
44
|
+
name,
|
|
45
|
+
title,
|
|
46
|
+
url,
|
|
47
|
+
imageURL,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
function normalizeFrontMatterAuthors(frontMatterAuthors = []) {
|
|
53
|
+
function normalizeAuthor(authorInput) {
|
|
54
|
+
if (typeof authorInput === 'string') {
|
|
55
|
+
// Technically, we could allow users to provide an author's name here, but
|
|
56
|
+
// we only support keys, otherwise, a typo in a key would fallback to
|
|
57
|
+
// becoming a name and may end up unnoticed
|
|
58
|
+
return { key: authorInput };
|
|
59
|
+
}
|
|
60
|
+
return authorInput;
|
|
61
|
+
}
|
|
62
|
+
return Array.isArray(frontMatterAuthors)
|
|
63
|
+
? frontMatterAuthors.map(normalizeAuthor)
|
|
64
|
+
: [normalizeAuthor(frontMatterAuthors)];
|
|
65
|
+
}
|
|
66
|
+
function getFrontMatterAuthors(params) {
|
|
67
|
+
const { authorsMap } = params;
|
|
68
|
+
const frontMatterAuthors = normalizeFrontMatterAuthors(params.frontMatter.authors);
|
|
69
|
+
function getAuthorsMapAuthor(key) {
|
|
70
|
+
if (key) {
|
|
71
|
+
if (!authorsMap || Object.keys(authorsMap).length === 0) {
|
|
72
|
+
throw new Error(`Can't reference blog post authors by a key (such as '${key}') because no authors map file could be loaded.
|
|
73
|
+
Please double-check your blog plugin config (in particular 'authorsMapPath'), ensure the file exists at the configured path, is not empty, and is valid!`);
|
|
74
|
+
}
|
|
75
|
+
const author = authorsMap[key];
|
|
76
|
+
if (!author) {
|
|
77
|
+
throw Error(`Blog author with key "${key}" not found in the authors map file.
|
|
78
|
+
Valid author keys are:
|
|
79
|
+
${Object.keys(authorsMap)
|
|
80
|
+
.map((validKey) => `- ${validKey}`)
|
|
81
|
+
.join('\n')}`);
|
|
82
|
+
}
|
|
83
|
+
return author;
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
function toAuthor(frontMatterAuthor) {
|
|
88
|
+
return {
|
|
89
|
+
// Author def from authorsMap can be locally overridden by front matter
|
|
90
|
+
...getAuthorsMapAuthor(frontMatterAuthor.key),
|
|
91
|
+
...frontMatterAuthor,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return frontMatterAuthors.map(toAuthor);
|
|
95
|
+
}
|
|
96
|
+
function getBlogPostAuthors(params) {
|
|
97
|
+
const authorLegacy = getFrontMatterAuthorLegacy(params.frontMatter);
|
|
98
|
+
const authors = getFrontMatterAuthors(params);
|
|
99
|
+
if (authorLegacy) {
|
|
100
|
+
// Technically, we could allow mixing legacy/authors front matter, but do we
|
|
101
|
+
// really want to?
|
|
102
|
+
if (authors.length > 0) {
|
|
103
|
+
throw new Error(`To declare blog post authors, use the 'authors' front matter in priority.
|
|
104
|
+
Don't mix 'authors' with other existing 'author_*' front matter. Choose one or the other, not both at the same time.`);
|
|
105
|
+
}
|
|
106
|
+
return [authorLegacy];
|
|
107
|
+
}
|
|
108
|
+
return authors;
|
|
109
|
+
}
|
|
110
|
+
exports.getBlogPostAuthors = getBlogPostAuthors;
|
package/lib/blogFrontMatter.d.ts
CHANGED
|
@@ -4,25 +4,5 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
export declare type BlogPostFrontMatter = {
|
|
9
|
-
id?: string;
|
|
10
|
-
title?: string;
|
|
11
|
-
description?: string;
|
|
12
|
-
tags?: (string | Tag)[];
|
|
13
|
-
slug?: string;
|
|
14
|
-
draft?: boolean;
|
|
15
|
-
date?: Date;
|
|
16
|
-
author?: string;
|
|
17
|
-
author_title?: string;
|
|
18
|
-
author_url?: string;
|
|
19
|
-
author_image_url?: string;
|
|
20
|
-
image?: string;
|
|
21
|
-
keywords?: string[];
|
|
22
|
-
hide_table_of_contents?: boolean;
|
|
23
|
-
/** @deprecated */
|
|
24
|
-
authorTitle?: string;
|
|
25
|
-
authorURL?: string;
|
|
26
|
-
authorImageURL?: string;
|
|
27
|
-
};
|
|
7
|
+
import type { BlogPostFrontMatter } from '@docusaurus/plugin-content-blog';
|
|
28
8
|
export declare function validateBlogPostFrontMatter(frontMatter: Record<string, unknown>): BlogPostFrontMatter;
|
package/lib/blogFrontMatter.js
CHANGED
|
@@ -7,44 +7,56 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.validateBlogPostFrontMatter = void 0;
|
|
10
|
-
/* eslint-disable camelcase */
|
|
11
10
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
const BlogPostFrontMatterAuthorSchema = utils_validation_1.JoiFrontMatter.object({
|
|
12
|
+
key: utils_validation_1.JoiFrontMatter.string(),
|
|
13
|
+
name: utils_validation_1.JoiFrontMatter.string(),
|
|
14
|
+
title: utils_validation_1.JoiFrontMatter.string(),
|
|
15
|
+
url: utils_validation_1.URISchema,
|
|
16
|
+
imageURL: utils_validation_1.JoiFrontMatter.string(),
|
|
17
|
+
})
|
|
18
|
+
.or('key', 'name', 'imageURL')
|
|
19
|
+
.rename('image_url', 'imageURL', { alias: true });
|
|
20
|
+
const FrontMatterAuthorErrorMessage = '{{#label}} does not look like a valid blog post author. Please use an author key or an author object (with a key and/or name).';
|
|
20
21
|
const BlogFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
21
22
|
id: utils_validation_1.JoiFrontMatter.string(),
|
|
22
23
|
title: utils_validation_1.JoiFrontMatter.string().allow(''),
|
|
23
24
|
description: utils_validation_1.JoiFrontMatter.string().allow(''),
|
|
24
|
-
tags: utils_validation_1.
|
|
25
|
+
tags: utils_validation_1.FrontMatterTagsSchema,
|
|
25
26
|
draft: utils_validation_1.JoiFrontMatter.boolean(),
|
|
26
27
|
date: utils_validation_1.JoiFrontMatter.date().raw(),
|
|
28
|
+
// New multi-authors front matter:
|
|
29
|
+
authors: utils_validation_1.JoiFrontMatter.alternatives()
|
|
30
|
+
.try(utils_validation_1.JoiFrontMatter.string(), BlogPostFrontMatterAuthorSchema, utils_validation_1.JoiFrontMatter.array()
|
|
31
|
+
.items(utils_validation_1.JoiFrontMatter.string(), BlogPostFrontMatterAuthorSchema)
|
|
32
|
+
.messages({
|
|
33
|
+
'array.sparse': FrontMatterAuthorErrorMessage,
|
|
34
|
+
'array.includes': FrontMatterAuthorErrorMessage,
|
|
35
|
+
}))
|
|
36
|
+
.messages({
|
|
37
|
+
'alternatives.match': FrontMatterAuthorErrorMessage,
|
|
38
|
+
}),
|
|
39
|
+
// Legacy author front matter
|
|
27
40
|
author: utils_validation_1.JoiFrontMatter.string(),
|
|
28
41
|
author_title: utils_validation_1.JoiFrontMatter.string(),
|
|
29
42
|
author_url: utils_validation_1.URISchema,
|
|
30
43
|
author_image_url: utils_validation_1.URISchema,
|
|
31
|
-
|
|
32
|
-
image: utils_validation_1.URISchema,
|
|
33
|
-
keywords: utils_validation_1.JoiFrontMatter.array().items(utils_validation_1.JoiFrontMatter.string().required()),
|
|
34
|
-
hide_table_of_contents: utils_validation_1.JoiFrontMatter.boolean(),
|
|
35
|
-
// TODO re-enable warnings later, our v1 blog posts use those older frontmatter fields
|
|
44
|
+
// TODO enable deprecation warnings later
|
|
36
45
|
authorURL: utils_validation_1.URISchema,
|
|
37
46
|
// .warning('deprecate.error', { alternative: '"author_url"'}),
|
|
38
47
|
authorTitle: utils_validation_1.JoiFrontMatter.string(),
|
|
39
48
|
// .warning('deprecate.error', { alternative: '"author_title"'}),
|
|
40
49
|
authorImageURL: utils_validation_1.URISchema,
|
|
41
50
|
// .warning('deprecate.error', { alternative: '"author_image_url"'}),
|
|
42
|
-
|
|
43
|
-
.
|
|
44
|
-
.
|
|
51
|
+
slug: utils_validation_1.JoiFrontMatter.string(),
|
|
52
|
+
image: utils_validation_1.URISchema,
|
|
53
|
+
keywords: utils_validation_1.JoiFrontMatter.array().items(utils_validation_1.JoiFrontMatter.string().required()),
|
|
54
|
+
hide_table_of_contents: utils_validation_1.JoiFrontMatter.boolean(),
|
|
55
|
+
...utils_validation_1.FrontMatterTOCHeadingLevels,
|
|
56
|
+
}).messages({
|
|
45
57
|
'deprecate.error': '{#label} blog frontMatter field is deprecated. Please use {#alternative} instead.',
|
|
46
58
|
});
|
|
47
59
|
function validateBlogPostFrontMatter(frontMatter) {
|
|
48
|
-
return utils_validation_1.validateFrontMatter(frontMatter, BlogFrontMatterSchema);
|
|
60
|
+
return (0, utils_validation_1.validateFrontMatter)(frontMatter, BlogFrontMatterSchema);
|
|
49
61
|
}
|
|
50
62
|
exports.validateBlogPostFrontMatter = validateBlogPostFrontMatter;
|
package/lib/blogUtils.d.ts
CHANGED
|
@@ -4,16 +4,34 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import type { BlogPost, BlogContentPaths, BlogMarkdownLoaderOptions, BlogTags, BlogPaginated } from './types';
|
|
8
|
+
import type { LoadContext } from '@docusaurus/types';
|
|
9
|
+
import type { PluginOptions } from '@docusaurus/plugin-content-blog';
|
|
10
10
|
export declare function truncate(fileString: string, truncateMarker: RegExp): string;
|
|
11
11
|
export declare function getSourceToPermalink(blogPosts: BlogPost[]): Record<string, string>;
|
|
12
|
-
export declare function
|
|
13
|
-
|
|
12
|
+
export declare function paginateBlogPosts({ blogPosts, basePageUrl, blogTitle, blogDescription, postsPerPageOption, }: {
|
|
13
|
+
blogPosts: BlogPost[];
|
|
14
|
+
basePageUrl: string;
|
|
15
|
+
blogTitle: string;
|
|
16
|
+
blogDescription: string;
|
|
17
|
+
postsPerPageOption: number | 'ALL';
|
|
18
|
+
}): BlogPaginated[];
|
|
19
|
+
export declare function getBlogTags({ blogPosts, ...params }: {
|
|
20
|
+
blogPosts: BlogPost[];
|
|
21
|
+
blogTitle: string;
|
|
22
|
+
blogDescription: string;
|
|
23
|
+
postsPerPageOption: number | 'ALL';
|
|
24
|
+
}): BlogTags;
|
|
25
|
+
declare type ParsedBlogFileName = {
|
|
26
|
+
date: Date | undefined;
|
|
27
|
+
text: string;
|
|
28
|
+
slug: string;
|
|
29
|
+
};
|
|
30
|
+
export declare function parseBlogFileName(blogSourceRelative: string): ParsedBlogFileName;
|
|
31
|
+
export declare function generateBlogPosts(contentPaths: BlogContentPaths, context: LoadContext, options: PluginOptions): Promise<BlogPost[]>;
|
|
14
32
|
export declare type LinkifyParams = {
|
|
15
33
|
filePath: string;
|
|
16
34
|
fileString: string;
|
|
17
35
|
} & Pick<BlogMarkdownLoaderOptions, 'sourceToPermalink' | 'siteDir' | 'contentPaths' | 'onBrokenMarkdownLink'>;
|
|
18
36
|
export declare function linkify({ filePath, contentPaths, fileString, siteDir, sourceToPermalink, onBrokenMarkdownLink, }: LinkifyParams): string;
|
|
19
|
-
export
|
|
37
|
+
export {};
|