@docusaurus/plugin-content-blog 0.0.0-5767 → 0.0.0-5769

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
@@ -204,7 +204,7 @@ async function processBlogSourceFile(blogSourceRelative, contentPaths, context,
204
204
  routeBasePath,
205
205
  tagsRouteBasePath,
206
206
  ]);
207
- const authors = (0, authors_1.getBlogPostAuthors)({ authorsMap, frontMatter });
207
+ const authors = (0, authors_1.getBlogPostAuthors)({ authorsMap, frontMatter, baseUrl });
208
208
  return {
209
209
  id: slug,
210
210
  metadata: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-blog",
3
- "version": "0.0.0-5767",
3
+ "version": "0.0.0-5769",
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": "0.0.0-5767",
23
- "@docusaurus/logger": "0.0.0-5767",
24
- "@docusaurus/mdx-loader": "0.0.0-5767",
25
- "@docusaurus/types": "0.0.0-5767",
26
- "@docusaurus/utils": "0.0.0-5767",
27
- "@docusaurus/utils-common": "0.0.0-5767",
28
- "@docusaurus/utils-validation": "0.0.0-5767",
22
+ "@docusaurus/core": "0.0.0-5769",
23
+ "@docusaurus/logger": "0.0.0-5769",
24
+ "@docusaurus/mdx-loader": "0.0.0-5769",
25
+ "@docusaurus/types": "0.0.0-5769",
26
+ "@docusaurus/utils": "0.0.0-5769",
27
+ "@docusaurus/utils-common": "0.0.0-5769",
28
+ "@docusaurus/utils-validation": "0.0.0-5769",
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": "fee9e248db0c480487fa9c7e6777873bea334e01"
47
+ "gitHead": "2a3c275804d5ab8a5b932644888d453a6c10e745"
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
@@ -319,7 +319,7 @@ async function processBlogSourceFile(
319
319
  routeBasePath,
320
320
  tagsRouteBasePath,
321
321
  ]);
322
- const authors = getBlogPostAuthors({authorsMap, frontMatter});
322
+ const authors = getBlogPostAuthors({authorsMap, frontMatter, baseUrl});
323
323
 
324
324
  return {
325
325
  id: slug,