@docusaurus/plugin-content-blog 3.3.2 → 3.5.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.
Files changed (62) hide show
  1. package/assets/atom.css +75 -0
  2. package/assets/atom.xsl +92 -0
  3. package/assets/rss.css +75 -0
  4. package/assets/rss.xsl +86 -0
  5. package/lib/authors.d.ts +9 -11
  6. package/lib/authors.js +42 -64
  7. package/lib/authorsMap.d.ts +23 -0
  8. package/lib/authorsMap.js +116 -0
  9. package/lib/authorsProblems.d.ts +21 -0
  10. package/lib/authorsProblems.js +51 -0
  11. package/lib/authorsSocials.d.ts +10 -0
  12. package/lib/authorsSocials.js +48 -0
  13. package/lib/blogUtils.d.ts +7 -12
  14. package/lib/blogUtils.js +44 -34
  15. package/lib/client/contexts.d.ts +33 -0
  16. package/lib/client/contexts.js +54 -0
  17. package/lib/client/index.d.ts +3 -3
  18. package/lib/client/index.js +3 -9
  19. package/lib/client/sidebarUtils.d.ts +21 -0
  20. package/lib/client/sidebarUtils.js +49 -0
  21. package/lib/client/sidebarUtils.test.d.ts +7 -0
  22. package/lib/client/sidebarUtils.test.js +43 -0
  23. package/lib/client/structuredDataUtils.d.ts +10 -0
  24. package/lib/client/structuredDataUtils.js +122 -0
  25. package/lib/feed.d.ts +8 -3
  26. package/lib/feed.js +111 -20
  27. package/lib/frontMatter.d.ts +0 -1
  28. package/lib/frontMatter.js +3 -2
  29. package/lib/index.d.ts +0 -1
  30. package/lib/index.js +132 -105
  31. package/lib/markdownLoader.js +3 -7
  32. package/lib/options.d.ts +4 -1
  33. package/lib/options.js +107 -26
  34. package/lib/props.d.ts +9 -2
  35. package/lib/props.js +23 -3
  36. package/lib/remark/footnoteIDFixer.js +1 -1
  37. package/lib/routes.d.ts +0 -1
  38. package/lib/routes.js +82 -14
  39. package/lib/translations.d.ts +0 -1
  40. package/lib/translations.js +2 -3
  41. package/lib/types.d.ts +1 -8
  42. package/package.json +13 -10
  43. package/src/authors.ts +56 -93
  44. package/src/authorsMap.ts +171 -0
  45. package/src/authorsProblems.ts +72 -0
  46. package/src/authorsSocials.ts +64 -0
  47. package/src/blogUtils.ts +51 -46
  48. package/src/client/contexts.tsx +95 -0
  49. package/src/client/index.tsx +24 -0
  50. package/src/client/sidebarUtils.test.ts +52 -0
  51. package/src/client/sidebarUtils.tsx +85 -0
  52. package/src/client/structuredDataUtils.ts +178 -0
  53. package/src/feed.ts +197 -18
  54. package/src/frontMatter.ts +2 -0
  55. package/src/index.ts +182 -137
  56. package/src/markdownLoader.ts +3 -7
  57. package/src/options.ts +132 -32
  58. package/src/plugin-content-blog.d.ts +252 -113
  59. package/src/props.ts +41 -1
  60. package/src/routes.ts +102 -12
  61. package/src/types.ts +1 -6
  62. package/src/client/index.ts +0 -20
package/src/routes.ts CHANGED
@@ -11,9 +11,15 @@ import {
11
11
  docuHash,
12
12
  aliasedSitePathToRelativePath,
13
13
  } from '@docusaurus/utils';
14
- import {shouldBeListed} from './blogUtils';
14
+ import {paginateBlogPosts, shouldBeListed} from './blogUtils';
15
15
 
16
- import {toTagProp, toTagsProp} from './props';
16
+ import {
17
+ toAuthorItemProp,
18
+ toBlogSidebarProp,
19
+ toTagProp,
20
+ toTagsProp,
21
+ } from './props';
22
+ import {groupBlogPostsByAuthorKey} from './authors';
17
23
  import type {
18
24
  PluginContentLoadedActions,
19
25
  RouteConfig,
@@ -26,7 +32,7 @@ import type {
26
32
  BlogContent,
27
33
  PluginOptions,
28
34
  BlogPost,
29
- BlogSidebar,
35
+ AuthorWithKey,
30
36
  } from '@docusaurus/plugin-content-blog';
31
37
 
32
38
  type CreateAllRoutesParam = {
@@ -55,11 +61,16 @@ export async function buildAllRoutes({
55
61
  blogListComponent,
56
62
  blogPostComponent,
57
63
  blogTagsListComponent,
64
+ blogAuthorsListComponent,
65
+ blogAuthorsPostsComponent,
58
66
  blogTagsPostsComponent,
59
67
  blogArchiveComponent,
60
68
  routeBasePath,
61
69
  archiveBasePath,
62
70
  blogTitle,
71
+ authorsBasePath,
72
+ postsPerPage,
73
+ blogDescription,
63
74
  } = options;
64
75
  const pluginId = options.id!;
65
76
  const {createData} = actions;
@@ -69,8 +80,15 @@ export async function buildAllRoutes({
69
80
  blogListPaginated,
70
81
  blogTags,
71
82
  blogTagsListPath,
83
+ authorsMap,
72
84
  } = content;
73
85
 
86
+ const authorsListPath = normalizeUrl([
87
+ baseUrl,
88
+ routeBasePath,
89
+ authorsBasePath,
90
+ ]);
91
+
74
92
  const listedBlogPosts = blogPosts.filter(shouldBeListed);
75
93
 
76
94
  const blogPostsById = _.keyBy(blogPosts, (post) => post.id);
@@ -88,17 +106,13 @@ export async function buildAllRoutes({
88
106
  : blogPosts.slice(0, options.blogSidebarCount);
89
107
 
90
108
  async function createSidebarModule() {
91
- const sidebar: BlogSidebar = {
92
- title: blogSidebarTitle,
93
- items: sidebarBlogPosts.map((blogPost) => ({
94
- title: blogPost.metadata.title,
95
- permalink: blogPost.metadata.permalink,
96
- unlisted: blogPost.metadata.unlisted,
97
- })),
98
- };
109
+ const sidebarProp = toBlogSidebarProp({
110
+ blogSidebarTitle,
111
+ blogPosts: sidebarBlogPosts,
112
+ });
99
113
  const modulePath = await createData(
100
114
  `blog-post-list-prop-${pluginId}.json`,
101
- sidebar,
115
+ sidebarProp,
102
116
  );
103
117
  return aliasedSource(modulePath);
104
118
  }
@@ -107,6 +121,7 @@ export async function buildAllRoutes({
107
121
  const blogMetadata: BlogMetadata = {
108
122
  blogBasePath: normalizeUrl([baseUrl, routeBasePath]),
109
123
  blogTitle,
124
+ authorsListPath,
110
125
  };
111
126
  const modulePath = await createData(
112
127
  `blogMetadata-${pluginId}.json`,
@@ -254,10 +269,85 @@ export async function buildAllRoutes({
254
269
  return [tagsListRoute, ...tagsPaginatedRoutes];
255
270
  }
256
271
 
272
+ function createAuthorsRoutes(): RouteConfig[] {
273
+ if (authorsMap === undefined || Object.keys(authorsMap).length === 0) {
274
+ return [];
275
+ }
276
+
277
+ const blogPostsByAuthorKey = groupBlogPostsByAuthorKey({
278
+ authorsMap,
279
+ blogPosts,
280
+ });
281
+ const authors = Object.values(authorsMap);
282
+
283
+ return [
284
+ createAuthorListRoute(),
285
+ ...authors.flatMap(createAuthorPaginatedRoute),
286
+ ];
287
+
288
+ function createAuthorListRoute(): RouteConfig {
289
+ return {
290
+ path: authorsListPath,
291
+ component: blogAuthorsListComponent,
292
+ exact: true,
293
+ modules: {
294
+ sidebar: sidebarModulePath,
295
+ },
296
+ props: {
297
+ authors: authors.map((author) =>
298
+ toAuthorItemProp({
299
+ author,
300
+ count: blogPostsByAuthorKey[author.key]?.length ?? 0,
301
+ }),
302
+ ),
303
+ },
304
+ context: {
305
+ blogMetadata: blogMetadataModulePath,
306
+ },
307
+ };
308
+ }
309
+
310
+ function createAuthorPaginatedRoute(author: AuthorWithKey): RouteConfig[] {
311
+ const authorBlogPosts = blogPostsByAuthorKey[author.key] ?? [];
312
+ if (!author.page) {
313
+ return [];
314
+ }
315
+
316
+ const pages = paginateBlogPosts({
317
+ blogPosts: authorBlogPosts,
318
+ basePageUrl: author.page.permalink,
319
+ blogDescription,
320
+ blogTitle,
321
+ pageBasePath: authorsBasePath,
322
+ postsPerPageOption: postsPerPage,
323
+ });
324
+
325
+ return pages.map(({metadata, items}) => {
326
+ return {
327
+ path: metadata.permalink,
328
+ component: blogAuthorsPostsComponent,
329
+ exact: true,
330
+ modules: {
331
+ items: blogPostItemsModule(items),
332
+ sidebar: sidebarModulePath,
333
+ },
334
+ props: {
335
+ author: toAuthorItemProp({author, count: authorBlogPosts.length}),
336
+ listMetadata: metadata,
337
+ },
338
+ context: {
339
+ blogMetadata: blogMetadataModulePath,
340
+ },
341
+ };
342
+ });
343
+ }
344
+ }
345
+
257
346
  return [
258
347
  ...createBlogPostRoutes(),
259
348
  ...createBlogPostsPaginatedRoutes(),
260
349
  ...createTagsRoutes(),
261
350
  ...createArchiveRoute(),
351
+ ...createAuthorsRoutes(),
262
352
  ];
263
353
  }
package/src/types.ts CHANGED
@@ -5,15 +5,10 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import type {BrokenMarkdownLink, ContentPaths} from '@docusaurus/utils';
8
+ import type {ContentPaths} from '@docusaurus/utils';
9
9
 
10
10
  export type BlogContentPaths = ContentPaths;
11
11
 
12
- export type BlogBrokenMarkdownLink = BrokenMarkdownLink<BlogContentPaths>;
13
12
  export type BlogMarkdownLoaderOptions = {
14
- siteDir: string;
15
- contentPaths: BlogContentPaths;
16
13
  truncateMarker: RegExp;
17
- sourceToPermalink: {[aliasedPath: string]: string};
18
- onBrokenMarkdownLink: (brokenMarkdownLink: BlogBrokenMarkdownLink) => void;
19
14
  };
@@ -1,20 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import useRouteContext from '@docusaurus/useRouteContext';
9
- import type {BlogMetadata} from '@docusaurus/plugin-content-blog';
10
-
11
- export function useBlogMetadata(): BlogMetadata {
12
- const routeContext = useRouteContext();
13
- const blogMetadata = routeContext?.data?.blogMetadata;
14
- if (!blogMetadata) {
15
- throw new Error(
16
- "useBlogMetadata() can't be called on the current route because the blog metadata could not be found in route context",
17
- );
18
- }
19
- return blogMetadata as BlogMetadata;
20
- }