mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-04 01:09:20 +02:00
feat(theme): make it possible to provide your own page title formatter (#11090)
This commit is contained in:
parent
5b944d6b64
commit
730ce485ba
17 changed files with 386 additions and 107 deletions
36
website/src/theme/ThemeProvider/TitleFormatter/index.tsx
Normal file
36
website/src/theme/ThemeProvider/TitleFormatter/index.tsx
Normal file
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* 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 React, {type ComponentProps, type ReactNode} from 'react';
|
||||
import {TitleFormatterProvider} from '@docusaurus/theme-common/internal';
|
||||
import type {Props} from '@theme/ThemeProvider/TitleFormatter';
|
||||
|
||||
type FormatterProp = ComponentProps<typeof TitleFormatterProvider>['formatter'];
|
||||
|
||||
const formatter: FormatterProp = (params) => {
|
||||
// Custom title for dogfood plugin instances
|
||||
if (params.plugin.id.endsWith('tests')) {
|
||||
const pluginLabel = `${params.plugin.name.replace(
|
||||
'docusaurus-plugin-content-',
|
||||
'',
|
||||
)} plugin`;
|
||||
return `🐕 Dogfood - ${pluginLabel}`;
|
||||
}
|
||||
|
||||
// Default title otherwise
|
||||
return params.defaultFormatter(params);
|
||||
};
|
||||
|
||||
export default function ThemeProviderTitleFormatter({
|
||||
children,
|
||||
}: Props): ReactNode {
|
||||
return (
|
||||
<TitleFormatterProvider formatter={formatter}>
|
||||
{children}
|
||||
</TitleFormatterProvider>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue