@docusaurus/plugin-content-blog 2.0.0-beta.1ab8aa0af → 2.0.0-beta.2

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/src/index.ts CHANGED
@@ -55,7 +55,7 @@ import {
55
55
  export default function pluginContentBlog(
56
56
  context: LoadContext,
57
57
  options: PluginOptions,
58
- ): Plugin<BlogContent | null> {
58
+ ): Plugin<BlogContent> {
59
59
  if (options.admonitions) {
60
60
  options.remarkPlugins = options.remarkPlugins.concat([
61
61
  [admonitions, options.admonitions],
@@ -88,8 +88,6 @@ export default function pluginContentBlog(
88
88
  const aliasedSource = (source: string) =>
89
89
  `~blog/${posixPath(path.relative(pluginDataDirRoot, source))}`;
90
90
 
91
- let blogPosts: BlogPost[] = [];
92
-
93
91
  return {
94
92
  name: 'docusaurus-plugin-content-blog',
95
93
 
@@ -116,9 +114,19 @@ export default function pluginContentBlog(
116
114
  async loadContent() {
117
115
  const {postsPerPage, routeBasePath} = options;
118
116
 
119
- blogPosts = await generateBlogPosts(contentPaths, context, options);
117
+ const blogPosts: BlogPost[] = await generateBlogPosts(
118
+ contentPaths,
119
+ context,
120
+ options,
121
+ );
122
+
120
123
  if (!blogPosts.length) {
121
- return null;
124
+ return {
125
+ blogPosts: [],
126
+ blogListPaginated: [],
127
+ blogTags: {},
128
+ blogTagsListPath: null,
129
+ };
122
130
  }
123
131
 
124
132
  // Colocate next and prev metadata.
@@ -241,7 +249,7 @@ export default function pluginContentBlog(
241
249
 
242
250
  const {addRoute, createData} = actions;
243
251
  const {
244
- blogPosts: loadedBlogPosts,
252
+ blogPosts,
245
253
  blogListPaginated,
246
254
  blogTags,
247
255
  blogTagsListPath,
@@ -274,7 +282,7 @@ export default function pluginContentBlog(
274
282
 
275
283
  // Create routes for blog entries.
276
284
  await Promise.all(
277
- loadedBlogPosts.map(async (blogPost) => {
285
+ blogPosts.map(async (blogPost) => {
278
286
  const {id, metadata} = blogPost;
279
287
  await createData(
280
288
  // Note that this created data path must be in sync with
@@ -288,7 +296,7 @@ export default function pluginContentBlog(
288
296
  component: blogPostComponent,
289
297
  exact: true,
290
298
  modules: {
291
- sidebar: sidebarProp,
299
+ sidebar: aliasedSource(sidebarProp),
292
300
  content: metadata.source,
293
301
  },
294
302
  });
@@ -312,7 +320,7 @@ export default function pluginContentBlog(
312
320
  component: blogListComponent,
313
321
  exact: true,
314
322
  modules: {
315
- sidebar: sidebarProp,
323
+ sidebar: aliasedSource(sidebarProp),
316
324
  items: items.map((postID) => {
317
325
  // To tell routes.js this is an import and not a nested object to recurse.
318
326
  return {
@@ -360,7 +368,7 @@ export default function pluginContentBlog(
360
368
  component: blogTagsPostsComponent,
361
369
  exact: true,
362
370
  modules: {
363
- sidebar: sidebarProp,
371
+ sidebar: aliasedSource(sidebarProp),
364
372
  items: items.map((postID) => {
365
373
  const metadata = blogItemsToMetadata[postID];
366
374
  return {
@@ -391,7 +399,7 @@ export default function pluginContentBlog(
391
399
  component: blogTagsListComponent,
392
400
  exact: true,
393
401
  modules: {
394
- sidebar: sidebarProp,
402
+ sidebar: aliasedSource(sidebarProp),
395
403
  tags: aliasedSource(tagsListPath),
396
404
  },
397
405
  });
@@ -402,6 +410,7 @@ export default function pluginContentBlog(
402
410
  _config: Configuration,
403
411
  isServer: boolean,
404
412
  {getJSLoader}: ConfigureWebpackUtils,
413
+ content,
405
414
  ) {
406
415
  const {
407
416
  rehypePlugins,
@@ -415,7 +424,7 @@ export default function pluginContentBlog(
415
424
  siteDir,
416
425
  contentPaths,
417
426
  truncateMarker,
418
- sourceToPermalink: getSourceToPermalink(blogPosts),
427
+ sourceToPermalink: getSourceToPermalink(content.blogPosts),
419
428
  onBrokenMarkdownLink: (brokenMarkdownLink) => {
420
429
  if (onBrokenMarkdownLinks === 'ignore') {
421
430
  return;
@@ -459,6 +468,9 @@ export default function pluginContentBlog(
459
468
  `${docuHash(aliasedPath)}.json`,
460
469
  );
461
470
  },
471
+ // For blog posts a title in markdown is always removed
472
+ // Blog posts title are rendered separately
473
+ removeContentTitle: true,
462
474
  },
463
475
  },
464
476
  {
@@ -496,16 +508,21 @@ export default function pluginContentBlog(
496
508
  try {
497
509
  await fs.outputFile(feedPath, feedContent);
498
510
  } catch (err) {
499
- throw new Error(`Generating ${feedType} feed failed: ${err}`);
511
+ throw new Error(`Generating ${feedType} feed failed: ${err}.`);
500
512
  }
501
513
  }),
502
514
  );
503
515
  },
504
516
 
505
- injectHtmlTags() {
517
+ injectHtmlTags({content}) {
518
+ if (!content.blogPosts.length) {
519
+ return {};
520
+ }
521
+
506
522
  if (!options.feedOptions?.type) {
507
523
  return {};
508
524
  }
525
+
509
526
  const feedTypes = options.feedOptions.type;
510
527
  const {
511
528
  siteConfig: {title},