@docusaurus/plugin-content-blog 2.0.0-beta.21 → 2.0.0-beta.22

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/blogUtils.js CHANGED
@@ -210,7 +210,7 @@ async function processBlogSourceFile(blogSourceRelative, contentPaths, context,
210
210
  defaultReadingTime,
211
211
  })
212
212
  : undefined,
213
- truncated: truncateMarker.test(content),
213
+ hasTruncateMarker: truncateMarker.test(content),
214
214
  authors,
215
215
  frontMatter,
216
216
  },
package/lib/index.js CHANGED
@@ -9,25 +9,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.validateOptions = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
13
  const utils_1 = require("@docusaurus/utils");
13
- const remark_admonitions_1 = tslib_1.__importDefault(require("remark-admonitions"));
14
14
  const blogUtils_1 = require("./blogUtils");
15
15
  const footnoteIDFixer_1 = tslib_1.__importDefault(require("./remark/footnoteIDFixer"));
16
16
  const translations_1 = require("./translations");
17
17
  const feed_1 = require("./feed");
18
18
  async function pluginContentBlog(context, options) {
19
- if (options.admonitions) {
20
- options.remarkPlugins = options.remarkPlugins.concat([
21
- [remark_admonitions_1.default, options.admonitions],
22
- ]);
23
- }
24
- const { siteDir, siteConfig, generatedFilesDir, i18n: { currentLocale }, } = context;
19
+ const { siteDir, siteConfig, generatedFilesDir, localizationDir, i18n: { currentLocale }, } = context;
25
20
  const { onBrokenMarkdownLinks, baseUrl } = siteConfig;
26
21
  const contentPaths = {
27
22
  contentPath: path_1.default.resolve(siteDir, options.path),
28
23
  contentPathLocalized: (0, utils_1.getPluginI18nPath)({
29
- siteDir,
30
- locale: currentLocale,
24
+ localizationDir,
31
25
  pluginName: 'docusaurus-plugin-content-blog',
32
26
  pluginId: options.id,
33
27
  }),
@@ -112,6 +106,20 @@ async function pluginContentBlog(context, options) {
112
106
  const sidebarBlogPosts = options.blogSidebarCount === 'ALL'
113
107
  ? blogPosts
114
108
  : blogPosts.slice(0, options.blogSidebarCount);
109
+ function blogPostItemsModule(items) {
110
+ return items.map((postId) => {
111
+ const blogPostMetadata = blogItemsToMetadata[postId];
112
+ return {
113
+ content: {
114
+ __import: true,
115
+ path: blogPostMetadata.source,
116
+ query: {
117
+ truncated: true,
118
+ },
119
+ },
120
+ };
121
+ });
122
+ }
115
123
  if (archiveBasePath && blogPosts.length) {
116
124
  const archiveUrl = (0, utils_1.normalizeUrl)([
117
125
  baseUrl,
@@ -169,15 +177,7 @@ async function pluginContentBlog(context, options) {
169
177
  exact: true,
170
178
  modules: {
171
179
  sidebar: aliasedSource(sidebarProp),
172
- items: items.map((postID) => ({
173
- content: {
174
- __import: true,
175
- path: blogItemsToMetadata[postID].source,
176
- query: {
177
- truncated: true,
178
- },
179
- },
180
- })),
180
+ items: blogPostItemsModule(items),
181
181
  metadata: aliasedSource(pageMetadataPath),
182
182
  },
183
183
  });
@@ -220,18 +220,7 @@ async function pluginContentBlog(context, options) {
220
220
  exact: true,
221
221
  modules: {
222
222
  sidebar: aliasedSource(sidebarProp),
223
- items: items.map((postID) => {
224
- const blogPostMetadata = blogItemsToMetadata[postID];
225
- return {
226
- content: {
227
- __import: true,
228
- path: blogPostMetadata.source,
229
- query: {
230
- truncated: true,
231
- },
232
- },
233
- };
234
- }),
223
+ items: blogPostItemsModule(items),
235
224
  tag: aliasedSource(tagPropPath),
236
225
  listMetadata: aliasedSource(listMetadataPath),
237
226
  },
@@ -245,7 +234,7 @@ async function pluginContentBlog(context, options) {
245
234
  return (0, translations_1.translateContent)(content, translationFiles);
246
235
  },
247
236
  configureWebpack(_config, isServer, { getJSLoader }, content) {
248
- const { rehypePlugins, remarkPlugins, truncateMarker, beforeDefaultRemarkPlugins, beforeDefaultRehypePlugins, } = options;
237
+ const { admonitions, rehypePlugins, remarkPlugins, truncateMarker, beforeDefaultRemarkPlugins, beforeDefaultRehypePlugins, } = options;
249
238
  const markdownLoaderOptions = {
250
239
  siteDir,
251
240
  contentPaths,
@@ -255,7 +244,7 @@ async function pluginContentBlog(context, options) {
255
244
  if (onBrokenMarkdownLinks === 'ignore') {
256
245
  return;
257
246
  }
258
- (0, utils_1.reportMessage)(`Blog markdown link couldn't be resolved: (${brokenMarkdownLink.link}) in ${brokenMarkdownLink.filePath}`, onBrokenMarkdownLinks);
247
+ logger_1.default.report(onBrokenMarkdownLinks) `Blog markdown link couldn't be resolved: (url=${brokenMarkdownLink.link}) in path=${brokenMarkdownLink.filePath}`;
259
248
  },
260
249
  };
261
250
  const contentDirs = (0, utils_1.getContentPathList)(contentPaths);
@@ -277,6 +266,7 @@ async function pluginContentBlog(context, options) {
277
266
  {
278
267
  loader: require.resolve('@docusaurus/mdx-loader'),
279
268
  options: {
269
+ admonitions,
280
270
  remarkPlugins,
281
271
  rehypePlugins,
282
272
  beforeDefaultRemarkPlugins: [
package/lib/options.js CHANGED
@@ -13,7 +13,7 @@ exports.DEFAULT_OPTIONS = {
13
13
  feedOptions: { type: ['rss', 'atom'], copyright: '' },
14
14
  beforeDefaultRehypePlugins: [],
15
15
  beforeDefaultRemarkPlugins: [],
16
- admonitions: {},
16
+ admonitions: true,
17
17
  truncateMarker: /<!--\s*truncate\s*-->/,
18
18
  rehypePlugins: [],
19
19
  remarkPlugins: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-blog",
3
- "version": "2.0.0-beta.21",
3
+ "version": "2.0.0-beta.22",
4
4
  "description": "Blog plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/plugin-content-blog.d.ts",
@@ -18,22 +18,22 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/core": "2.0.0-beta.21",
22
- "@docusaurus/logger": "2.0.0-beta.21",
23
- "@docusaurus/mdx-loader": "2.0.0-beta.21",
24
- "@docusaurus/utils": "2.0.0-beta.21",
25
- "@docusaurus/utils-common": "2.0.0-beta.21",
26
- "@docusaurus/utils-validation": "2.0.0-beta.21",
27
- "cheerio": "^1.0.0-rc.11",
21
+ "@docusaurus/core": "2.0.0-beta.22",
22
+ "@docusaurus/logger": "2.0.0-beta.22",
23
+ "@docusaurus/mdx-loader": "2.0.0-beta.22",
24
+ "@docusaurus/types": "2.0.0-beta.22",
25
+ "@docusaurus/utils": "2.0.0-beta.22",
26
+ "@docusaurus/utils-common": "2.0.0-beta.22",
27
+ "@docusaurus/utils-validation": "2.0.0-beta.22",
28
+ "cheerio": "^1.0.0-rc.12",
28
29
  "feed": "^4.2.2",
29
30
  "fs-extra": "^10.1.0",
30
31
  "lodash": "^4.17.21",
31
32
  "reading-time": "^1.5.0",
32
- "remark-admonitions": "^1.2.1",
33
33
  "tslib": "^2.4.0",
34
34
  "unist-util-visit": "^2.0.3",
35
35
  "utility-types": "^3.10.0",
36
- "webpack": "^5.72.1"
36
+ "webpack": "^5.73.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@docusaurus/types": "2.0.0-beta.21",
@@ -46,5 +46,5 @@
46
46
  "engines": {
47
47
  "node": ">=16.14"
48
48
  },
49
- "gitHead": "69ac49fc6909517f13615ee40290c4bd00c39df4"
49
+ "gitHead": "daf9e462c4eebb7ac26a940932311f987e768f87"
50
50
  }
package/src/blogUtils.ts CHANGED
@@ -323,7 +323,7 @@ async function processBlogSourceFile(
323
323
  defaultReadingTime,
324
324
  })
325
325
  : undefined,
326
- truncated: truncateMarker.test(content),
326
+ hasTruncateMarker: truncateMarker.test(content),
327
327
  authors,
328
328
  frontMatter,
329
329
  },
package/src/index.ts CHANGED
@@ -6,12 +6,12 @@
6
6
  */
7
7
 
8
8
  import path from 'path';
9
+ import logger from '@docusaurus/logger';
9
10
  import {
10
11
  normalizeUrl,
11
12
  docuHash,
12
13
  aliasedSitePath,
13
14
  getPluginI18nPath,
14
- reportMessage,
15
15
  posixPath,
16
16
  addTrailingPathSeparator,
17
17
  createAbsoluteFilePathMatcher,
@@ -21,7 +21,6 @@ import {
21
21
  type TagsListItem,
22
22
  type TagModule,
23
23
  } from '@docusaurus/utils';
24
- import admonitions from 'remark-admonitions';
25
24
  import {
26
25
  generateBlogPosts,
27
26
  getSourceToPermalink,
@@ -49,16 +48,11 @@ export default async function pluginContentBlog(
49
48
  context: LoadContext,
50
49
  options: PluginOptions,
51
50
  ): Promise<Plugin<BlogContent>> {
52
- if (options.admonitions) {
53
- options.remarkPlugins = options.remarkPlugins.concat([
54
- [admonitions, options.admonitions],
55
- ]);
56
- }
57
-
58
51
  const {
59
52
  siteDir,
60
53
  siteConfig,
61
54
  generatedFilesDir,
55
+ localizationDir,
62
56
  i18n: {currentLocale},
63
57
  } = context;
64
58
  const {onBrokenMarkdownLinks, baseUrl} = siteConfig;
@@ -66,8 +60,7 @@ export default async function pluginContentBlog(
66
60
  const contentPaths: BlogContentPaths = {
67
61
  contentPath: path.resolve(siteDir, options.path),
68
62
  contentPathLocalized: getPluginI18nPath({
69
- siteDir,
70
- locale: currentLocale,
63
+ localizationDir,
71
64
  pluginName: 'docusaurus-plugin-content-blog',
72
65
  pluginId: options.id,
73
66
  }),
@@ -202,6 +195,21 @@ export default async function pluginContentBlog(
202
195
  ? blogPosts
203
196
  : blogPosts.slice(0, options.blogSidebarCount);
204
197
 
198
+ function blogPostItemsModule(items: string[]) {
199
+ return items.map((postId) => {
200
+ const blogPostMetadata = blogItemsToMetadata[postId]!;
201
+ return {
202
+ content: {
203
+ __import: true,
204
+ path: blogPostMetadata.source,
205
+ query: {
206
+ truncated: true,
207
+ },
208
+ },
209
+ };
210
+ });
211
+ }
212
+
205
213
  if (archiveBasePath && blogPosts.length) {
206
214
  const archiveUrl = normalizeUrl([
207
215
  baseUrl,
@@ -282,15 +290,7 @@ export default async function pluginContentBlog(
282
290
  exact: true,
283
291
  modules: {
284
292
  sidebar: aliasedSource(sidebarProp),
285
- items: items.map((postID) => ({
286
- content: {
287
- __import: true,
288
- path: blogItemsToMetadata[postID]!.source,
289
- query: {
290
- truncated: true,
291
- },
292
- },
293
- })),
293
+ items: blogPostItemsModule(items),
294
294
  metadata: aliasedSource(pageMetadataPath),
295
295
  },
296
296
  });
@@ -351,18 +351,7 @@ export default async function pluginContentBlog(
351
351
  exact: true,
352
352
  modules: {
353
353
  sidebar: aliasedSource(sidebarProp),
354
- items: items.map((postID) => {
355
- const blogPostMetadata = blogItemsToMetadata[postID]!;
356
- return {
357
- content: {
358
- __import: true,
359
- path: blogPostMetadata.source,
360
- query: {
361
- truncated: true,
362
- },
363
- },
364
- };
365
- }),
354
+ items: blogPostItemsModule(items),
366
355
  tag: aliasedSource(tagPropPath),
367
356
  listMetadata: aliasedSource(listMetadataPath),
368
357
  },
@@ -381,6 +370,7 @@ export default async function pluginContentBlog(
381
370
 
382
371
  configureWebpack(_config, isServer, {getJSLoader}, content) {
383
372
  const {
373
+ admonitions,
384
374
  rehypePlugins,
385
375
  remarkPlugins,
386
376
  truncateMarker,
@@ -397,10 +387,9 @@ export default async function pluginContentBlog(
397
387
  if (onBrokenMarkdownLinks === 'ignore') {
398
388
  return;
399
389
  }
400
- reportMessage(
401
- `Blog markdown link couldn't be resolved: (${brokenMarkdownLink.link}) in ${brokenMarkdownLink.filePath}`,
390
+ logger.report(
402
391
  onBrokenMarkdownLinks,
403
- );
392
+ )`Blog markdown link couldn't be resolved: (url=${brokenMarkdownLink.link}) in path=${brokenMarkdownLink.filePath}`;
404
393
  },
405
394
  };
406
395
 
@@ -423,6 +412,7 @@ export default async function pluginContentBlog(
423
412
  {
424
413
  loader: require.resolve('@docusaurus/mdx-loader'),
425
414
  options: {
415
+ admonitions,
426
416
  remarkPlugins,
427
417
  rehypePlugins,
428
418
  beforeDefaultRemarkPlugins: [
package/src/options.ts CHANGED
@@ -24,7 +24,7 @@ export const DEFAULT_OPTIONS: PluginOptions = {
24
24
  feedOptions: {type: ['rss', 'atom'], copyright: ''},
25
25
  beforeDefaultRehypePlugins: [],
26
26
  beforeDefaultRemarkPlugins: [],
27
- admonitions: {},
27
+ admonitions: true,
28
28
  truncateMarker: /<!--\s*truncate\s*-->/,
29
29
  rehypePlugins: [],
30
30
  remarkPlugins: [],
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  declare module '@docusaurus/plugin-content-blog' {
9
+ import type {LoadedMDXContent} from '@docusaurus/mdx-loader';
9
10
  import type {MDXOptions} from '@docusaurus/mdx-loader';
10
11
  import type {FrontMatterTag, Tag} from '@docusaurus/utils';
11
12
  import type {Plugin, LoadContext} from '@docusaurus/types';
@@ -201,7 +202,7 @@ declare module '@docusaurus/plugin-content-blog' {
201
202
  /**
202
203
  * Whether the truncate marker exists in the post's content.
203
204
  */
204
- readonly truncated?: boolean;
205
+ readonly hasTruncateMarker: boolean;
205
206
  /**
206
207
  * Used in pagination. Generated after the other metadata, so not readonly.
207
208
  * Content is just a subset of another post's metadata.
@@ -377,7 +378,6 @@ declare module '@docusaurus/plugin-content-blog' {
377
378
  * unlocalized file. Ignored when `editUrl` is a function.
378
379
  */
379
380
  editLocalizedFiles?: boolean;
380
- admonitions: {[key: string]: unknown};
381
381
  /** Path to the authors map file, relative to the blog content directory. */
382
382
  authorsMapPath: string;
383
383
  /** A callback to customize the reading time number displayed. */
@@ -463,6 +463,20 @@ declare module '@docusaurus/plugin-content-blog' {
463
463
  items: string[];
464
464
  };
465
465
 
466
+ type PropBlogPostMetadata = Overwrite<
467
+ BlogPostMetadata,
468
+ {
469
+ /** The publish date of the post. Serialized from the `Date` object. */
470
+ date: string;
471
+ }
472
+ >;
473
+
474
+ export type PropBlogPostContent = LoadedMDXContent<
475
+ BlogPostFrontMatter,
476
+ PropBlogPostMetadata,
477
+ Assets
478
+ >;
479
+
466
480
  export default function pluginContentBlog(
467
481
  context: LoadContext,
468
482
  options: PluginOptions,
@@ -470,26 +484,15 @@ declare module '@docusaurus/plugin-content-blog' {
470
484
  }
471
485
 
472
486
  declare module '@theme/BlogPostPage' {
473
- import type {LoadedMDXContent} from '@docusaurus/mdx-loader';
474
487
  import type {
475
488
  BlogPostFrontMatter,
476
- BlogPostMetadata,
477
- Assets,
478
489
  BlogSidebar,
490
+ PropBlogPostContent,
479
491
  } from '@docusaurus/plugin-content-blog';
480
- import type {Overwrite} from 'utility-types';
481
492
 
482
493
  export type FrontMatter = BlogPostFrontMatter;
483
494
 
484
- export type Metadata = Overwrite<
485
- BlogPostMetadata,
486
- {
487
- /** The publish date of the post. Serialized from the `Date` object. */
488
- date: string;
489
- }
490
- >;
491
-
492
- export type Content = LoadedMDXContent<FrontMatter, Metadata, Assets>;
495
+ export type Content = PropBlogPostContent;
493
496
 
494
497
  export interface Props {
495
498
  /** Blog sidebar. */
@@ -501,6 +504,10 @@ declare module '@theme/BlogPostPage' {
501
504
  export default function BlogPostPage(props: Props): JSX.Element;
502
505
  }
503
506
 
507
+ declare module '@theme/BlogPostPage/Metadata' {
508
+ export default function BlogPostPageMetadata(): JSX.Element;
509
+ }
510
+
504
511
  declare module '@theme/BlogListPage' {
505
512
  import type {Content} from '@theme/BlogPostPage';
506
513
  import type {
package/src/deps.d.ts DELETED
@@ -1,13 +0,0 @@
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
- declare module 'remark-admonitions' {
9
- type Options = {[key: string]: unknown};
10
-
11
- const plugin: (options?: Options) => void;
12
- export = plugin;
13
- }