@docusaurus/plugin-content-blog 0.0.0-6063 → 0.0.0-6065
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.js +5 -1
- package/lib/authorsSocials.js +4 -0
- package/lib/contentHelpers.d.ts +12 -0
- package/lib/contentHelpers.js +30 -0
- package/lib/index.js +10 -25
- package/package.json +10 -10
- package/src/authors.ts +5 -1
- package/src/authorsSocials.ts +6 -0
- package/src/contentHelpers.ts +35 -0
- package/src/index.ts +14 -32
package/lib/authors.js
CHANGED
|
@@ -12,6 +12,7 @@ exports.groupBlogPostsByAuthorKey = groupBlogPostsByAuthorKey;
|
|
|
12
12
|
const tslib_1 = require("tslib");
|
|
13
13
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
14
14
|
const utils_1 = require("@docusaurus/utils");
|
|
15
|
+
const authorsSocials_1 = require("./authorsSocials");
|
|
15
16
|
function normalizeImageUrl({ imageURL, baseUrl, }) {
|
|
16
17
|
return imageURL?.startsWith('/')
|
|
17
18
|
? (0, utils_1.normalizeUrl)([baseUrl, imageURL])
|
|
@@ -66,7 +67,10 @@ function getFrontMatterAuthors(params) {
|
|
|
66
67
|
// becoming a name and may end up unnoticed
|
|
67
68
|
return { key: authorInput };
|
|
68
69
|
}
|
|
69
|
-
return
|
|
70
|
+
return {
|
|
71
|
+
...authorInput,
|
|
72
|
+
socials: (0, authorsSocials_1.normalizeSocials)(authorInput.socials ?? {}),
|
|
73
|
+
};
|
|
70
74
|
}
|
|
71
75
|
return Array.isArray(frontMatter.authors)
|
|
72
76
|
? frontMatter.authors.map(normalizeAuthor)
|
package/lib/authorsSocials.js
CHANGED
|
@@ -27,6 +27,10 @@ const PredefinedPlatformNormalizers = {
|
|
|
27
27
|
};
|
|
28
28
|
function normalizeSocialEntry([platform, value]) {
|
|
29
29
|
const normalizer = PredefinedPlatformNormalizers[platform.toLowerCase()];
|
|
30
|
+
if (typeof value !== 'string') {
|
|
31
|
+
throw new Error(`Author socials should be usernames/userIds/handles, or fully qualified HTTP(s) absolute URLs.
|
|
32
|
+
Social platform '${platform}' has illegal value '${value}'`);
|
|
33
|
+
}
|
|
30
34
|
const isAbsoluteUrl = value.startsWith('http://') || value.startsWith('https://');
|
|
31
35
|
if (isAbsoluteUrl) {
|
|
32
36
|
return [platform, value];
|
|
@@ -0,0 +1,12 @@
|
|
|
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 { BlogContent, BlogPost } from '@docusaurus/plugin-content-blog';
|
|
8
|
+
export declare function createContentHelpers(): {
|
|
9
|
+
updateContent: (content: BlogContent) => void;
|
|
10
|
+
sourceToBlogPost: Map<string, BlogPost>;
|
|
11
|
+
sourceToPermalink: Map<string, string>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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.createContentHelpers = createContentHelpers;
|
|
10
|
+
function indexBlogPostsBySource(content) {
|
|
11
|
+
return new Map(content.blogPosts.map((blogPost) => [blogPost.metadata.source, blogPost]));
|
|
12
|
+
}
|
|
13
|
+
// TODO this is bad, we should have a better way to do this (new lifecycle?)
|
|
14
|
+
// The source to blog/permalink is a mutable map passed to the mdx loader
|
|
15
|
+
// See https://github.com/facebook/docusaurus/pull/10457
|
|
16
|
+
// See https://github.com/facebook/docusaurus/pull/10185
|
|
17
|
+
function createContentHelpers() {
|
|
18
|
+
const sourceToBlogPost = new Map();
|
|
19
|
+
const sourceToPermalink = new Map();
|
|
20
|
+
// Mutable map update :/
|
|
21
|
+
function updateContent(content) {
|
|
22
|
+
sourceToBlogPost.clear();
|
|
23
|
+
sourceToPermalink.clear();
|
|
24
|
+
indexBlogPostsBySource(content).forEach((value, key) => {
|
|
25
|
+
sourceToBlogPost.set(key, value);
|
|
26
|
+
sourceToPermalink.set(key, value.metadata.permalink);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return { updateContent, sourceToBlogPost, sourceToPermalink };
|
|
30
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -20,28 +20,8 @@ const translations_1 = require("./translations");
|
|
|
20
20
|
const feed_1 = require("./feed");
|
|
21
21
|
const routes_1 = require("./routes");
|
|
22
22
|
const authorsMap_1 = require("./authorsMap");
|
|
23
|
+
const contentHelpers_1 = require("./contentHelpers");
|
|
23
24
|
const PluginName = 'docusaurus-plugin-content-blog';
|
|
24
|
-
// TODO this is bad, we should have a better way to do this (new lifecycle?)
|
|
25
|
-
// The source to permalink is currently a mutable map passed to the mdx loader
|
|
26
|
-
// for link resolution
|
|
27
|
-
// see https://github.com/facebook/docusaurus/pull/10185
|
|
28
|
-
function createSourceToPermalinkHelper() {
|
|
29
|
-
const sourceToPermalink = new Map();
|
|
30
|
-
function computeSourceToPermalink(content) {
|
|
31
|
-
return new Map(content.blogPosts.map(({ metadata: { source, permalink } }) => [
|
|
32
|
-
source,
|
|
33
|
-
permalink,
|
|
34
|
-
]));
|
|
35
|
-
}
|
|
36
|
-
// Mutable map update :/
|
|
37
|
-
function update(content) {
|
|
38
|
-
sourceToPermalink.clear();
|
|
39
|
-
computeSourceToPermalink(content).forEach((value, key) => {
|
|
40
|
-
sourceToPermalink.set(key, value);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return { get: () => sourceToPermalink, update };
|
|
44
|
-
}
|
|
45
25
|
async function pluginContentBlog(context, options) {
|
|
46
26
|
const { siteDir, siteConfig, generatedFilesDir, localizationDir, i18n: { currentLocale }, } = context;
|
|
47
27
|
const router = siteConfig.future.experimental_router;
|
|
@@ -69,7 +49,7 @@ async function pluginContentBlog(context, options) {
|
|
|
69
49
|
filePath: options.authorsMapPath,
|
|
70
50
|
contentPaths,
|
|
71
51
|
});
|
|
72
|
-
const
|
|
52
|
+
const contentHelpers = (0, contentHelpers_1.createContentHelpers)();
|
|
73
53
|
async function createBlogMDXLoaderRule() {
|
|
74
54
|
const { admonitions, rehypePlugins, remarkPlugins, recmaPlugins, truncateMarker, beforeDefaultRemarkPlugins, beforeDefaultRehypePlugins, } = options;
|
|
75
55
|
const contentDirs = (0, utils_1.getContentPathList)(contentPaths);
|
|
@@ -90,7 +70,12 @@ async function pluginContentBlog(context, options) {
|
|
|
90
70
|
// Note that metadataPath must be the same/in-sync as
|
|
91
71
|
// the path from createData for each MDX.
|
|
92
72
|
const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
|
|
93
|
-
|
|
73
|
+
const metadataPath = path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
|
|
74
|
+
const metadataContent = contentHelpers.sourceToBlogPost.get(aliasedPath).metadata;
|
|
75
|
+
return {
|
|
76
|
+
metadataPath,
|
|
77
|
+
metadataContent,
|
|
78
|
+
};
|
|
94
79
|
},
|
|
95
80
|
// For blog posts a title in markdown is always removed
|
|
96
81
|
// Blog posts title are rendered separately
|
|
@@ -106,7 +91,7 @@ async function pluginContentBlog(context, options) {
|
|
|
106
91
|
resolveMarkdownLink: ({ linkPathname, sourceFilePath }) => {
|
|
107
92
|
const permalink = (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
|
|
108
93
|
sourceFilePath,
|
|
109
|
-
sourceToPermalink:
|
|
94
|
+
sourceToPermalink: contentHelpers.sourceToPermalink,
|
|
110
95
|
siteDir,
|
|
111
96
|
contentPaths,
|
|
112
97
|
});
|
|
@@ -235,7 +220,7 @@ async function pluginContentBlog(context, options) {
|
|
|
235
220
|
};
|
|
236
221
|
},
|
|
237
222
|
async contentLoaded({ content, actions }) {
|
|
238
|
-
|
|
223
|
+
contentHelpers.updateContent(content);
|
|
239
224
|
await (0, routes_1.createAllRoutes)({
|
|
240
225
|
baseUrl,
|
|
241
226
|
content,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-blog",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-6065",
|
|
4
4
|
"description": "Blog plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/plugin-content-blog.d.ts",
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
},
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@docusaurus/core": "0.0.0-
|
|
35
|
-
"@docusaurus/logger": "0.0.0-
|
|
36
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
37
|
-
"@docusaurus/theme-common": "0.0.0-
|
|
38
|
-
"@docusaurus/types": "0.0.0-
|
|
39
|
-
"@docusaurus/utils": "0.0.0-
|
|
40
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
41
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
34
|
+
"@docusaurus/core": "0.0.0-6065",
|
|
35
|
+
"@docusaurus/logger": "0.0.0-6065",
|
|
36
|
+
"@docusaurus/mdx-loader": "0.0.0-6065",
|
|
37
|
+
"@docusaurus/theme-common": "0.0.0-6065",
|
|
38
|
+
"@docusaurus/types": "0.0.0-6065",
|
|
39
|
+
"@docusaurus/utils": "0.0.0-6065",
|
|
40
|
+
"@docusaurus/utils-common": "0.0.0-6065",
|
|
41
|
+
"@docusaurus/utils-validation": "0.0.0-6065",
|
|
42
42
|
"cheerio": "1.0.0-rc.12",
|
|
43
43
|
"feed": "^4.2.2",
|
|
44
44
|
"fs-extra": "^11.1.1",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
63
63
|
"tree-node-cli": "^1.6.0"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "6da713a524315a36515fc3e998ff1551bfa054d2"
|
|
66
66
|
}
|
package/src/authors.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import _ from 'lodash';
|
|
9
9
|
import {normalizeUrl} from '@docusaurus/utils';
|
|
10
|
+
import {normalizeSocials} from './authorsSocials';
|
|
10
11
|
import type {
|
|
11
12
|
Author,
|
|
12
13
|
AuthorsMap,
|
|
@@ -107,7 +108,10 @@ function getFrontMatterAuthors(params: AuthorsParam): Author[] {
|
|
|
107
108
|
// becoming a name and may end up unnoticed
|
|
108
109
|
return {key: authorInput};
|
|
109
110
|
}
|
|
110
|
-
return
|
|
111
|
+
return {
|
|
112
|
+
...authorInput,
|
|
113
|
+
socials: normalizeSocials(authorInput.socials ?? {}),
|
|
114
|
+
};
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
return Array.isArray(frontMatter.authors)
|
package/src/authorsSocials.ts
CHANGED
|
@@ -41,6 +41,12 @@ type SocialEntry = [string, string];
|
|
|
41
41
|
|
|
42
42
|
function normalizeSocialEntry([platform, value]: SocialEntry): SocialEntry {
|
|
43
43
|
const normalizer = PredefinedPlatformNormalizers[platform.toLowerCase()];
|
|
44
|
+
if (typeof value !== 'string') {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Author socials should be usernames/userIds/handles, or fully qualified HTTP(s) absolute URLs.
|
|
47
|
+
Social platform '${platform}' has illegal value '${value}'`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
44
50
|
const isAbsoluteUrl =
|
|
45
51
|
value.startsWith('http://') || value.startsWith('https://');
|
|
46
52
|
if (isAbsoluteUrl) {
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
|
|
8
|
+
import type {BlogContent, BlogPost} from '@docusaurus/plugin-content-blog';
|
|
9
|
+
|
|
10
|
+
function indexBlogPostsBySource(content: BlogContent): Map<string, BlogPost> {
|
|
11
|
+
return new Map(
|
|
12
|
+
content.blogPosts.map((blogPost) => [blogPost.metadata.source, blogPost]),
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// TODO this is bad, we should have a better way to do this (new lifecycle?)
|
|
17
|
+
// The source to blog/permalink is a mutable map passed to the mdx loader
|
|
18
|
+
// See https://github.com/facebook/docusaurus/pull/10457
|
|
19
|
+
// See https://github.com/facebook/docusaurus/pull/10185
|
|
20
|
+
export function createContentHelpers() {
|
|
21
|
+
const sourceToBlogPost = new Map<string, BlogPost>();
|
|
22
|
+
const sourceToPermalink = new Map<string, string>();
|
|
23
|
+
|
|
24
|
+
// Mutable map update :/
|
|
25
|
+
function updateContent(content: BlogContent): void {
|
|
26
|
+
sourceToBlogPost.clear();
|
|
27
|
+
sourceToPermalink.clear();
|
|
28
|
+
indexBlogPostsBySource(content).forEach((value, key) => {
|
|
29
|
+
sourceToBlogPost.set(key, value);
|
|
30
|
+
sourceToPermalink.set(key, value.metadata.permalink);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {updateContent, sourceToBlogPost, sourceToPermalink};
|
|
35
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
getDataFilePath,
|
|
20
20
|
DEFAULT_PLUGIN_ID,
|
|
21
21
|
resolveMarkdownLinkPathname,
|
|
22
|
-
type SourceToPermalink,
|
|
23
22
|
} from '@docusaurus/utils';
|
|
24
23
|
import {getTagsFilePathsToWatch} from '@docusaurus/utils-validation';
|
|
25
24
|
import {
|
|
@@ -40,6 +39,7 @@ import {createBlogFeedFiles, createFeedHtmlHeadTags} from './feed';
|
|
|
40
39
|
|
|
41
40
|
import {createAllRoutes} from './routes';
|
|
42
41
|
import {checkAuthorsMapPermalinkCollisions, getAuthorsMap} from './authorsMap';
|
|
42
|
+
import {createContentHelpers} from './contentHelpers';
|
|
43
43
|
import type {BlogContentPaths, BlogMarkdownLoaderOptions} from './types';
|
|
44
44
|
import type {LoadContext, Plugin} from '@docusaurus/types';
|
|
45
45
|
import type {
|
|
@@ -55,33 +55,6 @@ import type {RuleSetRule, RuleSetUseItem} from 'webpack';
|
|
|
55
55
|
|
|
56
56
|
const PluginName = 'docusaurus-plugin-content-blog';
|
|
57
57
|
|
|
58
|
-
// TODO this is bad, we should have a better way to do this (new lifecycle?)
|
|
59
|
-
// The source to permalink is currently a mutable map passed to the mdx loader
|
|
60
|
-
// for link resolution
|
|
61
|
-
// see https://github.com/facebook/docusaurus/pull/10185
|
|
62
|
-
function createSourceToPermalinkHelper() {
|
|
63
|
-
const sourceToPermalink: SourceToPermalink = new Map();
|
|
64
|
-
|
|
65
|
-
function computeSourceToPermalink(content: BlogContent): SourceToPermalink {
|
|
66
|
-
return new Map(
|
|
67
|
-
content.blogPosts.map(({metadata: {source, permalink}}) => [
|
|
68
|
-
source,
|
|
69
|
-
permalink,
|
|
70
|
-
]),
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Mutable map update :/
|
|
75
|
-
function update(content: BlogContent): void {
|
|
76
|
-
sourceToPermalink.clear();
|
|
77
|
-
computeSourceToPermalink(content).forEach((value, key) => {
|
|
78
|
-
sourceToPermalink.set(key, value);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return {get: () => sourceToPermalink, update};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
58
|
export default async function pluginContentBlog(
|
|
86
59
|
context: LoadContext,
|
|
87
60
|
options: PluginOptions,
|
|
@@ -128,7 +101,7 @@ export default async function pluginContentBlog(
|
|
|
128
101
|
contentPaths,
|
|
129
102
|
});
|
|
130
103
|
|
|
131
|
-
const
|
|
104
|
+
const contentHelpers = createContentHelpers();
|
|
132
105
|
|
|
133
106
|
async function createBlogMDXLoaderRule(): Promise<RuleSetRule> {
|
|
134
107
|
const {
|
|
@@ -162,7 +135,16 @@ export default async function pluginContentBlog(
|
|
|
162
135
|
// Note that metadataPath must be the same/in-sync as
|
|
163
136
|
// the path from createData for each MDX.
|
|
164
137
|
const aliasedPath = aliasedSitePath(mdxPath, siteDir);
|
|
165
|
-
|
|
138
|
+
const metadataPath = path.join(
|
|
139
|
+
dataDir,
|
|
140
|
+
`${docuHash(aliasedPath)}.json`,
|
|
141
|
+
);
|
|
142
|
+
const metadataContent =
|
|
143
|
+
contentHelpers.sourceToBlogPost.get(aliasedPath)!.metadata;
|
|
144
|
+
return {
|
|
145
|
+
metadataPath,
|
|
146
|
+
metadataContent,
|
|
147
|
+
};
|
|
166
148
|
},
|
|
167
149
|
// For blog posts a title in markdown is always removed
|
|
168
150
|
// Blog posts title are rendered separately
|
|
@@ -184,7 +166,7 @@ export default async function pluginContentBlog(
|
|
|
184
166
|
resolveMarkdownLink: ({linkPathname, sourceFilePath}) => {
|
|
185
167
|
const permalink = resolveMarkdownLinkPathname(linkPathname, {
|
|
186
168
|
sourceFilePath,
|
|
187
|
-
sourceToPermalink:
|
|
169
|
+
sourceToPermalink: contentHelpers.sourceToPermalink,
|
|
188
170
|
siteDir,
|
|
189
171
|
contentPaths,
|
|
190
172
|
});
|
|
@@ -352,7 +334,7 @@ export default async function pluginContentBlog(
|
|
|
352
334
|
},
|
|
353
335
|
|
|
354
336
|
async contentLoaded({content, actions}) {
|
|
355
|
-
|
|
337
|
+
contentHelpers.updateContent(content);
|
|
356
338
|
|
|
357
339
|
await createAllRoutes({
|
|
358
340
|
baseUrl,
|