@docusaurus/plugin-content-blog 2.1.0 → 2.3.0

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/feed.js CHANGED
@@ -33,17 +33,30 @@ async function generateBlogFeed({ blogPosts, options, siteConfig, outDir, locale
33
33
  favicon: favicon ? (0, utils_1.normalizeUrl)([siteUrl, baseUrl, favicon]) : undefined,
34
34
  copyright: feedOptions.copyright,
35
35
  });
36
+ const createFeedItems = options.feedOptions.createFeedItems ?? defaultCreateFeedItems;
37
+ const feedItems = await createFeedItems({
38
+ blogPosts,
39
+ siteConfig,
40
+ outDir,
41
+ defaultCreateFeedItems,
42
+ });
43
+ feedItems.forEach(feed.addItem);
44
+ return feed;
45
+ }
46
+ async function defaultCreateFeedItems({ blogPosts, siteConfig, outDir, }) {
47
+ const { url: siteUrl } = siteConfig;
36
48
  function toFeedAuthor(author) {
37
49
  return { name: author.name, link: author.url, email: author.email };
38
50
  }
39
- await Promise.all(blogPosts.map(async (post) => {
40
- const { id, metadata: { title: metadataTitle, permalink, date, description, authors, tags, }, } = post;
51
+ return Promise.all(blogPosts.map(async (post) => {
52
+ const { metadata: { title: metadataTitle, permalink, date, description, authors, tags, }, } = post;
41
53
  const content = await (0, utils_1.readOutputHTMLFile)(permalink.replace(siteConfig.baseUrl, ''), outDir, siteConfig.trailingSlash);
42
54
  const $ = (0, cheerio_1.load)(content);
55
+ const link = (0, utils_1.normalizeUrl)([siteUrl, permalink]);
43
56
  const feedItem = {
44
57
  title: metadataTitle,
45
- id,
46
- link: (0, utils_1.normalizeUrl)([siteUrl, permalink]),
58
+ id: link,
59
+ link,
47
60
  date,
48
61
  description,
49
62
  // Atom feed demands the "term", while other feeds use "name"
@@ -57,8 +70,7 @@ async function generateBlogFeed({ blogPosts, options, siteConfig, outDir, locale
57
70
  feedItem.author = feedItemAuthors;
58
71
  }
59
72
  return feedItem;
60
- })).then((items) => items.forEach(feed.addItem));
61
- return feed;
73
+ }));
62
74
  }
63
75
  async function createBlogFeedFile({ feed, feedType, generatePath, }) {
64
76
  const [feedContent, feedPath] = (() => {
package/lib/index.js CHANGED
@@ -292,6 +292,7 @@ async function pluginContentBlog(context, options) {
292
292
  image: frontMatter.image,
293
293
  authorsImageUrls: metadata.authors.map((author) => author.imageURL),
294
294
  }),
295
+ markdownConfig: siteConfig.markdown,
295
296
  },
296
297
  },
297
298
  {
package/lib/options.js CHANGED
@@ -94,6 +94,7 @@ const PluginOptionSchema = utils_validation_1.Joi.object({
94
94
  .default(exports.DEFAULT_OPTIONS.feedOptions.copyright),
95
95
  }),
96
96
  language: utils_validation_1.Joi.string(),
97
+ createFeedItems: utils_validation_1.Joi.function(),
97
98
  }).default(exports.DEFAULT_OPTIONS.feedOptions),
98
99
  authorsMapPath: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.authorsMapPath),
99
100
  readingTime: utils_validation_1.Joi.function().default(() => exports.DEFAULT_OPTIONS.readingTime),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-blog",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
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.1.0",
22
- "@docusaurus/logger": "2.1.0",
23
- "@docusaurus/mdx-loader": "2.1.0",
24
- "@docusaurus/types": "2.1.0",
25
- "@docusaurus/utils": "2.1.0",
26
- "@docusaurus/utils-common": "2.1.0",
27
- "@docusaurus/utils-validation": "2.1.0",
21
+ "@docusaurus/core": "2.3.0",
22
+ "@docusaurus/logger": "2.3.0",
23
+ "@docusaurus/mdx-loader": "2.3.0",
24
+ "@docusaurus/types": "2.3.0",
25
+ "@docusaurus/utils": "2.3.0",
26
+ "@docusaurus/utils-common": "2.3.0",
27
+ "@docusaurus/utils-validation": "2.3.0",
28
28
  "cheerio": "^1.0.0-rc.12",
29
29
  "feed": "^4.2.2",
30
30
  "fs-extra": "^10.1.0",
@@ -35,9 +35,6 @@
35
35
  "utility-types": "^3.10.0",
36
36
  "webpack": "^5.73.0"
37
37
  },
38
- "devDependencies": {
39
- "escape-string-regexp": "^4.0.0"
40
- },
41
38
  "peerDependencies": {
42
39
  "react": "^16.8.4 || ^17.0.0",
43
40
  "react-dom": "^16.8.4 || ^17.0.0"
@@ -45,5 +42,5 @@
45
42
  "engines": {
46
43
  "node": ">=16.14"
47
44
  },
48
- "gitHead": "be9b0942641184213485eba7fd75ceb0b328d3f4"
45
+ "gitHead": "ad477781bdca6a11fa9c6daef5048bdcec0ee37e"
49
46
  }
package/src/feed.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  import path from 'path';
9
9
  import fs from 'fs-extra';
10
10
  import logger from '@docusaurus/logger';
11
- import {Feed, type Author as FeedAuthor, type Item as FeedItem} from 'feed';
11
+ import {Feed, type Author as FeedAuthor} from 'feed';
12
12
  import {normalizeUrl, readOutputHTMLFile} from '@docusaurus/utils';
13
13
  import {blogPostContainerID} from '@docusaurus/utils-common';
14
14
  import {load as cheerioLoad} from 'cheerio';
@@ -18,6 +18,7 @@ import type {
18
18
  PluginOptions,
19
19
  Author,
20
20
  BlogPost,
21
+ BlogFeedItem,
21
22
  } from '@docusaurus/plugin-content-blog';
22
23
 
23
24
  async function generateBlogFeed({
@@ -54,14 +55,39 @@ async function generateBlogFeed({
54
55
  copyright: feedOptions.copyright,
55
56
  });
56
57
 
58
+ const createFeedItems =
59
+ options.feedOptions.createFeedItems ?? defaultCreateFeedItems;
60
+
61
+ const feedItems = await createFeedItems({
62
+ blogPosts,
63
+ siteConfig,
64
+ outDir,
65
+ defaultCreateFeedItems,
66
+ });
67
+
68
+ feedItems.forEach(feed.addItem);
69
+
70
+ return feed;
71
+ }
72
+
73
+ async function defaultCreateFeedItems({
74
+ blogPosts,
75
+ siteConfig,
76
+ outDir,
77
+ }: {
78
+ blogPosts: BlogPost[];
79
+ siteConfig: DocusaurusConfig;
80
+ outDir: string;
81
+ }): Promise<BlogFeedItem[]> {
82
+ const {url: siteUrl} = siteConfig;
83
+
57
84
  function toFeedAuthor(author: Author): FeedAuthor {
58
85
  return {name: author.name, link: author.url, email: author.email};
59
86
  }
60
87
 
61
- await Promise.all(
88
+ return Promise.all(
62
89
  blogPosts.map(async (post) => {
63
90
  const {
64
- id,
65
91
  metadata: {
66
92
  title: metadataTitle,
67
93
  permalink,
@@ -79,10 +105,11 @@ async function generateBlogFeed({
79
105
  );
80
106
  const $ = cheerioLoad(content);
81
107
 
82
- const feedItem: FeedItem = {
108
+ const link = normalizeUrl([siteUrl, permalink]);
109
+ const feedItem: BlogFeedItem = {
83
110
  title: metadataTitle,
84
- id,
85
- link: normalizeUrl([siteUrl, permalink]),
111
+ id: link,
112
+ link,
86
113
  date,
87
114
  description,
88
115
  // Atom feed demands the "term", while other feeds use "name"
@@ -99,9 +126,7 @@ async function generateBlogFeed({
99
126
 
100
127
  return feedItem;
101
128
  }),
102
- ).then((items) => items.forEach(feed.addItem));
103
-
104
- return feed;
129
+ );
105
130
  }
106
131
 
107
132
  async function createBlogFeedFile({
package/src/index.ts CHANGED
@@ -455,6 +455,7 @@ export default async function pluginContentBlog(
455
455
  (author) => author.imageURL,
456
456
  ),
457
457
  }),
458
+ markdownConfig: siteConfig.markdown,
458
459
  },
459
460
  },
460
461
  {
package/src/options.ts CHANGED
@@ -124,6 +124,7 @@ const PluginOptionSchema = Joi.object<PluginOptions>({
124
124
  .default(DEFAULT_OPTIONS.feedOptions.copyright),
125
125
  }),
126
126
  language: Joi.string(),
127
+ createFeedItems: Joi.function(),
127
128
  }).default(DEFAULT_OPTIONS.feedOptions),
128
129
  authorsMapPath: Joi.string().default(DEFAULT_OPTIONS.authorsMapPath),
129
130
  readingTime: Joi.function().default(() => DEFAULT_OPTIONS.readingTime),
@@ -9,12 +9,19 @@ declare module '@docusaurus/plugin-content-blog' {
9
9
  import type {LoadedMDXContent} from '@docusaurus/mdx-loader';
10
10
  import type {MDXOptions} from '@docusaurus/mdx-loader';
11
11
  import type {FrontMatterTag, Tag} from '@docusaurus/utils';
12
- import type {Plugin, LoadContext} from '@docusaurus/types';
12
+ import type {DocusaurusConfig, Plugin, LoadContext} from '@docusaurus/types';
13
+ import type {Item as FeedItem} from 'feed';
13
14
  import type {Overwrite} from 'utility-types';
14
15
 
15
16
  export type Assets = {
16
17
  /**
17
- * If `metadata.image` is a collocated image path, this entry will be the
18
+ * If `metadata.yarn workspace website typecheck
19
+ 4
20
+ yarn workspace v1.22.19yarn workspace website typecheck
21
+ 4
22
+ yarn workspace v1.22.19yarn workspace website typecheck
23
+ 4
24
+ yarn workspace v1.22.19image` is a collocated image path, this entry will be the
18
25
  * bundler-generated image path. Otherwise, it's empty, and the image URL
19
26
  * should be accessed through `frontMatter.image`.
20
27
  */
@@ -255,6 +262,24 @@ declare module '@docusaurus/plugin-content-blog' {
255
262
  copyright: string;
256
263
  /** Language of the feed. */
257
264
  language?: string;
265
+ /** Allow control over the construction of BlogFeedItems */
266
+ createFeedItems?: CreateFeedItemsFn;
267
+ };
268
+
269
+ type DefaultCreateFeedItemsParams = {
270
+ blogPosts: BlogPost[];
271
+ siteConfig: DocusaurusConfig;
272
+ outDir: string;
273
+ };
274
+
275
+ type CreateFeedItemsFn = (
276
+ params: CreateFeedItemsParams,
277
+ ) => Promise<BlogFeedItem[]>;
278
+
279
+ type CreateFeedItemsParams = DefaultCreateFeedItemsParams & {
280
+ defaultCreateFeedItems: (
281
+ params: DefaultCreateFeedItemsParams,
282
+ ) => Promise<BlogFeedItem[]>;
258
283
  };
259
284
 
260
285
  /**
@@ -436,6 +461,8 @@ declare module '@docusaurus/plugin-content-blog' {
436
461
  content: string;
437
462
  };
438
463
 
464
+ export type BlogFeedItem = FeedItem;
465
+
439
466
  export type BlogPaginatedMetadata = {
440
467
  /** Title of the entire blog. */
441
468
  readonly blogTitle: string;