feat(v2): extract site title formatter to theme-common util (#3838)

This commit is contained in:
Bartosz Kaszubowski 2020-11-30 15:41:09 +01:00 committed by GitHub
parent 821a39bf2e
commit 21572ccd37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 23 deletions

View file

@ -22,6 +22,8 @@ export {isDocsPluginEnabled} from './utils/docsUtils';
export {isSamePath} from './utils/pathUtils';
export {useTitleFormatter} from './utils/generalUtils';
export {
useDocsPreferredVersion,
useDocsPreferredVersionByPluginId,

View file

@ -0,0 +1,15 @@
/**
* 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 useDocusaurusContext from '@docusaurus/useDocusaurusContext';
export const useTitleFormatter = (title?: string | undefined) => {
const {siteConfig = {}} = useDocusaurusContext();
const {title: siteTitle, titleDelimiter = '|'} = siteConfig;
return title && title.trim().length
? `${title.trim()} ${titleDelimiter} ${siteTitle}`
: siteTitle;
};