@docusaurus/plugin-content-blog 0.0.0-5833 → 0.0.0-5835

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.
@@ -0,0 +1,8 @@
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
+ import type { BlogMetadata } from '@docusaurus/plugin-content-blog';
8
+ export declare function useBlogMetadata(): BlogMetadata;
@@ -0,0 +1,15 @@
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
+ import useRouteContext from '@docusaurus/useRouteContext';
8
+ export function useBlogMetadata() {
9
+ const routeContext = useRouteContext();
10
+ const blogMetadata = routeContext?.data?.blogMetadata;
11
+ if (!blogMetadata) {
12
+ throw new Error("useBlogMetadata() can't be called on the current route because the blog metadata could not be found in route context");
13
+ }
14
+ return blogMetadata;
15
+ }
package/lib/index.js CHANGED
@@ -104,7 +104,7 @@ async function pluginContentBlog(context, options) {
104
104
  };
105
105
  },
106
106
  async contentLoaded({ content: blogContents, actions }) {
107
- const { blogListComponent, blogPostComponent, blogTagsListComponent, blogTagsPostsComponent, blogArchiveComponent, routeBasePath, archiveBasePath, } = options;
107
+ const { blogListComponent, blogPostComponent, blogTagsListComponent, blogTagsPostsComponent, blogArchiveComponent, routeBasePath, archiveBasePath, blogTitle, } = options;
108
108
  const { addRoute, createData } = actions;
109
109
  const { blogSidebarTitle, blogPosts, blogListPaginated, blogTags, blogTagsListPath, } = blogContents;
110
110
  const listedBlogPosts = blogPosts.filter(blogUtils_1.shouldBeListed);
@@ -155,6 +155,11 @@ async function pluginContentBlog(context, options) {
155
155
  unlisted: blogPost.metadata.unlisted,
156
156
  })),
157
157
  }, null, 2));
158
+ const blogMetadata = {
159
+ blogBasePath: (0, utils_1.normalizeUrl)([baseUrl, routeBasePath]),
160
+ blogTitle,
161
+ };
162
+ const blogMetadataPath = await createData(`blogMetadata-${pluginId}.json`, JSON.stringify(blogMetadata, null, 2));
158
163
  // Create routes for blog entries.
159
164
  await Promise.all(blogPosts.map(async (blogPost) => {
160
165
  const { id, metadata } = blogPost;
@@ -170,6 +175,9 @@ async function pluginContentBlog(context, options) {
170
175
  sidebar: aliasedSource(sidebarProp),
171
176
  content: metadata.source,
172
177
  },
178
+ context: {
179
+ blogMetadata: aliasedSource(blogMetadataPath),
180
+ },
173
181
  });
174
182
  blogItemsToMetadata[id] = metadata;
175
183
  }));
package/package.json CHANGED
@@ -1,12 +1,24 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-blog",
3
- "version": "0.0.0-5833",
3
+ "version": "0.0.0-5835",
4
4
  "description": "Blog plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/plugin-content-blog.d.ts",
7
+ "exports": {
8
+ "./lib/*": "./lib/*",
9
+ "./src/*": "./src/*",
10
+ "./client": {
11
+ "type": "./lib/client/index.d.ts",
12
+ "default": "./lib/client/index.js"
13
+ },
14
+ ".": {
15
+ "types": "./src/plugin-content-blog.d.ts",
16
+ "default": "./lib/index.js"
17
+ }
18
+ },
7
19
  "scripts": {
8
- "build": "tsc",
9
- "watch": "tsc --watch",
20
+ "build": "tsc --build",
21
+ "watch": "tsc --build --watch",
10
22
  "test:generate-build-snap": "yarn docusaurus build src/__tests__/__fixtures__/website --out-dir build-snap && yarn rimraf src/__tests__/__fixtures__/website/.docusaurus && yarn rimraf src/__tests__/__fixtures__/website/build-snap/assets && git add src/__tests__/__fixtures__/website/build-snap"
11
23
  },
12
24
  "repository": {
@@ -19,13 +31,13 @@
19
31
  },
20
32
  "license": "MIT",
21
33
  "dependencies": {
22
- "@docusaurus/core": "0.0.0-5833",
23
- "@docusaurus/logger": "0.0.0-5833",
24
- "@docusaurus/mdx-loader": "0.0.0-5833",
25
- "@docusaurus/types": "0.0.0-5833",
26
- "@docusaurus/utils": "0.0.0-5833",
27
- "@docusaurus/utils-common": "0.0.0-5833",
28
- "@docusaurus/utils-validation": "0.0.0-5833",
34
+ "@docusaurus/core": "0.0.0-5835",
35
+ "@docusaurus/logger": "0.0.0-5835",
36
+ "@docusaurus/mdx-loader": "0.0.0-5835",
37
+ "@docusaurus/types": "0.0.0-5835",
38
+ "@docusaurus/utils": "0.0.0-5835",
39
+ "@docusaurus/utils-common": "0.0.0-5835",
40
+ "@docusaurus/utils-validation": "0.0.0-5835",
29
41
  "cheerio": "^1.0.0-rc.12",
30
42
  "feed": "^4.2.2",
31
43
  "fs-extra": "^11.1.1",
@@ -44,5 +56,5 @@
44
56
  "engines": {
45
57
  "node": ">=18.0"
46
58
  },
47
- "gitHead": "e2881302a2bbc9d1b3277dc5729c5adba3d5684f"
59
+ "gitHead": "63065664a850451b45d9b9fcaaf110388d1e39d4"
48
60
  }
@@ -0,0 +1,20 @@
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
+ }
package/src/index.ts CHANGED
@@ -42,6 +42,7 @@ import type {
42
42
  BlogTags,
43
43
  BlogContent,
44
44
  BlogPaginated,
45
+ BlogMetadata,
45
46
  } from '@docusaurus/plugin-content-blog';
46
47
 
47
48
  export default async function pluginContentBlog(
@@ -182,6 +183,7 @@ export default async function pluginContentBlog(
182
183
  blogArchiveComponent,
183
184
  routeBasePath,
184
185
  archiveBasePath,
186
+ blogTitle,
185
187
  } = options;
186
188
 
187
189
  const {addRoute, createData} = actions;
@@ -257,6 +259,15 @@ export default async function pluginContentBlog(
257
259
  ),
258
260
  );
259
261
 
262
+ const blogMetadata: BlogMetadata = {
263
+ blogBasePath: normalizeUrl([baseUrl, routeBasePath]),
264
+ blogTitle,
265
+ };
266
+ const blogMetadataPath = await createData(
267
+ `blogMetadata-${pluginId}.json`,
268
+ JSON.stringify(blogMetadata, null, 2),
269
+ );
270
+
260
271
  // Create routes for blog entries.
261
272
  await Promise.all(
262
273
  blogPosts.map(async (blogPost) => {
@@ -276,6 +287,9 @@ export default async function pluginContentBlog(
276
287
  sidebar: aliasedSource(sidebarProp),
277
288
  content: metadata.source,
278
289
  },
290
+ context: {
291
+ blogMetadata: aliasedSource(blogMetadataPath),
292
+ },
279
293
  });
280
294
 
281
295
  blogItemsToMetadata[id] = metadata;
@@ -5,6 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
+ /// <reference types="@docusaurus/module-type-aliases" />
9
+
8
10
  declare module '@docusaurus/plugin-content-blog' {
9
11
  import type {LoadedMDXContent} from '@docusaurus/mdx-loader';
10
12
  import type {MDXOptions} from '@docusaurus/mdx-loader';
@@ -466,6 +468,13 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the
466
468
  blogTagsListPath: string;
467
469
  };
468
470
 
471
+ export type BlogMetadata = {
472
+ /** the path to the base of the blog */
473
+ blogBasePath: string;
474
+ /** title of the overall blog */
475
+ blogTitle: string;
476
+ };
477
+
469
478
  export type BlogTags = {
470
479
  [permalink: string]: BlogTag;
471
480
  };
@@ -537,6 +546,7 @@ declare module '@theme/BlogPostPage' {
537
546
  BlogPostFrontMatter,
538
547
  BlogSidebar,
539
548
  PropBlogPostContent,
549
+ BlogMetadata,
540
550
  } from '@docusaurus/plugin-content-blog';
541
551
 
542
552
  export type FrontMatter = BlogPostFrontMatter;
@@ -548,6 +558,8 @@ declare module '@theme/BlogPostPage' {
548
558
  readonly sidebar: BlogSidebar;
549
559
  /** Content of this post as an MDX component, with useful metadata. */
550
560
  readonly content: Content;
561
+ /** Metadata about the blog. */
562
+ readonly blogMetadata: BlogMetadata;
551
563
  }
552
564
 
553
565
  export default function BlogPostPage(props: Props): JSX.Element;
@@ -557,6 +569,10 @@ declare module '@theme/BlogPostPage/Metadata' {
557
569
  export default function BlogPostPageMetadata(): JSX.Element;
558
570
  }
559
571
 
572
+ declare module '@theme/BlogPostPage/StructuredData' {
573
+ export default function BlogPostStructuredData(): JSX.Element;
574
+ }
575
+
560
576
  declare module '@theme/BlogListPage' {
561
577
  import type {Content} from '@theme/BlogPostPage';
562
578
  import type {
@@ -579,6 +595,28 @@ declare module '@theme/BlogListPage' {
579
595
  export default function BlogListPage(props: Props): JSX.Element;
580
596
  }
581
597
 
598
+ declare module '@theme/BlogListPage/StructuredData' {
599
+ import type {Content} from '@theme/BlogPostPage';
600
+ import type {
601
+ BlogSidebar,
602
+ BlogPaginatedMetadata,
603
+ } from '@docusaurus/plugin-content-blog';
604
+
605
+ export interface Props {
606
+ /** Blog sidebar. */
607
+ readonly sidebar: BlogSidebar;
608
+ /** Metadata of the current listing page. */
609
+ readonly metadata: BlogPaginatedMetadata;
610
+ /**
611
+ * Array of blog posts included on this page. Every post's metadata is also
612
+ * available.
613
+ */
614
+ readonly items: readonly {readonly content: Content}[];
615
+ }
616
+
617
+ export default function BlogListPageStructuredData(props: Props): JSX.Element;
618
+ }
619
+
582
620
  declare module '@theme/BlogTagsListPage' {
583
621
  import type {BlogSidebar} from '@docusaurus/plugin-content-blog';
584
622
  import type {TagsListItem} from '@docusaurus/utils';