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

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/authors.js CHANGED
@@ -29,7 +29,11 @@ const AuthorsMapSchema = utils_validation_1.Joi.object()
29
29
  'object.base': "The authors map file should contain an object where each entry contains an author key and the corresponding author's data.",
30
30
  });
31
31
  function validateAuthorsMap(content) {
32
- return utils_validation_1.Joi.attempt(content, AuthorsMapSchema);
32
+ const { error, value } = AuthorsMapSchema.validate(content);
33
+ if (error) {
34
+ throw error;
35
+ }
36
+ return value;
33
37
  }
34
38
  exports.validateAuthorsMap = validateAuthorsMap;
35
39
  async function getAuthorsMap(params) {
@@ -4,9 +4,9 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import type { BlogContentPaths, BlogMarkdownLoaderOptions } from './types';
8
7
  import type { LoadContext } from '@docusaurus/types';
9
8
  import type { PluginOptions, BlogPost, BlogTags, BlogPaginated } from '@docusaurus/plugin-content-blog';
9
+ import type { BlogContentPaths, BlogMarkdownLoaderOptions } from './types';
10
10
  export declare function truncate(fileString: string, truncateMarker: RegExp): string;
11
11
  export declare function getSourceToPermalink(blogPosts: BlogPost[]): {
12
12
  [aliasedPath: string]: string;
package/lib/blogUtils.js CHANGED
@@ -10,12 +10,12 @@ exports.linkify = exports.generateBlogPosts = exports.parseBlogFileName = export
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"));
13
- const reading_time_1 = tslib_1.__importDefault(require("reading-time"));
14
13
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
14
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
+ const reading_time_1 = tslib_1.__importDefault(require("reading-time"));
15
16
  const utils_1 = require("@docusaurus/utils");
16
17
  const frontMatter_1 = require("./frontMatter");
17
18
  const authors_1 = require("./authors");
18
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
19
19
  function truncate(fileString, truncateMarker) {
20
20
  return fileString.split(truncateMarker, 1).shift();
21
21
  }
@@ -161,7 +161,7 @@ async function processBlogSourceFile(blogSourceRelative, contentPaths, context,
161
161
  const formattedDate = formatBlogPostDate(i18n.currentLocale, date, i18n.localeConfigs[i18n.currentLocale].calendar);
162
162
  const title = frontMatter.title ?? contentTitle ?? parsedBlogFileName.text;
163
163
  const description = frontMatter.description ?? excerpt ?? '';
164
- const slug = frontMatter.slug || parsedBlogFileName.slug;
164
+ const slug = frontMatter.slug ?? parsedBlogFileName.slug;
165
165
  const permalink = (0, utils_1.normalizeUrl)([baseUrl, routeBasePath, slug]);
166
166
  function getBlogEditUrl() {
167
167
  const blogPathRelative = path_1.default.relative(blogDirPath, path_1.default.resolve(blogSourceAbsolute));
@@ -210,7 +210,7 @@ async function processBlogSourceFile(blogSourceRelative, contentPaths, context,
210
210
  defaultReadingTime,
211
211
  })
212
212
  : undefined,
213
- truncated: truncateMarker?.test(content) || false,
213
+ truncated: truncateMarker.test(content),
214
214
  authors,
215
215
  frontMatter,
216
216
  },
package/lib/feed.js CHANGED
@@ -8,12 +8,13 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.createBlogFeedFiles = void 0;
10
10
  const tslib_1 = require("tslib");
11
- const feed_1 = require("feed");
12
- const utils_1 = require("@docusaurus/utils");
13
- const cheerio_1 = require("cheerio");
14
11
  const path_1 = tslib_1.__importDefault(require("path"));
15
12
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const feed_1 = require("feed");
15
+ const utils_1 = require("@docusaurus/utils");
16
16
  const utils_common_1 = require("@docusaurus/utils-common");
17
+ const cheerio_1 = require("cheerio");
17
18
  async function generateBlogFeed({ blogPosts, options, siteConfig, outDir, locale, }) {
18
19
  if (!blogPosts.length) {
19
20
  return null;
@@ -76,7 +77,8 @@ async function createBlogFeedFile({ feed, feedType, generatePath, }) {
76
77
  await fs_extra_1.default.outputFile(path_1.default.join(generatePath, feedPath), feedContent);
77
78
  }
78
79
  catch (err) {
79
- throw new Error(`Generating ${feedType} feed failed: ${err}.`);
80
+ logger_1.default.error(`Generating ${feedType} feed failed.`);
81
+ throw err;
80
82
  }
81
83
  }
82
84
  async function createBlogFeedFiles({ blogPosts, options, siteConfig, outDir, locale, }) {
package/lib/index.js CHANGED
@@ -9,11 +9,11 @@ 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 utils_1 = require("@docusaurus/utils");
12
13
  const remark_admonitions_1 = tslib_1.__importDefault(require("remark-admonitions"));
14
+ const blogUtils_1 = require("./blogUtils");
13
15
  const footnoteIDFixer_1 = tslib_1.__importDefault(require("./remark/footnoteIDFixer"));
14
- const utils_1 = require("@docusaurus/utils");
15
16
  const translations_1 = require("./translations");
16
- const blogUtils_1 = require("./blogUtils");
17
17
  const feed_1 = require("./feed");
18
18
  async function pluginContentBlog(context, options) {
19
19
  if (options.admonitions) {
@@ -105,9 +105,6 @@ async function pluginContentBlog(context, options) {
105
105
  };
106
106
  },
107
107
  async contentLoaded({ content: blogContents, actions }) {
108
- if (!blogContents) {
109
- return;
110
- }
111
108
  const { blogListComponent, blogPostComponent, blogTagsListComponent, blogTagsPostsComponent, blogArchiveComponent, routeBasePath, archiveBasePath, } = options;
112
109
  const { addRoute, createData } = actions;
113
110
  const { blogSidebarTitle, blogPosts, blogListPaginated, blogTags, blogTagsListPath, } = blogContents;
@@ -334,10 +331,7 @@ async function pluginContentBlog(context, options) {
334
331
  });
335
332
  },
336
333
  injectHtmlTags({ content }) {
337
- if (!content.blogPosts.length) {
338
- return {};
339
- }
340
- if (!options.feedOptions?.type) {
334
+ if (!content.blogPosts.length || !options.feedOptions.type) {
341
335
  return {};
342
336
  }
343
337
  const feedTypes = options.feedOptions.type;
@@ -25,6 +25,6 @@ function markdownLoader(source) {
25
25
  if (truncated) {
26
26
  finalContent = (0, blogUtils_1.truncate)(finalContent, markdownLoaderOptions.truncateMarker);
27
27
  }
28
- return callback?.(null, finalContent);
28
+ return callback(null, finalContent);
29
29
  }
30
30
  exports.default = markdownLoader;
package/lib/options.d.ts CHANGED
@@ -7,4 +7,4 @@
7
7
  import type { PluginOptions, Options } from '@docusaurus/plugin-content-blog';
8
8
  import type { OptionValidationContext } from '@docusaurus/types';
9
9
  export declare const DEFAULT_OPTIONS: PluginOptions;
10
- export declare function validateOptions({ validate, options, }: OptionValidationContext<Options, PluginOptions>): PluginOptions;
10
+ export declare function validateOptions({ validate, options, }: OptionValidationContext<Options | undefined, PluginOptions>): PluginOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-blog",
3
- "version": "2.0.0-beta.20",
3
+ "version": "2.0.0-beta.21",
4
4
  "description": "Blog plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/plugin-content-blog.d.ts",
@@ -18,13 +18,13 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/core": "2.0.0-beta.20",
22
- "@docusaurus/logger": "2.0.0-beta.20",
23
- "@docusaurus/mdx-loader": "2.0.0-beta.20",
24
- "@docusaurus/utils": "2.0.0-beta.20",
25
- "@docusaurus/utils-common": "2.0.0-beta.20",
26
- "@docusaurus/utils-validation": "2.0.0-beta.20",
27
- "cheerio": "^1.0.0-rc.10",
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",
28
28
  "feed": "^4.2.2",
29
29
  "fs-extra": "^10.1.0",
30
30
  "lodash": "^4.17.21",
@@ -33,10 +33,10 @@
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.0"
36
+ "webpack": "^5.72.1"
37
37
  },
38
38
  "devDependencies": {
39
- "@docusaurus/types": "2.0.0-beta.20",
39
+ "@docusaurus/types": "2.0.0-beta.21",
40
40
  "escape-string-regexp": "^4.0.0"
41
41
  },
42
42
  "peerDependencies": {
@@ -44,7 +44,7 @@
44
44
  "react-dom": "^16.8.4 || ^17.0.0"
45
45
  },
46
46
  "engines": {
47
- "node": ">=14"
47
+ "node": ">=16.14"
48
48
  },
49
- "gitHead": "ed5cdba401a5948e187e927039b142a0decc702d"
49
+ "gitHead": "69ac49fc6909517f13615ee40290c4bd00c39df4"
50
50
  }
package/src/authors.ts CHANGED
@@ -5,9 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import type {BlogContentPaths} from './types';
9
8
  import {getDataFileData} from '@docusaurus/utils';
10
9
  import {Joi, URISchema} from '@docusaurus/utils-validation';
10
+ import type {BlogContentPaths} from './types';
11
11
  import type {
12
12
  Author,
13
13
  BlogPostFrontMatter,
@@ -44,7 +44,11 @@ const AuthorsMapSchema = Joi.object<AuthorsMap>()
44
44
  });
45
45
 
46
46
  export function validateAuthorsMap(content: unknown): AuthorsMap {
47
- return Joi.attempt(content, AuthorsMapSchema);
47
+ const {error, value} = AuthorsMapSchema.validate(content);
48
+ if (error) {
49
+ throw error;
50
+ }
51
+ return value;
48
52
  }
49
53
 
50
54
  export async function getAuthorsMap(params: {
package/src/blogUtils.ts CHANGED
@@ -7,9 +7,9 @@
7
7
 
8
8
  import fs from 'fs-extra';
9
9
  import path from 'path';
10
- import readingTime from 'reading-time';
11
10
  import _ from 'lodash';
12
- import type {BlogContentPaths, BlogMarkdownLoaderOptions} from './types';
11
+ import logger from '@docusaurus/logger';
12
+ import readingTime from 'reading-time';
13
13
  import {
14
14
  parseMarkdownString,
15
15
  normalizeUrl,
@@ -24,10 +24,9 @@ import {
24
24
  getFileCommitDate,
25
25
  getContentPathList,
26
26
  } from '@docusaurus/utils';
27
- import type {LoadContext} from '@docusaurus/types';
28
27
  import {validateBlogPostFrontMatter} from './frontMatter';
29
28
  import {type AuthorsMap, getAuthorsMap, getBlogPostAuthors} from './authors';
30
- import logger from '@docusaurus/logger';
29
+ import type {LoadContext} from '@docusaurus/types';
31
30
  import type {
32
31
  PluginOptions,
33
32
  ReadingTimeFunction,
@@ -35,6 +34,7 @@ import type {
35
34
  BlogTags,
36
35
  BlogPaginated,
37
36
  } from '@docusaurus/plugin-content-blog';
37
+ import type {BlogContentPaths, BlogMarkdownLoaderOptions} from './types';
38
38
 
39
39
  export function truncate(fileString: string, truncateMarker: RegExp): string {
40
40
  return fileString.split(truncateMarker, 1).shift()!;
@@ -264,7 +264,7 @@ async function processBlogSourceFile(
264
264
  const title = frontMatter.title ?? contentTitle ?? parsedBlogFileName.text;
265
265
  const description = frontMatter.description ?? excerpt ?? '';
266
266
 
267
- const slug = frontMatter.slug || parsedBlogFileName.slug;
267
+ const slug = frontMatter.slug ?? parsedBlogFileName.slug;
268
268
 
269
269
  const permalink = normalizeUrl([baseUrl, routeBasePath, slug]);
270
270
 
@@ -323,7 +323,7 @@ async function processBlogSourceFile(
323
323
  defaultReadingTime,
324
324
  })
325
325
  : undefined,
326
- truncated: truncateMarker?.test(content) || false,
326
+ truncated: truncateMarker.test(content),
327
327
  authors,
328
328
  frontMatter,
329
329
  },
package/src/feed.ts CHANGED
@@ -5,19 +5,20 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
+ import path from 'path';
9
+ import fs from 'fs-extra';
10
+ import logger from '@docusaurus/logger';
8
11
  import {Feed, type Author as FeedAuthor, type Item as FeedItem} from 'feed';
9
12
  import {normalizeUrl, readOutputHTMLFile} from '@docusaurus/utils';
13
+ import {blogPostContainerID} from '@docusaurus/utils-common';
10
14
  import {load as cheerioLoad} from 'cheerio';
11
15
  import type {DocusaurusConfig} from '@docusaurus/types';
12
- import path from 'path';
13
- import fs from 'fs-extra';
14
16
  import type {
15
17
  FeedType,
16
18
  PluginOptions,
17
19
  Author,
18
20
  BlogPost,
19
21
  } from '@docusaurus/plugin-content-blog';
20
- import {blogPostContainerID} from '@docusaurus/utils-common';
21
22
 
22
23
  async function generateBlogFeed({
23
24
  blogPosts,
@@ -127,7 +128,8 @@ async function createBlogFeedFile({
127
128
  try {
128
129
  await fs.outputFile(path.join(generatePath, feedPath), feedContent);
129
130
  } catch (err) {
130
- throw new Error(`Generating ${feedType} feed failed: ${err}.`);
131
+ logger.error(`Generating ${feedType} feed failed.`);
132
+ throw err;
131
133
  }
132
134
  }
133
135
 
package/src/index.ts CHANGED
@@ -6,8 +6,6 @@
6
6
  */
7
7
 
8
8
  import path from 'path';
9
- import admonitions from 'remark-admonitions';
10
- import footnoteIDFixer from './remark/footnoteIDFixer';
11
9
  import {
12
10
  normalizeUrl,
13
11
  docuHash,
@@ -23,17 +21,19 @@ import {
23
21
  type TagsListItem,
24
22
  type TagModule,
25
23
  } from '@docusaurus/utils';
26
- import {translateContent, getTranslationFiles} from './translations';
27
-
28
- import type {BlogContentPaths, BlogMarkdownLoaderOptions} from './types';
29
- import type {LoadContext, Plugin, HtmlTags} from '@docusaurus/types';
24
+ import admonitions from 'remark-admonitions';
30
25
  import {
31
26
  generateBlogPosts,
32
27
  getSourceToPermalink,
33
28
  getBlogTags,
34
29
  paginateBlogPosts,
35
30
  } from './blogUtils';
31
+ import footnoteIDFixer from './remark/footnoteIDFixer';
32
+ import {translateContent, getTranslationFiles} from './translations';
36
33
  import {createBlogFeedFiles} from './feed';
34
+
35
+ import type {BlogContentPaths, BlogMarkdownLoaderOptions} from './types';
36
+ import type {LoadContext, Plugin, HtmlTags} from '@docusaurus/types';
37
37
  import type {
38
38
  PluginOptions,
39
39
  BlogPostFrontMatter,
@@ -176,10 +176,6 @@ export default async function pluginContentBlog(
176
176
  },
177
177
 
178
178
  async contentLoaded({content: blogContents, actions}) {
179
- if (!blogContents) {
180
- return;
181
- }
182
-
183
179
  const {
184
180
  blogListComponent,
185
181
  blogPostComponent,
@@ -500,11 +496,7 @@ export default async function pluginContentBlog(
500
496
  },
501
497
 
502
498
  injectHtmlTags({content}) {
503
- if (!content.blogPosts.length) {
504
- return {};
505
- }
506
-
507
- if (!options.feedOptions?.type) {
499
+ if (!content.blogPosts.length || !options.feedOptions.type) {
508
500
  return {};
509
501
  }
510
502
 
@@ -34,5 +34,5 @@ export default function markdownLoader(
34
34
  finalContent = truncate(finalContent, markdownLoaderOptions.truncateMarker);
35
35
  }
36
36
 
37
- return callback?.(null, finalContent);
37
+ return callback(null, finalContent);
38
38
  }
package/src/options.ts CHANGED
@@ -13,7 +13,11 @@ import {
13
13
  URISchema,
14
14
  } from '@docusaurus/utils-validation';
15
15
  import {GlobExcludeDefault} from '@docusaurus/utils';
16
- import type {PluginOptions, Options} from '@docusaurus/plugin-content-blog';
16
+ import type {
17
+ PluginOptions,
18
+ Options,
19
+ FeedType,
20
+ } from '@docusaurus/plugin-content-blog';
17
21
  import type {OptionValidationContext} from '@docusaurus/types';
18
22
 
19
23
  export const DEFAULT_OPTIONS: PluginOptions = {
@@ -101,7 +105,7 @@ const PluginOptionSchema = Joi.object<PluginOptions>({
101
105
  Joi.alternatives().conditional(
102
106
  Joi.string().equal('all', 'rss', 'atom', 'json'),
103
107
  {
104
- then: Joi.custom((val) =>
108
+ then: Joi.custom((val: FeedType | 'all') =>
105
109
  val === 'all' ? ['rss', 'atom', 'json'] : [val],
106
110
  ),
107
111
  },
@@ -131,10 +135,7 @@ const PluginOptionSchema = Joi.object<PluginOptions>({
131
135
  export function validateOptions({
132
136
  validate,
133
137
  options,
134
- }: OptionValidationContext<Options, PluginOptions>): PluginOptions {
135
- const validatedOptions = validate(
136
- PluginOptionSchema,
137
- options,
138
- ) as PluginOptions;
138
+ }: OptionValidationContext<Options | undefined, PluginOptions>): PluginOptions {
139
+ const validatedOptions = validate(PluginOptionSchema, options);
139
140
  return validatedOptions;
140
141
  }
@@ -538,11 +538,11 @@ declare module '@theme/BlogTagsListPage' {
538
538
  }
539
539
 
540
540
  declare module '@theme/BlogTagsPostsPage' {
541
+ import type {Content} from '@theme/BlogPostPage';
541
542
  import type {
542
543
  BlogSidebar,
543
544
  BlogPaginatedMetadata,
544
545
  } from '@docusaurus/plugin-content-blog';
545
- import type {Content} from '@theme/BlogPostPage';
546
546
  import type {TagModule} from '@docusaurus/utils';
547
547
 
548
548
  export interface Props {