@docusaurus/plugin-content-blog 0.0.0-6064 → 0.0.0-6067
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/contentHelpers.d.ts +12 -0
- package/lib/contentHelpers.js +30 -0
- package/lib/index.js +15 -31
- package/package.json +10 -10
- package/src/contentHelpers.ts +35 -0
- package/src/index.ts +19 -46
|
@@ -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);
|
|
@@ -95,18 +75,22 @@ async function pluginContentBlog(context, options) {
|
|
|
95
75
|
// For blog posts a title in markdown is always removed
|
|
96
76
|
// Blog posts title are rendered separately
|
|
97
77
|
removeContentTitle: true,
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
78
|
+
// createAssets converts relative paths to require() calls
|
|
79
|
+
createAssets: ({ filePath }) => {
|
|
80
|
+
const blogPost = contentHelpers.sourceToBlogPost.get((0, utils_1.aliasedSitePath)(filePath, siteDir));
|
|
81
|
+
if (!blogPost) {
|
|
82
|
+
throw new Error(`Blog post not found for filePath=${filePath}`);
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
image: blogPost.metadata.frontMatter.image,
|
|
86
|
+
authorsImageUrls: blogPost.metadata.authors.map((author) => author.imageURL),
|
|
87
|
+
};
|
|
88
|
+
},
|
|
105
89
|
markdownConfig: siteConfig.markdown,
|
|
106
90
|
resolveMarkdownLink: ({ linkPathname, sourceFilePath }) => {
|
|
107
91
|
const permalink = (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
|
|
108
92
|
sourceFilePath,
|
|
109
|
-
sourceToPermalink:
|
|
93
|
+
sourceToPermalink: contentHelpers.sourceToPermalink,
|
|
110
94
|
siteDir,
|
|
111
95
|
contentPaths,
|
|
112
96
|
});
|
|
@@ -235,7 +219,7 @@ async function pluginContentBlog(context, options) {
|
|
|
235
219
|
};
|
|
236
220
|
},
|
|
237
221
|
async contentLoaded({ content, actions }) {
|
|
238
|
-
|
|
222
|
+
contentHelpers.updateContent(content);
|
|
239
223
|
await (0, routes_1.createAllRoutes)({
|
|
240
224
|
baseUrl,
|
|
241
225
|
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-6067",
|
|
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-6067",
|
|
35
|
+
"@docusaurus/logger": "0.0.0-6067",
|
|
36
|
+
"@docusaurus/mdx-loader": "0.0.0-6067",
|
|
37
|
+
"@docusaurus/theme-common": "0.0.0-6067",
|
|
38
|
+
"@docusaurus/types": "0.0.0-6067",
|
|
39
|
+
"@docusaurus/utils": "0.0.0-6067",
|
|
40
|
+
"@docusaurus/utils-common": "0.0.0-6067",
|
|
41
|
+
"@docusaurus/utils-validation": "0.0.0-6067",
|
|
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": "856911a5474e8e907f83438abe5c42d4793e06cb"
|
|
66
66
|
}
|
|
@@ -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,12 +39,11 @@ 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 {
|
|
46
46
|
PluginOptions,
|
|
47
|
-
BlogPostFrontMatter,
|
|
48
|
-
BlogPostMetadata,
|
|
49
47
|
Assets,
|
|
50
48
|
BlogTags,
|
|
51
49
|
BlogContent,
|
|
@@ -55,33 +53,6 @@ import type {RuleSetRule, RuleSetUseItem} from 'webpack';
|
|
|
55
53
|
|
|
56
54
|
const PluginName = 'docusaurus-plugin-content-blog';
|
|
57
55
|
|
|
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
56
|
export default async function pluginContentBlog(
|
|
86
57
|
context: LoadContext,
|
|
87
58
|
options: PluginOptions,
|
|
@@ -128,7 +99,7 @@ export default async function pluginContentBlog(
|
|
|
128
99
|
contentPaths,
|
|
129
100
|
});
|
|
130
101
|
|
|
131
|
-
const
|
|
102
|
+
const contentHelpers = createContentHelpers();
|
|
132
103
|
|
|
133
104
|
async function createBlogMDXLoaderRule(): Promise<RuleSetRule> {
|
|
134
105
|
const {
|
|
@@ -167,24 +138,26 @@ export default async function pluginContentBlog(
|
|
|
167
138
|
// For blog posts a title in markdown is always removed
|
|
168
139
|
// Blog posts title are rendered separately
|
|
169
140
|
removeContentTitle: true,
|
|
170
|
-
//
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
141
|
+
// createAssets converts relative paths to require() calls
|
|
142
|
+
createAssets: ({filePath}: {filePath: string}): Assets => {
|
|
143
|
+
const blogPost = contentHelpers.sourceToBlogPost.get(
|
|
144
|
+
aliasedSitePath(filePath, siteDir),
|
|
145
|
+
)!;
|
|
146
|
+
if (!blogPost) {
|
|
147
|
+
throw new Error(`Blog post not found for filePath=${filePath}`);
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
image: blogPost.metadata.frontMatter.image as string,
|
|
151
|
+
authorsImageUrls: blogPost.metadata.authors.map(
|
|
152
|
+
(author) => author.imageURL,
|
|
153
|
+
),
|
|
154
|
+
};
|
|
155
|
+
},
|
|
183
156
|
markdownConfig: siteConfig.markdown,
|
|
184
157
|
resolveMarkdownLink: ({linkPathname, sourceFilePath}) => {
|
|
185
158
|
const permalink = resolveMarkdownLinkPathname(linkPathname, {
|
|
186
159
|
sourceFilePath,
|
|
187
|
-
sourceToPermalink:
|
|
160
|
+
sourceToPermalink: contentHelpers.sourceToPermalink,
|
|
188
161
|
siteDir,
|
|
189
162
|
contentPaths,
|
|
190
163
|
});
|
|
@@ -352,7 +325,7 @@ export default async function pluginContentBlog(
|
|
|
352
325
|
},
|
|
353
326
|
|
|
354
327
|
async contentLoaded({content, actions}) {
|
|
355
|
-
|
|
328
|
+
contentHelpers.updateContent(content);
|
|
356
329
|
|
|
357
330
|
await createAllRoutes({
|
|
358
331
|
baseUrl,
|