@docusaurus/plugin-content-blog 0.0.0-5962 → 0.0.0-5963

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.
@@ -9,9 +9,6 @@ import type { LoadContext } from '@docusaurus/types';
9
9
  import type { PluginOptions, BlogPost, BlogTags, BlogPaginated } from '@docusaurus/plugin-content-blog';
10
10
  import type { BlogContentPaths } from './types';
11
11
  export declare function truncate(fileString: string, truncateMarker: RegExp): string;
12
- export declare function getSourceToPermalink(blogPosts: BlogPost[]): {
13
- [aliasedPath: string]: string;
14
- };
15
12
  export declare function paginateBlogPosts({ blogPosts, basePageUrl, blogTitle, blogDescription, postsPerPageOption, pageBasePath, }: {
16
13
  blogPosts: BlogPost[];
17
14
  basePageUrl: string;
package/lib/blogUtils.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.applyProcessBlogPosts = exports.generateBlogPosts = exports.parseBlogFileName = exports.getBlogTags = exports.shouldBeListed = exports.paginateBlogPosts = exports.getSourceToPermalink = exports.truncate = void 0;
9
+ exports.applyProcessBlogPosts = exports.generateBlogPosts = exports.parseBlogFileName = exports.getBlogTags = exports.shouldBeListed = exports.paginateBlogPosts = exports.truncate = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
12
  const path_1 = tslib_1.__importDefault(require("path"));
@@ -21,10 +21,6 @@ function truncate(fileString, truncateMarker) {
21
21
  return fileString.split(truncateMarker, 1).shift();
22
22
  }
23
23
  exports.truncate = truncate;
24
- function getSourceToPermalink(blogPosts) {
25
- return Object.fromEntries(blogPosts.map(({ metadata: { source, permalink } }) => [source, permalink]));
26
- }
27
- exports.getSourceToPermalink = getSourceToPermalink;
28
24
  function paginateBlogPosts({ blogPosts, basePageUrl, blogTitle, blogDescription, postsPerPageOption, pageBasePath, }) {
29
25
  const totalCount = blogPosts.length;
30
26
  const postsPerPage = postsPerPageOption === 'ALL' ? totalCount : postsPerPageOption;
package/lib/index.js CHANGED
@@ -18,6 +18,27 @@ const translations_1 = require("./translations");
18
18
  const feed_1 = require("./feed");
19
19
  const routes_1 = require("./routes");
20
20
  const PluginName = 'docusaurus-plugin-content-blog';
21
+ // TODO this is bad, we should have a better way to do this (new lifecycle?)
22
+ // The source to permalink is currently a mutable map passed to the mdx loader
23
+ // for link resolution
24
+ // see https://github.com/facebook/docusaurus/pull/10185
25
+ function createSourceToPermalinkHelper() {
26
+ const sourceToPermalink = new Map();
27
+ function computeSourceToPermalink(content) {
28
+ return new Map(content.blogPosts.map(({ metadata: { source, permalink } }) => [
29
+ source,
30
+ permalink,
31
+ ]));
32
+ }
33
+ // Mutable map update :/
34
+ function update(content) {
35
+ sourceToPermalink.clear();
36
+ computeSourceToPermalink(content).forEach((value, key) => {
37
+ sourceToPermalink.set(key, value);
38
+ });
39
+ }
40
+ return { get: () => sourceToPermalink, update };
41
+ }
21
42
  async function pluginContentBlog(context, options) {
22
43
  const { siteDir, siteConfig, generatedFilesDir, localizationDir, i18n: { currentLocale }, } = context;
23
44
  const router = siteConfig.future.experimental_router;
@@ -45,6 +66,7 @@ async function pluginContentBlog(context, options) {
45
66
  filePath: options.authorsMapPath,
46
67
  contentPaths,
47
68
  });
69
+ const sourceToPermalinkHelper = createSourceToPermalinkHelper();
48
70
  return {
49
71
  name: PluginName,
50
72
  getPathsToWatch() {
@@ -126,6 +148,7 @@ async function pluginContentBlog(context, options) {
126
148
  };
127
149
  },
128
150
  async contentLoaded({ content, actions }) {
151
+ sourceToPermalinkHelper.update(content);
129
152
  await (0, routes_1.createAllRoutes)({
130
153
  baseUrl,
131
154
  content,
@@ -137,9 +160,8 @@ async function pluginContentBlog(context, options) {
137
160
  translateContent({ content, translationFiles }) {
138
161
  return (0, translations_1.translateContent)(content, translationFiles);
139
162
  },
140
- configureWebpack(_config, isServer, utils, content) {
163
+ configureWebpack() {
141
164
  const { admonitions, rehypePlugins, remarkPlugins, truncateMarker, beforeDefaultRemarkPlugins, beforeDefaultRehypePlugins, } = options;
142
- const sourceToPermalink = (0, blogUtils_1.getSourceToPermalink)(content.blogPosts);
143
165
  const contentDirs = (0, utils_1.getContentPathList)(contentPaths);
144
166
  function createMDXLoader() {
145
167
  const loaderOptions = {
@@ -174,7 +196,7 @@ async function pluginContentBlog(context, options) {
174
196
  resolveMarkdownLink: ({ linkPathname, sourceFilePath }) => {
175
197
  const permalink = (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
176
198
  sourceFilePath,
177
- sourceToPermalink,
199
+ sourceToPermalink: sourceToPermalinkHelper.get(),
178
200
  siteDir,
179
201
  contentPaths,
180
202
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-blog",
3
- "version": "0.0.0-5962",
3
+ "version": "0.0.0-5963",
4
4
  "description": "Blog plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/plugin-content-blog.d.ts",
@@ -31,13 +31,13 @@
31
31
  },
32
32
  "license": "MIT",
33
33
  "dependencies": {
34
- "@docusaurus/core": "0.0.0-5962",
35
- "@docusaurus/logger": "0.0.0-5962",
36
- "@docusaurus/mdx-loader": "0.0.0-5962",
37
- "@docusaurus/types": "0.0.0-5962",
38
- "@docusaurus/utils": "0.0.0-5962",
39
- "@docusaurus/utils-common": "0.0.0-5962",
40
- "@docusaurus/utils-validation": "0.0.0-5962",
34
+ "@docusaurus/core": "0.0.0-5963",
35
+ "@docusaurus/logger": "0.0.0-5963",
36
+ "@docusaurus/mdx-loader": "0.0.0-5963",
37
+ "@docusaurus/types": "0.0.0-5963",
38
+ "@docusaurus/utils": "0.0.0-5963",
39
+ "@docusaurus/utils-common": "0.0.0-5963",
40
+ "@docusaurus/utils-validation": "0.0.0-5963",
41
41
  "cheerio": "^1.0.0-rc.12",
42
42
  "feed": "^4.2.2",
43
43
  "fs-extra": "^11.1.1",
@@ -59,5 +59,5 @@
59
59
  "devDependencies": {
60
60
  "@total-typescript/shoehorn": "^0.1.2"
61
61
  },
62
- "gitHead": "35386a1d384d8e8757ef9f993b84dd5accc00e97"
62
+ "gitHead": "e9090dc8a38a21043b0849887aa7d54d04c4af9f"
63
63
  }
package/src/blogUtils.ts CHANGED
@@ -45,14 +45,6 @@ export function truncate(fileString: string, truncateMarker: RegExp): string {
45
45
  return fileString.split(truncateMarker, 1).shift()!;
46
46
  }
47
47
 
48
- export function getSourceToPermalink(blogPosts: BlogPost[]): {
49
- [aliasedPath: string]: string;
50
- } {
51
- return Object.fromEntries(
52
- blogPosts.map(({metadata: {source, permalink}}) => [source, permalink]),
53
- );
54
- }
55
-
56
48
  export function paginateBlogPosts({
57
49
  blogPosts,
58
50
  basePageUrl,
package/src/index.ts CHANGED
@@ -19,10 +19,10 @@ import {
19
19
  getDataFilePath,
20
20
  DEFAULT_PLUGIN_ID,
21
21
  resolveMarkdownLinkPathname,
22
+ type SourceToPermalink,
22
23
  } from '@docusaurus/utils';
23
24
  import {getTagsFilePathsToWatch} from '@docusaurus/utils-validation';
24
25
  import {
25
- getSourceToPermalink,
26
26
  getBlogTags,
27
27
  paginateBlogPosts,
28
28
  shouldBeListed,
@@ -50,6 +50,33 @@ import type {RuleSetUseItem} from 'webpack';
50
50
 
51
51
  const PluginName = 'docusaurus-plugin-content-blog';
52
52
 
53
+ // TODO this is bad, we should have a better way to do this (new lifecycle?)
54
+ // The source to permalink is currently a mutable map passed to the mdx loader
55
+ // for link resolution
56
+ // see https://github.com/facebook/docusaurus/pull/10185
57
+ function createSourceToPermalinkHelper() {
58
+ const sourceToPermalink: SourceToPermalink = new Map();
59
+
60
+ function computeSourceToPermalink(content: BlogContent): SourceToPermalink {
61
+ return new Map(
62
+ content.blogPosts.map(({metadata: {source, permalink}}) => [
63
+ source,
64
+ permalink,
65
+ ]),
66
+ );
67
+ }
68
+
69
+ // Mutable map update :/
70
+ function update(content: BlogContent): void {
71
+ sourceToPermalink.clear();
72
+ computeSourceToPermalink(content).forEach((value, key) => {
73
+ sourceToPermalink.set(key, value);
74
+ });
75
+ }
76
+
77
+ return {get: () => sourceToPermalink, update};
78
+ }
79
+
53
80
  export default async function pluginContentBlog(
54
81
  context: LoadContext,
55
82
  options: PluginOptions,
@@ -96,6 +123,8 @@ export default async function pluginContentBlog(
96
123
  contentPaths,
97
124
  });
98
125
 
126
+ const sourceToPermalinkHelper = createSourceToPermalinkHelper();
127
+
99
128
  return {
100
129
  name: PluginName,
101
130
 
@@ -201,6 +230,8 @@ export default async function pluginContentBlog(
201
230
  },
202
231
 
203
232
  async contentLoaded({content, actions}) {
233
+ sourceToPermalinkHelper.update(content);
234
+
204
235
  await createAllRoutes({
205
236
  baseUrl,
206
237
  content,
@@ -214,7 +245,7 @@ export default async function pluginContentBlog(
214
245
  return translateContent(content, translationFiles);
215
246
  },
216
247
 
217
- configureWebpack(_config, isServer, utils, content) {
248
+ configureWebpack() {
218
249
  const {
219
250
  admonitions,
220
251
  rehypePlugins,
@@ -224,7 +255,6 @@ export default async function pluginContentBlog(
224
255
  beforeDefaultRehypePlugins,
225
256
  } = options;
226
257
 
227
- const sourceToPermalink = getSourceToPermalink(content.blogPosts);
228
258
  const contentDirs = getContentPathList(contentPaths);
229
259
 
230
260
  function createMDXLoader(): RuleSetUseItem {
@@ -271,7 +301,7 @@ export default async function pluginContentBlog(
271
301
  resolveMarkdownLink: ({linkPathname, sourceFilePath}) => {
272
302
  const permalink = resolveMarkdownLinkPathname(linkPathname, {
273
303
  sourceFilePath,
274
- sourceToPermalink,
304
+ sourceToPermalink: sourceToPermalinkHelper.get(),
275
305
  siteDir,
276
306
  contentPaths,
277
307
  });