@docusaurus/plugin-content-blog 3.0.0 → 3.1.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/authors.d.ts CHANGED
@@ -17,6 +17,7 @@ export declare function getAuthorsMap(params: {
17
17
  type AuthorsParam = {
18
18
  frontMatter: BlogPostFrontMatter;
19
19
  authorsMap: AuthorsMap | undefined;
20
+ baseUrl: string;
20
21
  };
21
22
  export declare function getBlogPostAuthors(params: AuthorsParam): Author[];
22
23
  export {};
package/lib/authors.js CHANGED
@@ -44,13 +44,21 @@ async function getAuthorsMap(params) {
44
44
  }, validateAuthorsMap);
45
45
  }
46
46
  exports.getAuthorsMap = getAuthorsMap;
47
+ function normalizeImageUrl({ imageURL, baseUrl, }) {
48
+ return imageURL?.startsWith('/')
49
+ ? (0, utils_1.normalizeUrl)([baseUrl, imageURL])
50
+ : imageURL;
51
+ }
47
52
  // Legacy v1/early-v2 front matter fields
48
53
  // We may want to deprecate those in favor of using only frontMatter.authors
49
- function getFrontMatterAuthorLegacy(frontMatter) {
54
+ function getFrontMatterAuthorLegacy({ baseUrl, frontMatter, }) {
50
55
  const name = frontMatter.author;
51
56
  const title = frontMatter.author_title ?? frontMatter.authorTitle;
52
57
  const url = frontMatter.author_url ?? frontMatter.authorURL;
53
- const imageURL = frontMatter.author_image_url ?? frontMatter.authorImageURL;
58
+ const imageURL = normalizeImageUrl({
59
+ imageURL: frontMatter.author_image_url ?? frontMatter.authorImageURL,
60
+ baseUrl,
61
+ });
54
62
  if (name || title || url || imageURL) {
55
63
  return {
56
64
  name,
@@ -105,18 +113,25 @@ ${Object.keys(authorsMap)
105
113
  }
106
114
  return frontMatterAuthors.map(toAuthor);
107
115
  }
116
+ function fixAuthorImageBaseURL(authors, { baseUrl }) {
117
+ return authors.map((author) => ({
118
+ ...author,
119
+ imageURL: normalizeImageUrl({ imageURL: author.imageURL, baseUrl }),
120
+ }));
121
+ }
108
122
  function getBlogPostAuthors(params) {
109
- const authorLegacy = getFrontMatterAuthorLegacy(params.frontMatter);
123
+ const authorLegacy = getFrontMatterAuthorLegacy(params);
110
124
  const authors = getFrontMatterAuthors(params);
125
+ const updatedAuthors = fixAuthorImageBaseURL(authors, params);
111
126
  if (authorLegacy) {
112
127
  // Technically, we could allow mixing legacy/authors front matter, but do we
113
128
  // really want to?
114
- if (authors.length > 0) {
129
+ if (updatedAuthors.length > 0) {
115
130
  throw new Error(`To declare blog post authors, use the 'authors' front matter in priority.
116
131
  Don't mix 'authors' with other existing 'author_*' front matter. Choose one or the other, not both at the same time.`);
117
132
  }
118
133
  return [authorLegacy];
119
134
  }
120
- return authors;
135
+ return updatedAuthors;
121
136
  }
122
137
  exports.getBlogPostAuthors = getBlogPostAuthors;
package/lib/blogUtils.js CHANGED
@@ -111,10 +111,13 @@ function formatBlogPostDate(locale, date, calendar) {
111
111
  throw err;
112
112
  }
113
113
  }
114
- async function parseBlogPostMarkdownFile(blogSourceAbsolute) {
115
- const markdownString = await fs_extra_1.default.readFile(blogSourceAbsolute, 'utf-8');
114
+ async function parseBlogPostMarkdownFile({ filePath, parseFrontMatter, }) {
115
+ const fileContent = await fs_extra_1.default.readFile(filePath, 'utf-8');
116
116
  try {
117
- const result = (0, utils_1.parseMarkdownString)(markdownString, {
117
+ const result = await (0, utils_1.parseMarkdownFile)({
118
+ filePath,
119
+ fileContent,
120
+ parseFrontMatter,
118
121
  removeContentTitle: true,
119
122
  });
120
123
  return {
@@ -123,18 +126,21 @@ async function parseBlogPostMarkdownFile(blogSourceAbsolute) {
123
126
  };
124
127
  }
125
128
  catch (err) {
126
- logger_1.default.error `Error while parsing blog post file path=${blogSourceAbsolute}.`;
129
+ logger_1.default.error `Error while parsing blog post file path=${filePath}.`;
127
130
  throw err;
128
131
  }
129
132
  }
130
133
  const defaultReadingTime = ({ content, options }) => (0, reading_time_1.default)(content, options).minutes;
131
134
  async function processBlogSourceFile(blogSourceRelative, contentPaths, context, options, authorsMap) {
132
- const { siteConfig: { baseUrl }, siteDir, i18n, } = context;
135
+ const { siteConfig: { baseUrl, markdown: { parseFrontMatter }, }, siteDir, i18n, } = context;
133
136
  const { routeBasePath, tagsBasePath: tagsRouteBasePath, truncateMarker, showReadingTime, editUrl, } = options;
134
137
  // Lookup in localized folder in priority
135
138
  const blogDirPath = await (0, utils_1.getFolderContainingFile)((0, utils_1.getContentPathList)(contentPaths), blogSourceRelative);
136
139
  const blogSourceAbsolute = path_1.default.join(blogDirPath, blogSourceRelative);
137
- const { frontMatter, content, contentTitle, excerpt } = await parseBlogPostMarkdownFile(blogSourceAbsolute);
140
+ const { frontMatter, content, contentTitle, excerpt } = await parseBlogPostMarkdownFile({
141
+ filePath: blogSourceAbsolute,
142
+ parseFrontMatter,
143
+ });
138
144
  const aliasedSource = (0, utils_1.aliasedSitePath)(blogSourceAbsolute, siteDir);
139
145
  const draft = (0, utils_1.isDraft)({ frontMatter });
140
146
  const unlisted = (0, utils_1.isUnlisted)({ frontMatter });
@@ -204,7 +210,7 @@ async function processBlogSourceFile(blogSourceRelative, contentPaths, context,
204
210
  routeBasePath,
205
211
  tagsRouteBasePath,
206
212
  ]);
207
- const authors = (0, authors_1.getBlogPostAuthors)({ authorsMap, frontMatter });
213
+ const authors = (0, authors_1.getBlogPostAuthors)({ authorsMap, frontMatter, baseUrl });
208
214
  return {
209
215
  id: slug,
210
216
  metadata: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-blog",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Blog plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/plugin-content-blog.d.ts",
@@ -19,13 +19,13 @@
19
19
  },
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@docusaurus/core": "3.0.0",
23
- "@docusaurus/logger": "3.0.0",
24
- "@docusaurus/mdx-loader": "3.0.0",
25
- "@docusaurus/types": "3.0.0",
26
- "@docusaurus/utils": "3.0.0",
27
- "@docusaurus/utils-common": "3.0.0",
28
- "@docusaurus/utils-validation": "3.0.0",
22
+ "@docusaurus/core": "3.1.0",
23
+ "@docusaurus/logger": "3.1.0",
24
+ "@docusaurus/mdx-loader": "3.1.0",
25
+ "@docusaurus/types": "3.1.0",
26
+ "@docusaurus/utils": "3.1.0",
27
+ "@docusaurus/utils-common": "3.1.0",
28
+ "@docusaurus/utils-validation": "3.1.0",
29
29
  "cheerio": "^1.0.0-rc.12",
30
30
  "feed": "^4.2.2",
31
31
  "fs-extra": "^11.1.1",
@@ -44,5 +44,5 @@
44
44
  "engines": {
45
45
  "node": ">=18.0"
46
46
  },
47
- "gitHead": "ca8b4638c47119d38838656c4a11ee3a5e7ba6f2"
47
+ "gitHead": "a5e675821f0e8b70b591fcebf19fd60a70d55548"
48
48
  }
package/src/authors.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import {getDataFileData} from '@docusaurus/utils';
8
+ import {getDataFileData, normalizeUrl} from '@docusaurus/utils';
9
9
  import {Joi, URISchema} from '@docusaurus/utils-validation';
10
10
  import type {BlogContentPaths} from './types';
11
11
  import type {
@@ -68,17 +68,37 @@ export async function getAuthorsMap(params: {
68
68
  type AuthorsParam = {
69
69
  frontMatter: BlogPostFrontMatter;
70
70
  authorsMap: AuthorsMap | undefined;
71
+ baseUrl: string;
71
72
  };
72
73
 
74
+ function normalizeImageUrl({
75
+ imageURL,
76
+ baseUrl,
77
+ }: {
78
+ imageURL: string | undefined;
79
+ baseUrl: string;
80
+ }) {
81
+ return imageURL?.startsWith('/')
82
+ ? normalizeUrl([baseUrl, imageURL])
83
+ : imageURL;
84
+ }
85
+
73
86
  // Legacy v1/early-v2 front matter fields
74
87
  // We may want to deprecate those in favor of using only frontMatter.authors
75
- function getFrontMatterAuthorLegacy(
76
- frontMatter: BlogPostFrontMatter,
77
- ): Author | undefined {
88
+ function getFrontMatterAuthorLegacy({
89
+ baseUrl,
90
+ frontMatter,
91
+ }: {
92
+ baseUrl: string;
93
+ frontMatter: BlogPostFrontMatter;
94
+ }): Author | undefined {
78
95
  const name = frontMatter.author;
79
96
  const title = frontMatter.author_title ?? frontMatter.authorTitle;
80
97
  const url = frontMatter.author_url ?? frontMatter.authorURL;
81
- const imageURL = frontMatter.author_image_url ?? frontMatter.authorImageURL;
98
+ const imageURL = normalizeImageUrl({
99
+ imageURL: frontMatter.author_image_url ?? frontMatter.authorImageURL,
100
+ baseUrl,
101
+ });
82
102
 
83
103
  if (name || title || url || imageURL) {
84
104
  return {
@@ -148,14 +168,26 @@ ${Object.keys(authorsMap)
148
168
  return frontMatterAuthors.map(toAuthor);
149
169
  }
150
170
 
171
+ function fixAuthorImageBaseURL(
172
+ authors: Author[],
173
+ {baseUrl}: {baseUrl: string},
174
+ ) {
175
+ return authors.map((author) => ({
176
+ ...author,
177
+ imageURL: normalizeImageUrl({imageURL: author.imageURL, baseUrl}),
178
+ }));
179
+ }
180
+
151
181
  export function getBlogPostAuthors(params: AuthorsParam): Author[] {
152
- const authorLegacy = getFrontMatterAuthorLegacy(params.frontMatter);
182
+ const authorLegacy = getFrontMatterAuthorLegacy(params);
153
183
  const authors = getFrontMatterAuthors(params);
154
184
 
185
+ const updatedAuthors = fixAuthorImageBaseURL(authors, params);
186
+
155
187
  if (authorLegacy) {
156
188
  // Technically, we could allow mixing legacy/authors front matter, but do we
157
189
  // really want to?
158
- if (authors.length > 0) {
190
+ if (updatedAuthors.length > 0) {
159
191
  throw new Error(
160
192
  `To declare blog post authors, use the 'authors' front matter in priority.
161
193
  Don't mix 'authors' with other existing 'author_*' front matter. Choose one or the other, not both at the same time.`,
@@ -164,5 +196,5 @@ Don't mix 'authors' with other existing 'author_*' front matter. Choose one or t
164
196
  return [authorLegacy];
165
197
  }
166
198
 
167
- return authors;
199
+ return updatedAuthors;
168
200
  }
package/src/blogUtils.ts CHANGED
@@ -11,7 +11,7 @@ import _ from 'lodash';
11
11
  import logger from '@docusaurus/logger';
12
12
  import readingTime from 'reading-time';
13
13
  import {
14
- parseMarkdownString,
14
+ parseMarkdownFile,
15
15
  normalizeUrl,
16
16
  aliasedSitePath,
17
17
  getEditUrl,
@@ -29,7 +29,7 @@ import {
29
29
  } from '@docusaurus/utils';
30
30
  import {validateBlogPostFrontMatter} from './frontMatter';
31
31
  import {type AuthorsMap, getAuthorsMap, getBlogPostAuthors} from './authors';
32
- import type {LoadContext} from '@docusaurus/types';
32
+ import type {LoadContext, ParseFrontMatter} from '@docusaurus/types';
33
33
  import type {
34
34
  PluginOptions,
35
35
  ReadingTimeFunction,
@@ -180,10 +180,19 @@ function formatBlogPostDate(
180
180
  }
181
181
  }
182
182
 
183
- async function parseBlogPostMarkdownFile(blogSourceAbsolute: string) {
184
- const markdownString = await fs.readFile(blogSourceAbsolute, 'utf-8');
183
+ async function parseBlogPostMarkdownFile({
184
+ filePath,
185
+ parseFrontMatter,
186
+ }: {
187
+ filePath: string;
188
+ parseFrontMatter: ParseFrontMatter;
189
+ }) {
190
+ const fileContent = await fs.readFile(filePath, 'utf-8');
185
191
  try {
186
- const result = parseMarkdownString(markdownString, {
192
+ const result = await parseMarkdownFile({
193
+ filePath,
194
+ fileContent,
195
+ parseFrontMatter,
187
196
  removeContentTitle: true,
188
197
  });
189
198
  return {
@@ -191,7 +200,7 @@ async function parseBlogPostMarkdownFile(blogSourceAbsolute: string) {
191
200
  frontMatter: validateBlogPostFrontMatter(result.frontMatter),
192
201
  };
193
202
  } catch (err) {
194
- logger.error`Error while parsing blog post file path=${blogSourceAbsolute}.`;
203
+ logger.error`Error while parsing blog post file path=${filePath}.`;
195
204
  throw err;
196
205
  }
197
206
  }
@@ -207,7 +216,10 @@ async function processBlogSourceFile(
207
216
  authorsMap?: AuthorsMap,
208
217
  ): Promise<BlogPost | undefined> {
209
218
  const {
210
- siteConfig: {baseUrl},
219
+ siteConfig: {
220
+ baseUrl,
221
+ markdown: {parseFrontMatter},
222
+ },
211
223
  siteDir,
212
224
  i18n,
213
225
  } = context;
@@ -228,7 +240,10 @@ async function processBlogSourceFile(
228
240
  const blogSourceAbsolute = path.join(blogDirPath, blogSourceRelative);
229
241
 
230
242
  const {frontMatter, content, contentTitle, excerpt} =
231
- await parseBlogPostMarkdownFile(blogSourceAbsolute);
243
+ await parseBlogPostMarkdownFile({
244
+ filePath: blogSourceAbsolute,
245
+ parseFrontMatter,
246
+ });
232
247
 
233
248
  const aliasedSource = aliasedSitePath(blogSourceAbsolute, siteDir);
234
249
 
@@ -319,7 +334,7 @@ async function processBlogSourceFile(
319
334
  routeBasePath,
320
335
  tagsRouteBasePath,
321
336
  ]);
322
- const authors = getBlogPostAuthors({authorsMap, frontMatter});
337
+ const authors = getBlogPostAuthors({authorsMap, frontMatter, baseUrl});
323
338
 
324
339
  return {
325
340
  id: slug,