mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-29 18:27:56 +02:00
Co-authored-by: Joshua Chen <sidachen2003@gmail.com> Co-authored-by: sebastien <lorber.sebastien@gmail.com>
20 lines
688 B
TypeScript
20 lines
688 B
TypeScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
import useRouteContext from '@docusaurus/useRouteContext';
|
|
import type {BlogMetadata} from '@docusaurus/plugin-content-blog';
|
|
|
|
export function useBlogMetadata(): BlogMetadata {
|
|
const routeContext = useRouteContext();
|
|
const blogMetadata = routeContext?.data?.blogMetadata;
|
|
if (!blogMetadata) {
|
|
throw new Error(
|
|
"useBlogMetadata() can't be called on the current route because the blog metadata could not be found in route context",
|
|
);
|
|
}
|
|
return blogMetadata as BlogMetadata;
|
|
}
|