@docusaurus/plugin-content-blog 0.0.0-6056 → 0.0.0-6060

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.
Files changed (3) hide show
  1. package/lib/index.js +69 -69
  2. package/package.json +10 -10
  3. package/src/index.ts +97 -96
package/lib/index.js CHANGED
@@ -13,6 +13,7 @@ const path_1 = tslib_1.__importDefault(require("path"));
13
13
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
14
  const utils_1 = require("@docusaurus/utils");
15
15
  const utils_validation_1 = require("@docusaurus/utils-validation");
16
+ const mdx_loader_1 = require("@docusaurus/mdx-loader");
16
17
  const blogUtils_1 = require("./blogUtils");
17
18
  const footnoteIDFixer_1 = tslib_1.__importDefault(require("./remark/footnoteIDFixer"));
18
19
  const translations_1 = require("./translations");
@@ -69,6 +70,73 @@ async function pluginContentBlog(context, options) {
69
70
  contentPaths,
70
71
  });
71
72
  const sourceToPermalinkHelper = createSourceToPermalinkHelper();
73
+ async function createBlogMDXLoaderRule() {
74
+ const { admonitions, rehypePlugins, remarkPlugins, recmaPlugins, truncateMarker, beforeDefaultRemarkPlugins, beforeDefaultRehypePlugins, } = options;
75
+ const contentDirs = (0, utils_1.getContentPathList)(contentPaths);
76
+ const loaderOptions = {
77
+ admonitions,
78
+ remarkPlugins,
79
+ rehypePlugins,
80
+ recmaPlugins,
81
+ beforeDefaultRemarkPlugins: [
82
+ footnoteIDFixer_1.default,
83
+ ...beforeDefaultRemarkPlugins,
84
+ ],
85
+ beforeDefaultRehypePlugins,
86
+ staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
87
+ siteDir,
88
+ isMDXPartial: (0, utils_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
89
+ metadataPath: (mdxPath) => {
90
+ // Note that metadataPath must be the same/in-sync as
91
+ // the path from createData for each MDX.
92
+ const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
93
+ return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
94
+ },
95
+ // For blog posts a title in markdown is always removed
96
+ // Blog posts title are rendered separately
97
+ removeContentTitle: true,
98
+ // Assets allow to convert some relative images paths to
99
+ // require() calls
100
+ // @ts-expect-error: TODO fix typing issue
101
+ createAssets: ({ frontMatter, metadata, }) => ({
102
+ image: frontMatter.image,
103
+ authorsImageUrls: metadata.authors.map((author) => author.imageURL),
104
+ }),
105
+ markdownConfig: siteConfig.markdown,
106
+ resolveMarkdownLink: ({ linkPathname, sourceFilePath }) => {
107
+ const permalink = (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
108
+ sourceFilePath,
109
+ sourceToPermalink: sourceToPermalinkHelper.get(),
110
+ siteDir,
111
+ contentPaths,
112
+ });
113
+ if (permalink === null) {
114
+ logger_1.default.report(onBrokenMarkdownLinks) `Blog markdown link couldn't be resolved: (url=${linkPathname}) in source file path=${sourceFilePath}`;
115
+ }
116
+ return permalink;
117
+ },
118
+ };
119
+ function createBlogMarkdownLoader() {
120
+ const markdownLoaderOptions = {
121
+ truncateMarker,
122
+ };
123
+ return {
124
+ loader: path_1.default.resolve(__dirname, './markdownLoader.js'),
125
+ options: markdownLoaderOptions,
126
+ };
127
+ }
128
+ return {
129
+ test: /\.mdx?$/i,
130
+ include: contentDirs
131
+ // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
132
+ .map(utils_1.addTrailingPathSeparator),
133
+ use: [
134
+ await (0, mdx_loader_1.createMDXLoaderItem)(loaderOptions),
135
+ createBlogMarkdownLoader(),
136
+ ],
137
+ };
138
+ }
139
+ const blogMDXLoaderRule = await createBlogMDXLoaderRule();
72
140
  return {
73
141
  name: PluginName,
74
142
  getPathsToWatch() {
@@ -179,66 +247,6 @@ async function pluginContentBlog(context, options) {
179
247
  return (0, translations_1.translateContent)(content, translationFiles);
180
248
  },
181
249
  configureWebpack() {
182
- const { admonitions, rehypePlugins, remarkPlugins, recmaPlugins, truncateMarker, beforeDefaultRemarkPlugins, beforeDefaultRehypePlugins, } = options;
183
- const contentDirs = (0, utils_1.getContentPathList)(contentPaths);
184
- function createMDXLoader() {
185
- const loaderOptions = {
186
- admonitions,
187
- remarkPlugins,
188
- rehypePlugins,
189
- recmaPlugins,
190
- beforeDefaultRemarkPlugins: [
191
- footnoteIDFixer_1.default,
192
- ...beforeDefaultRemarkPlugins,
193
- ],
194
- beforeDefaultRehypePlugins,
195
- staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
196
- siteDir,
197
- isMDXPartial: (0, utils_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
198
- metadataPath: (mdxPath) => {
199
- // Note that metadataPath must be the same/in-sync as
200
- // the path from createData for each MDX.
201
- const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
202
- return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
203
- },
204
- // For blog posts a title in markdown is always removed
205
- // Blog posts title are rendered separately
206
- removeContentTitle: true,
207
- // Assets allow to convert some relative images paths to
208
- // require() calls
209
- // @ts-expect-error: TODO fix typing issue
210
- createAssets: ({ frontMatter, metadata, }) => ({
211
- image: frontMatter.image,
212
- authorsImageUrls: metadata.authors.map((author) => author.imageURL),
213
- }),
214
- markdownConfig: siteConfig.markdown,
215
- resolveMarkdownLink: ({ linkPathname, sourceFilePath }) => {
216
- const permalink = (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
217
- sourceFilePath,
218
- sourceToPermalink: sourceToPermalinkHelper.get(),
219
- siteDir,
220
- contentPaths,
221
- });
222
- if (permalink === null) {
223
- logger_1.default.report(onBrokenMarkdownLinks) `Blog markdown link couldn't be resolved: (url=${linkPathname}) in source file path=${sourceFilePath}`;
224
- }
225
- return permalink;
226
- },
227
- };
228
- return {
229
- loader: require.resolve('@docusaurus/mdx-loader'),
230
- options: loaderOptions,
231
- };
232
- }
233
- function createBlogMarkdownLoader() {
234
- const loaderOptions = {
235
- truncateMarker,
236
- };
237
- return {
238
- loader: path_1.default.resolve(__dirname, './markdownLoader.js'),
239
- options: loaderOptions,
240
- };
241
- }
242
250
  return {
243
251
  resolve: {
244
252
  alias: {
@@ -246,15 +254,7 @@ async function pluginContentBlog(context, options) {
246
254
  },
247
255
  },
248
256
  module: {
249
- rules: [
250
- {
251
- test: /\.mdx?$/i,
252
- include: contentDirs
253
- // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
254
- .map(utils_1.addTrailingPathSeparator),
255
- use: [createMDXLoader(), createBlogMarkdownLoader()],
256
- },
257
- ],
257
+ rules: [blogMDXLoaderRule],
258
258
  },
259
259
  };
260
260
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-blog",
3
- "version": "0.0.0-6056",
3
+ "version": "0.0.0-6060",
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-6056",
35
- "@docusaurus/logger": "0.0.0-6056",
36
- "@docusaurus/mdx-loader": "0.0.0-6056",
37
- "@docusaurus/theme-common": "0.0.0-6056",
38
- "@docusaurus/types": "0.0.0-6056",
39
- "@docusaurus/utils": "0.0.0-6056",
40
- "@docusaurus/utils-common": "0.0.0-6056",
41
- "@docusaurus/utils-validation": "0.0.0-6056",
34
+ "@docusaurus/core": "0.0.0-6060",
35
+ "@docusaurus/logger": "0.0.0-6060",
36
+ "@docusaurus/mdx-loader": "0.0.0-6060",
37
+ "@docusaurus/theme-common": "0.0.0-6060",
38
+ "@docusaurus/types": "0.0.0-6060",
39
+ "@docusaurus/utils": "0.0.0-6060",
40
+ "@docusaurus/utils-common": "0.0.0-6060",
41
+ "@docusaurus/utils-validation": "0.0.0-6060",
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": "acf50a339a52a999dd474ff7e5b610b4227b8362"
65
+ "gitHead": "75cf549134cde8901d2598e6c6d2439a334512ff"
66
66
  }
package/src/index.ts CHANGED
@@ -22,6 +22,10 @@ import {
22
22
  type SourceToPermalink,
23
23
  } from '@docusaurus/utils';
24
24
  import {getTagsFilePathsToWatch} from '@docusaurus/utils-validation';
25
+ import {
26
+ createMDXLoaderItem,
27
+ type Options as MDXLoaderOptions,
28
+ } from '@docusaurus/mdx-loader';
25
29
  import {
26
30
  getBlogTags,
27
31
  paginateBlogPosts,
@@ -47,8 +51,7 @@ import type {
47
51
  BlogContent,
48
52
  BlogPaginated,
49
53
  } from '@docusaurus/plugin-content-blog';
50
- import type {Options as MDXLoaderOptions} from '@docusaurus/mdx-loader/lib/loader';
51
- import type {RuleSetUseItem} from 'webpack';
54
+ import type {RuleSetRule, RuleSetUseItem} from 'webpack';
52
55
 
53
56
  const PluginName = 'docusaurus-plugin-content-blog';
54
57
 
@@ -127,6 +130,97 @@ export default async function pluginContentBlog(
127
130
 
128
131
  const sourceToPermalinkHelper = createSourceToPermalinkHelper();
129
132
 
133
+ async function createBlogMDXLoaderRule(): Promise<RuleSetRule> {
134
+ const {
135
+ admonitions,
136
+ rehypePlugins,
137
+ remarkPlugins,
138
+ recmaPlugins,
139
+ truncateMarker,
140
+ beforeDefaultRemarkPlugins,
141
+ beforeDefaultRehypePlugins,
142
+ } = options;
143
+
144
+ const contentDirs = getContentPathList(contentPaths);
145
+
146
+ const loaderOptions: MDXLoaderOptions = {
147
+ admonitions,
148
+ remarkPlugins,
149
+ rehypePlugins,
150
+ recmaPlugins,
151
+ beforeDefaultRemarkPlugins: [
152
+ footnoteIDFixer,
153
+ ...beforeDefaultRemarkPlugins,
154
+ ],
155
+ beforeDefaultRehypePlugins,
156
+ staticDirs: siteConfig.staticDirectories.map((dir) =>
157
+ path.resolve(siteDir, dir),
158
+ ),
159
+ siteDir,
160
+ isMDXPartial: createAbsoluteFilePathMatcher(options.exclude, contentDirs),
161
+ metadataPath: (mdxPath: string) => {
162
+ // Note that metadataPath must be the same/in-sync as
163
+ // the path from createData for each MDX.
164
+ const aliasedPath = aliasedSitePath(mdxPath, siteDir);
165
+ return path.join(dataDir, `${docuHash(aliasedPath)}.json`);
166
+ },
167
+ // For blog posts a title in markdown is always removed
168
+ // Blog posts title are rendered separately
169
+ removeContentTitle: true,
170
+ // Assets allow to convert some relative images paths to
171
+ // require() calls
172
+ // @ts-expect-error: TODO fix typing issue
173
+ createAssets: ({
174
+ frontMatter,
175
+ metadata,
176
+ }: {
177
+ frontMatter: BlogPostFrontMatter;
178
+ metadata: BlogPostMetadata;
179
+ }): Assets => ({
180
+ image: frontMatter.image,
181
+ authorsImageUrls: metadata.authors.map((author) => author.imageURL),
182
+ }),
183
+ markdownConfig: siteConfig.markdown,
184
+ resolveMarkdownLink: ({linkPathname, sourceFilePath}) => {
185
+ const permalink = resolveMarkdownLinkPathname(linkPathname, {
186
+ sourceFilePath,
187
+ sourceToPermalink: sourceToPermalinkHelper.get(),
188
+ siteDir,
189
+ contentPaths,
190
+ });
191
+ if (permalink === null) {
192
+ logger.report(
193
+ onBrokenMarkdownLinks,
194
+ )`Blog markdown link couldn't be resolved: (url=${linkPathname}) in source file path=${sourceFilePath}`;
195
+ }
196
+ return permalink;
197
+ },
198
+ };
199
+
200
+ function createBlogMarkdownLoader(): RuleSetUseItem {
201
+ const markdownLoaderOptions: BlogMarkdownLoaderOptions = {
202
+ truncateMarker,
203
+ };
204
+ return {
205
+ loader: path.resolve(__dirname, './markdownLoader.js'),
206
+ options: markdownLoaderOptions,
207
+ };
208
+ }
209
+
210
+ return {
211
+ test: /\.mdx?$/i,
212
+ include: contentDirs
213
+ // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
214
+ .map(addTrailingPathSeparator),
215
+ use: [
216
+ await createMDXLoaderItem(loaderOptions),
217
+ createBlogMarkdownLoader(),
218
+ ],
219
+ };
220
+ }
221
+
222
+ const blogMDXLoaderRule = await createBlogMDXLoaderRule();
223
+
130
224
  return {
131
225
  name: PluginName,
132
226
 
@@ -273,91 +367,6 @@ export default async function pluginContentBlog(
273
367
  },
274
368
 
275
369
  configureWebpack() {
276
- const {
277
- admonitions,
278
- rehypePlugins,
279
- remarkPlugins,
280
- recmaPlugins,
281
- truncateMarker,
282
- beforeDefaultRemarkPlugins,
283
- beforeDefaultRehypePlugins,
284
- } = options;
285
-
286
- const contentDirs = getContentPathList(contentPaths);
287
-
288
- function createMDXLoader(): RuleSetUseItem {
289
- const loaderOptions: MDXLoaderOptions = {
290
- admonitions,
291
- remarkPlugins,
292
- rehypePlugins,
293
- recmaPlugins,
294
- beforeDefaultRemarkPlugins: [
295
- footnoteIDFixer,
296
- ...beforeDefaultRemarkPlugins,
297
- ],
298
- beforeDefaultRehypePlugins,
299
- staticDirs: siteConfig.staticDirectories.map((dir) =>
300
- path.resolve(siteDir, dir),
301
- ),
302
- siteDir,
303
- isMDXPartial: createAbsoluteFilePathMatcher(
304
- options.exclude,
305
- contentDirs,
306
- ),
307
- metadataPath: (mdxPath: string) => {
308
- // Note that metadataPath must be the same/in-sync as
309
- // the path from createData for each MDX.
310
- const aliasedPath = aliasedSitePath(mdxPath, siteDir);
311
- return path.join(dataDir, `${docuHash(aliasedPath)}.json`);
312
- },
313
- // For blog posts a title in markdown is always removed
314
- // Blog posts title are rendered separately
315
- removeContentTitle: true,
316
- // Assets allow to convert some relative images paths to
317
- // require() calls
318
- // @ts-expect-error: TODO fix typing issue
319
- createAssets: ({
320
- frontMatter,
321
- metadata,
322
- }: {
323
- frontMatter: BlogPostFrontMatter;
324
- metadata: BlogPostMetadata;
325
- }): Assets => ({
326
- image: frontMatter.image,
327
- authorsImageUrls: metadata.authors.map((author) => author.imageURL),
328
- }),
329
- markdownConfig: siteConfig.markdown,
330
- resolveMarkdownLink: ({linkPathname, sourceFilePath}) => {
331
- const permalink = resolveMarkdownLinkPathname(linkPathname, {
332
- sourceFilePath,
333
- sourceToPermalink: sourceToPermalinkHelper.get(),
334
- siteDir,
335
- contentPaths,
336
- });
337
- if (permalink === null) {
338
- logger.report(
339
- onBrokenMarkdownLinks,
340
- )`Blog markdown link couldn't be resolved: (url=${linkPathname}) in source file path=${sourceFilePath}`;
341
- }
342
- return permalink;
343
- },
344
- };
345
- return {
346
- loader: require.resolve('@docusaurus/mdx-loader'),
347
- options: loaderOptions,
348
- };
349
- }
350
-
351
- function createBlogMarkdownLoader(): RuleSetUseItem {
352
- const loaderOptions: BlogMarkdownLoaderOptions = {
353
- truncateMarker,
354
- };
355
- return {
356
- loader: path.resolve(__dirname, './markdownLoader.js'),
357
- options: loaderOptions,
358
- };
359
- }
360
-
361
370
  return {
362
371
  resolve: {
363
372
  alias: {
@@ -365,15 +374,7 @@ export default async function pluginContentBlog(
365
374
  },
366
375
  },
367
376
  module: {
368
- rules: [
369
- {
370
- test: /\.mdx?$/i,
371
- include: contentDirs
372
- // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
373
- .map(addTrailingPathSeparator),
374
- use: [createMDXLoader(), createBlogMarkdownLoader()],
375
- },
376
- ],
377
+ rules: [blogMDXLoaderRule],
377
378
  },
378
379
  };
379
380
  },