@docusaurus/theme-common 3.7.0-canary-6291 → 3.7.0-canary-6292
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.
- package/lib/internal.d.ts +1 -1
- package/lib/internal.d.ts.map +1 -1
- package/lib/internal.js +1 -1
- package/lib/internal.js.map +1 -1
- package/lib/utils/metadataUtils.d.ts.map +1 -1
- package/lib/utils/metadataUtils.js +37 -20
- package/lib/utils/metadataUtils.js.map +1 -1
- package/lib/utils/titleFormatterUtils.d.ts +59 -0
- package/lib/utils/titleFormatterUtils.d.ts.map +1 -0
- package/lib/utils/titleFormatterUtils.js +51 -0
- package/lib/utils/titleFormatterUtils.js.map +1 -0
- package/package.json +8 -8
- package/src/internal.ts +4 -1
- package/src/utils/metadataUtils.tsx +57 -27
- package/src/utils/titleFormatterUtils.tsx +122 -0
- package/lib/utils/generalUtils.d.ts +0 -11
- package/lib/utils/generalUtils.d.ts.map +0 -1
- package/lib/utils/generalUtils.js +0 -18
- package/lib/utils/generalUtils.js.map +0 -1
- package/src/utils/generalUtils.ts +0 -19
package/lib/internal.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export { ColorModeProvider } from './contexts/colorMode';
|
|
|
14
14
|
export { useAlternatePageUtils } from './utils/useAlternatePageUtils';
|
|
15
15
|
export { type CodeBlockMetadata, createCodeBlockMetadata, getPrismCssVariables, CodeBlockContextProvider, useCodeBlockContext, } from './utils/codeBlockUtils';
|
|
16
16
|
export { DEFAULT_SEARCH_TAG } from './utils/searchUtils';
|
|
17
|
-
export { useTitleFormatter } from './utils/
|
|
17
|
+
export { TitleFormatterProvider, useTitleFormatter, } from './utils/titleFormatterUtils';
|
|
18
18
|
export { useLocationChange } from './utils/useLocationChange';
|
|
19
19
|
export { useLocalPathname } from './utils/useLocalPathname';
|
|
20
20
|
export { useHistoryPopHandler, useHistorySelector, useQueryStringValue, } from './utils/historyUtils';
|
package/lib/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,cAAc,SAAS,CAAC;AAExB,OAAO,EACL,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAC,OAAO,EAAE,oBAAoB,EAAC,MAAM,mBAAmB,CAAC;AAChE,YAAY,EAAC,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAEzE,OAAO,EAAC,sBAAsB,EAAC,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAC,sBAAsB,EAAC,MAAM,wCAAwC,CAAC;AAE9E,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAC,qBAAqB,EAAC,MAAM,+BAA+B,CAAC;AAEpE,OAAO,EACL,KAAK,iBAAiB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAC,kBAAkB,EAAC,MAAM,qBAAqB,CAAC;AAEvD,OAAO,
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,cAAc,SAAS,CAAC;AAExB,OAAO,EACL,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAC,OAAO,EAAE,oBAAoB,EAAC,MAAM,mBAAmB,CAAC;AAChE,YAAY,EAAC,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAEzE,OAAO,EAAC,sBAAsB,EAAC,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAC,sBAAsB,EAAC,MAAM,wCAAwC,CAAC;AAE9E,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAEvD,OAAO,E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,4BAA4B,CAAC;AAE9D,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,iCAAiC,EACjC,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,iCAAiC,CAAC"}
|
package/lib/internal.js
CHANGED
|
@@ -24,7 +24,7 @@ export { ColorModeProvider } from './contexts/colorMode';
|
|
|
24
24
|
export { useAlternatePageUtils } from './utils/useAlternatePageUtils';
|
|
25
25
|
export { createCodeBlockMetadata, getPrismCssVariables, CodeBlockContextProvider, useCodeBlockContext, } from './utils/codeBlockUtils';
|
|
26
26
|
export { DEFAULT_SEARCH_TAG } from './utils/searchUtils';
|
|
27
|
-
export { useTitleFormatter } from './utils/
|
|
27
|
+
export { TitleFormatterProvider, useTitleFormatter, } from './utils/titleFormatterUtils';
|
|
28
28
|
export { useLocationChange } from './utils/useLocationChange';
|
|
29
29
|
export { useLocalPathname } from './utils/useLocalPathname';
|
|
30
30
|
export { useHistoryPopHandler, useHistorySelector, useQueryStringValue, } from './utils/historyUtils';
|
package/lib/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,4EAA4E;AAC5E,6EAA6E;AAC7E,2EAA2E;AAC3E,uDAAuD;AACvD,EAAE;AACF,6DAA6D;AAC7D,gFAAgF;AAChF,yEAAyE;AACzE,oDAAoD;AACpD,EAAE;AACF,gDAAgD;AAChD,cAAc,SAAS,CAAC;AAExB,OAAO,EACL,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAC,OAAO,EAAE,oBAAoB,EAAC,MAAM,mBAAmB,CAAC;AAGhE,OAAO,EAAC,sBAAsB,EAAC,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAC,sBAAsB,EAAC,MAAM,wCAAwC,CAAC;AAE9E,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAEv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AE,GAAG,MAAM,CAAC;IAC/C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;CAC/B,CAAC;
|
|
1
|
+
{"version":3,"file":"metadataUtils.d.ts","sourceRoot":"","sources":["../../src/utils/metadataUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAAC,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAO5C,KAAK,iBAAiB,GAAG;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC;IAC/C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;CAC/B,CAAC;AAmDF;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,WAAW,EACX,QAAQ,EACR,KAAK,EACL,QAAQ,GACT,EAAE,iBAAiB,GAAG,SAAS,CAU/B;AAID;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,SAAS,EAAE,aAAa,EACxB,QAAQ,GACT,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,SAAS,CAWZ;AASD;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,EAC1C,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,SAAS,CASZ"}
|
|
@@ -9,31 +9,48 @@ import clsx from 'clsx';
|
|
|
9
9
|
import Head from '@docusaurus/Head';
|
|
10
10
|
import useRouteContext from '@docusaurus/useRouteContext';
|
|
11
11
|
import { useBaseUrlUtils } from '@docusaurus/useBaseUrl';
|
|
12
|
-
import { useTitleFormatter } from './
|
|
12
|
+
import { useTitleFormatter } from './titleFormatterUtils';
|
|
13
|
+
function TitleMetadata({ title }) {
|
|
14
|
+
const titleFormatter = useTitleFormatter();
|
|
15
|
+
const formattedTitle = titleFormatter.format(title);
|
|
16
|
+
return (<Head>
|
|
17
|
+
<title>{formattedTitle}</title>
|
|
18
|
+
<meta property="og:title" content={formattedTitle}/>
|
|
19
|
+
</Head>);
|
|
20
|
+
}
|
|
21
|
+
function DescriptionMetadata({ description }) {
|
|
22
|
+
return (<Head>
|
|
23
|
+
<meta name="description" content={description}/>
|
|
24
|
+
<meta property="og:description" content={description}/>
|
|
25
|
+
</Head>);
|
|
26
|
+
}
|
|
27
|
+
function ImageMetadata({ image }) {
|
|
28
|
+
const { withBaseUrl } = useBaseUrlUtils();
|
|
29
|
+
const pageImage = withBaseUrl(image, { absolute: true });
|
|
30
|
+
return (<Head>
|
|
31
|
+
<meta property="og:image" content={pageImage}/>
|
|
32
|
+
<meta name="twitter:image" content={pageImage}/>
|
|
33
|
+
</Head>);
|
|
34
|
+
}
|
|
35
|
+
function KeywordsMetadata({ keywords, }) {
|
|
36
|
+
return (<Head>
|
|
37
|
+
<meta name="keywords" content={
|
|
38
|
+
// https://github.com/microsoft/TypeScript/issues/17002
|
|
39
|
+
(Array.isArray(keywords) ? keywords.join(',') : keywords)}/>
|
|
40
|
+
</Head>);
|
|
41
|
+
}
|
|
13
42
|
/**
|
|
14
43
|
* Helper component to manipulate page metadata and override site defaults.
|
|
15
44
|
* Works in the same way as Helmet.
|
|
16
45
|
*/
|
|
17
46
|
export function PageMetadata({ title, description, keywords, image, children, }) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
{
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
-
{description && <meta name="description" content={description}/>}
|
|
26
|
-
{description && <meta property="og:description" content={description}/>}
|
|
27
|
-
|
|
28
|
-
{keywords && (<meta name="keywords" content={
|
|
29
|
-
// https://github.com/microsoft/TypeScript/issues/17002
|
|
30
|
-
(Array.isArray(keywords) ? keywords.join(',') : keywords)}/>)}
|
|
31
|
-
|
|
32
|
-
{pageImage && <meta property="og:image" content={pageImage}/>}
|
|
33
|
-
{pageImage && <meta name="twitter:image" content={pageImage}/>}
|
|
34
|
-
|
|
35
|
-
{children}
|
|
36
|
-
</Head>);
|
|
47
|
+
return (<>
|
|
48
|
+
{title && <TitleMetadata title={title}/>}
|
|
49
|
+
{description && <DescriptionMetadata description={description}/>}
|
|
50
|
+
{keywords && <KeywordsMetadata keywords={keywords}/>}
|
|
51
|
+
{image && <ImageMetadata image={image}/>}
|
|
52
|
+
{children && <Head>{children}</Head>}
|
|
53
|
+
</>);
|
|
37
54
|
}
|
|
38
55
|
const HtmlClassNameContext = React.createContext(undefined);
|
|
39
56
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadataUtils.js","sourceRoot":"","sources":["../../src/utils/metadataUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAuB,MAAM,OAAO,CAAC;AAC5C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAC,iBAAiB,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"metadataUtils.js","sourceRoot":"","sources":["../../src/utils/metadataUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAuB,MAAM,OAAO,CAAC;AAC5C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,C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AAA,CAAC,IAAI,CACH;QAAA,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,EAC7B;MAAA,EAAE,IAAI,CACN;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CACjC,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,UAAkB;IAC/C,OAAO,UAAU,UAAU,CAAC,OAAO,CACjC,6CAA6C,EAC7C,EAAE,CACH,EAAE,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,EAC1C,QAAQ,GAGT;IACC,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,MAAM,SAAS,GAAG,qBAAqB,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClE,MAAM,OAAO,GAAG,aAAa,YAAY,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;IACtD,OAAO,CACL,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CACzD;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,qBAAqB,CAAC,CACzB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
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 { ReactNode } from 'react';
|
|
8
|
+
type TitleFormatterParams = {
|
|
9
|
+
/**
|
|
10
|
+
* The page title to format
|
|
11
|
+
* Usually provided with these APIs:
|
|
12
|
+
* - <PageMetadata title={title}>
|
|
13
|
+
* - useTitleFormatter().format(title)
|
|
14
|
+
*/
|
|
15
|
+
title: string;
|
|
16
|
+
/**
|
|
17
|
+
* The siteConfig.title value
|
|
18
|
+
*/
|
|
19
|
+
siteTitle: string;
|
|
20
|
+
/**
|
|
21
|
+
* The siteConfig.titleDelimiter value
|
|
22
|
+
*/
|
|
23
|
+
titleDelimiter: string;
|
|
24
|
+
/**
|
|
25
|
+
* The plugin that created the page you are on
|
|
26
|
+
*/
|
|
27
|
+
plugin: {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* This is the full formatting function, including all useful params
|
|
34
|
+
* Can be customized through React context with the provider
|
|
35
|
+
*/
|
|
36
|
+
export type TitleFormatterFn = (params: TitleFormatterParams) => string;
|
|
37
|
+
/**
|
|
38
|
+
* The default formatter is provided in params for convenience
|
|
39
|
+
*/
|
|
40
|
+
export type TitleFormatterFnWithDefault = (params: TitleFormatterParams & {
|
|
41
|
+
defaultFormatter: (params: TitleFormatterParams) => string;
|
|
42
|
+
}) => string;
|
|
43
|
+
export declare const TitleFormatterFnDefault: TitleFormatterFn;
|
|
44
|
+
/**
|
|
45
|
+
* This is the simpler API exposed to theme/users
|
|
46
|
+
*/
|
|
47
|
+
type TitleFormatter = {
|
|
48
|
+
format: (title: string) => string;
|
|
49
|
+
};
|
|
50
|
+
export declare function TitleFormatterProvider({ formatter, children, }: {
|
|
51
|
+
children: ReactNode;
|
|
52
|
+
formatter: TitleFormatterFnWithDefault;
|
|
53
|
+
}): ReactNode;
|
|
54
|
+
/**
|
|
55
|
+
* Returns a function to format the page title
|
|
56
|
+
*/
|
|
57
|
+
export declare function useTitleFormatter(): TitleFormatter;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=titleFormatterUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"titleFormatterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/titleFormatterUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAKrC,KAAK,oBAAoB,GAAG;IAC1B;;;;;OAKG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,MAAM,EAAE;QACN,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,oBAAoB,KAAK,MAAM,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,CACxC,MAAM,EAAE,oBAAoB,GAAG;IAC7B,gBAAgB,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,MAAM,CAAC;CAC5D,KACE,MAAM,CAAC;AAEZ,eAAO,MAAM,uBAAuB,EAAE,gBAUrC,CAAC;AAEF;;GAEG;AACH,KAAK,cAAc,GAAG;IAAC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;CAAC,CAAC;AAM1D,wBAAgB,sBAAsB,CAAC,EACrC,SAAS,EACT,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,EAAE,2BAA2B,CAAC;CACxC,GAAG,SAAS,CAMZ;AAUD;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAmBlD"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { createContext, useContext } from 'react';
|
|
8
|
+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
9
|
+
import useRouteContext from '@docusaurus/useRouteContext';
|
|
10
|
+
import { ReactContextError } from './reactUtils';
|
|
11
|
+
export const TitleFormatterFnDefault = ({ title, siteTitle, titleDelimiter, }) => {
|
|
12
|
+
const trimmedTitle = title?.trim();
|
|
13
|
+
if (!trimmedTitle || trimmedTitle === siteTitle) {
|
|
14
|
+
return siteTitle;
|
|
15
|
+
}
|
|
16
|
+
return `${trimmedTitle} ${titleDelimiter} ${siteTitle}`;
|
|
17
|
+
};
|
|
18
|
+
const TitleFormatterContext = createContext(null);
|
|
19
|
+
export function TitleFormatterProvider({ formatter, children, }) {
|
|
20
|
+
return (<TitleFormatterContext.Provider value={formatter}>
|
|
21
|
+
{children}
|
|
22
|
+
</TitleFormatterContext.Provider>);
|
|
23
|
+
}
|
|
24
|
+
function useTitleFormatterContext() {
|
|
25
|
+
const value = useContext(TitleFormatterContext);
|
|
26
|
+
if (value === null) {
|
|
27
|
+
throw new ReactContextError('TitleFormatterProvider');
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns a function to format the page title
|
|
33
|
+
*/
|
|
34
|
+
export function useTitleFormatter() {
|
|
35
|
+
const formatter = useTitleFormatterContext();
|
|
36
|
+
const { siteConfig } = useDocusaurusContext();
|
|
37
|
+
const { title: siteTitle, titleDelimiter } = siteConfig;
|
|
38
|
+
// Unfortunately we can only call this hook here, not in the provider
|
|
39
|
+
// Route context can't be accessed in any provider applied above the router
|
|
40
|
+
const { plugin } = useRouteContext();
|
|
41
|
+
return {
|
|
42
|
+
format: (title) => formatter({
|
|
43
|
+
title,
|
|
44
|
+
siteTitle,
|
|
45
|
+
titleDelimiter,
|
|
46
|
+
plugin,
|
|
47
|
+
defaultFormatter: TitleFormatterFnDefault,
|
|
48
|
+
}),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=titleFormatterUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"titleFormatterUtils.js","sourceRoot":"","sources":["../../src/utils/titleFormatterUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;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AAU,CAAC;IAEtD,qEAAqE;IACrE,2EAA2E;IAC3E,MAAM,EAAC,MAAM,EAAC,GAAG,eAAe,EAAE,CAAC;IAEnC,OAAO;QACL,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE,CACxB,SAAS,CAAC;YACR,KAAK;YACL,SAAS;YACT,cAAc;YACd,MAAM;YACN,gBAAgB,EAAE,uBAAuB;SAC1C,CAAC;KACL,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-common",
|
|
3
|
-
"version": "3.7.0-canary-
|
|
3
|
+
"version": "3.7.0-canary-6292",
|
|
4
4
|
"description": "Common code for Docusaurus themes.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
},
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@docusaurus/mdx-loader": "3.7.0-canary-
|
|
34
|
-
"@docusaurus/module-type-aliases": "3.7.0-canary-
|
|
35
|
-
"@docusaurus/utils": "3.7.0-canary-
|
|
36
|
-
"@docusaurus/utils-common": "3.7.0-canary-
|
|
33
|
+
"@docusaurus/mdx-loader": "3.7.0-canary-6292",
|
|
34
|
+
"@docusaurus/module-type-aliases": "3.7.0-canary-6292",
|
|
35
|
+
"@docusaurus/utils": "3.7.0-canary-6292",
|
|
36
|
+
"@docusaurus/utils-common": "3.7.0-canary-6292",
|
|
37
37
|
"@types/history": "^4.7.11",
|
|
38
38
|
"@types/react": "*",
|
|
39
39
|
"@types/react-router-config": "*",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"utility-types": "^3.10.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@docusaurus/core": "3.7.0-canary-
|
|
48
|
-
"@docusaurus/types": "3.7.0-canary-
|
|
47
|
+
"@docusaurus/core": "3.7.0-canary-6292",
|
|
48
|
+
"@docusaurus/types": "3.7.0-canary-6292",
|
|
49
49
|
"fs-extra": "^11.1.1",
|
|
50
50
|
"lodash": "^4.17.21"
|
|
51
51
|
},
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"engines": {
|
|
58
58
|
"node": ">=18.0"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "202a6243823c4fdc0ae16d50fb72193fc1fd7d6a"
|
|
61
61
|
}
|
package/src/internal.ts
CHANGED
|
@@ -43,7 +43,10 @@ export {
|
|
|
43
43
|
|
|
44
44
|
export {DEFAULT_SEARCH_TAG} from './utils/searchUtils';
|
|
45
45
|
|
|
46
|
-
export {
|
|
46
|
+
export {
|
|
47
|
+
TitleFormatterProvider,
|
|
48
|
+
useTitleFormatter,
|
|
49
|
+
} from './utils/titleFormatterUtils';
|
|
47
50
|
|
|
48
51
|
export {useLocationChange} from './utils/useLocationChange';
|
|
49
52
|
|
|
@@ -10,7 +10,7 @@ import clsx from 'clsx';
|
|
|
10
10
|
import Head from '@docusaurus/Head';
|
|
11
11
|
import useRouteContext from '@docusaurus/useRouteContext';
|
|
12
12
|
import {useBaseUrlUtils} from '@docusaurus/useBaseUrl';
|
|
13
|
-
import {useTitleFormatter} from './
|
|
13
|
+
import {useTitleFormatter} from './titleFormatterUtils';
|
|
14
14
|
|
|
15
15
|
type PageMetadataProps = {
|
|
16
16
|
readonly title?: string;
|
|
@@ -20,6 +20,55 @@ type PageMetadataProps = {
|
|
|
20
20
|
readonly children?: ReactNode;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
function TitleMetadata({title}: {title: string}) {
|
|
24
|
+
const titleFormatter = useTitleFormatter();
|
|
25
|
+
const formattedTitle = titleFormatter.format(title);
|
|
26
|
+
return (
|
|
27
|
+
<Head>
|
|
28
|
+
<title>{formattedTitle}</title>
|
|
29
|
+
<meta property="og:title" content={formattedTitle} />
|
|
30
|
+
</Head>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function DescriptionMetadata({description}: {description: string}) {
|
|
35
|
+
return (
|
|
36
|
+
<Head>
|
|
37
|
+
<meta name="description" content={description} />
|
|
38
|
+
<meta property="og:description" content={description} />
|
|
39
|
+
</Head>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function ImageMetadata({image}: {image: string}) {
|
|
44
|
+
const {withBaseUrl} = useBaseUrlUtils();
|
|
45
|
+
const pageImage = withBaseUrl(image, {absolute: true});
|
|
46
|
+
return (
|
|
47
|
+
<Head>
|
|
48
|
+
<meta property="og:image" content={pageImage} />
|
|
49
|
+
<meta name="twitter:image" content={pageImage} />
|
|
50
|
+
</Head>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function KeywordsMetadata({
|
|
55
|
+
keywords,
|
|
56
|
+
}: {
|
|
57
|
+
keywords: PageMetadataProps['keywords'];
|
|
58
|
+
}) {
|
|
59
|
+
return (
|
|
60
|
+
<Head>
|
|
61
|
+
<meta
|
|
62
|
+
name="keywords"
|
|
63
|
+
content={
|
|
64
|
+
// https://github.com/microsoft/TypeScript/issues/17002
|
|
65
|
+
(Array.isArray(keywords) ? keywords.join(',') : keywords) as string
|
|
66
|
+
}
|
|
67
|
+
/>
|
|
68
|
+
</Head>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
23
72
|
/**
|
|
24
73
|
* Helper component to manipulate page metadata and override site defaults.
|
|
25
74
|
* Works in the same way as Helmet.
|
|
@@ -31,33 +80,14 @@ export function PageMetadata({
|
|
|
31
80
|
image,
|
|
32
81
|
children,
|
|
33
82
|
}: PageMetadataProps): ReactNode {
|
|
34
|
-
const pageTitle = useTitleFormatter(title);
|
|
35
|
-
const {withBaseUrl} = useBaseUrlUtils();
|
|
36
|
-
const pageImage = image ? withBaseUrl(image, {absolute: true}) : undefined;
|
|
37
|
-
|
|
38
83
|
return (
|
|
39
|
-
|
|
40
|
-
{title && <title
|
|
41
|
-
{
|
|
42
|
-
|
|
43
|
-
{
|
|
44
|
-
{
|
|
45
|
-
|
|
46
|
-
{keywords && (
|
|
47
|
-
<meta
|
|
48
|
-
name="keywords"
|
|
49
|
-
content={
|
|
50
|
-
// https://github.com/microsoft/TypeScript/issues/17002
|
|
51
|
-
(Array.isArray(keywords) ? keywords.join(',') : keywords) as string
|
|
52
|
-
}
|
|
53
|
-
/>
|
|
54
|
-
)}
|
|
55
|
-
|
|
56
|
-
{pageImage && <meta property="og:image" content={pageImage} />}
|
|
57
|
-
{pageImage && <meta name="twitter:image" content={pageImage} />}
|
|
58
|
-
|
|
59
|
-
{children}
|
|
60
|
-
</Head>
|
|
84
|
+
<>
|
|
85
|
+
{title && <TitleMetadata title={title} />}
|
|
86
|
+
{description && <DescriptionMetadata description={description} />}
|
|
87
|
+
{keywords && <KeywordsMetadata keywords={keywords} />}
|
|
88
|
+
{image && <ImageMetadata image={image} />}
|
|
89
|
+
{children && <Head>{children}</Head>}
|
|
90
|
+
</>
|
|
61
91
|
);
|
|
62
92
|
}
|
|
63
93
|
|
|
@@ -0,0 +1,122 @@
|
|
|
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 {createContext, useContext} from 'react';
|
|
9
|
+
import type {ReactNode} from 'react';
|
|
10
|
+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
11
|
+
import useRouteContext from '@docusaurus/useRouteContext';
|
|
12
|
+
import {ReactContextError} from './reactUtils';
|
|
13
|
+
|
|
14
|
+
type TitleFormatterParams = {
|
|
15
|
+
/**
|
|
16
|
+
* The page title to format
|
|
17
|
+
* Usually provided with these APIs:
|
|
18
|
+
* - <PageMetadata title={title}>
|
|
19
|
+
* - useTitleFormatter().format(title)
|
|
20
|
+
*/
|
|
21
|
+
title: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The siteConfig.title value
|
|
25
|
+
*/
|
|
26
|
+
siteTitle: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The siteConfig.titleDelimiter value
|
|
30
|
+
*/
|
|
31
|
+
titleDelimiter: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The plugin that created the page you are on
|
|
35
|
+
*/
|
|
36
|
+
plugin: {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* This is the full formatting function, including all useful params
|
|
44
|
+
* Can be customized through React context with the provider
|
|
45
|
+
*/
|
|
46
|
+
export type TitleFormatterFn = (params: TitleFormatterParams) => string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The default formatter is provided in params for convenience
|
|
50
|
+
*/
|
|
51
|
+
export type TitleFormatterFnWithDefault = (
|
|
52
|
+
params: TitleFormatterParams & {
|
|
53
|
+
defaultFormatter: (params: TitleFormatterParams) => string;
|
|
54
|
+
},
|
|
55
|
+
) => string;
|
|
56
|
+
|
|
57
|
+
export const TitleFormatterFnDefault: TitleFormatterFn = ({
|
|
58
|
+
title,
|
|
59
|
+
siteTitle,
|
|
60
|
+
titleDelimiter,
|
|
61
|
+
}): string => {
|
|
62
|
+
const trimmedTitle = title?.trim();
|
|
63
|
+
if (!trimmedTitle || trimmedTitle === siteTitle) {
|
|
64
|
+
return siteTitle;
|
|
65
|
+
}
|
|
66
|
+
return `${trimmedTitle} ${titleDelimiter} ${siteTitle}`;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* This is the simpler API exposed to theme/users
|
|
71
|
+
*/
|
|
72
|
+
type TitleFormatter = {format: (title: string) => string};
|
|
73
|
+
|
|
74
|
+
const TitleFormatterContext = createContext<TitleFormatterFnWithDefault | null>(
|
|
75
|
+
null,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
export function TitleFormatterProvider({
|
|
79
|
+
formatter,
|
|
80
|
+
children,
|
|
81
|
+
}: {
|
|
82
|
+
children: ReactNode;
|
|
83
|
+
formatter: TitleFormatterFnWithDefault;
|
|
84
|
+
}): ReactNode {
|
|
85
|
+
return (
|
|
86
|
+
<TitleFormatterContext.Provider value={formatter}>
|
|
87
|
+
{children}
|
|
88
|
+
</TitleFormatterContext.Provider>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function useTitleFormatterContext() {
|
|
93
|
+
const value = useContext(TitleFormatterContext);
|
|
94
|
+
if (value === null) {
|
|
95
|
+
throw new ReactContextError('TitleFormatterProvider');
|
|
96
|
+
}
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Returns a function to format the page title
|
|
102
|
+
*/
|
|
103
|
+
export function useTitleFormatter(): TitleFormatter {
|
|
104
|
+
const formatter = useTitleFormatterContext();
|
|
105
|
+
const {siteConfig} = useDocusaurusContext();
|
|
106
|
+
const {title: siteTitle, titleDelimiter} = siteConfig;
|
|
107
|
+
|
|
108
|
+
// Unfortunately we can only call this hook here, not in the provider
|
|
109
|
+
// Route context can't be accessed in any provider applied above the router
|
|
110
|
+
const {plugin} = useRouteContext();
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
format: (title: string) =>
|
|
114
|
+
formatter({
|
|
115
|
+
title,
|
|
116
|
+
siteTitle,
|
|
117
|
+
titleDelimiter,
|
|
118
|
+
plugin,
|
|
119
|
+
defaultFormatter: TitleFormatterFnDefault,
|
|
120
|
+
}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -1,11 +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
|
-
* Formats the page's title based on relevant site config and other contexts.
|
|
9
|
-
*/
|
|
10
|
-
export declare function useTitleFormatter(title?: string | undefined): string;
|
|
11
|
-
//# sourceMappingURL=generalUtils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAMpE"}
|
|
@@ -1,18 +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
|
-
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
8
|
-
/**
|
|
9
|
-
* Formats the page's title based on relevant site config and other contexts.
|
|
10
|
-
*/
|
|
11
|
-
export function useTitleFormatter(title) {
|
|
12
|
-
const { siteConfig } = useDocusaurusContext();
|
|
13
|
-
const { title: siteTitle, titleDelimiter } = siteConfig;
|
|
14
|
-
return title?.trim().length
|
|
15
|
-
? `${title.trim()} ${titleDelimiter} ${siteTitle}`
|
|
16
|
-
: siteTitle;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=generalUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generalUtils.js","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAEpE;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA0B;IAC1D,MAAM,EAAC,UAAU,EAAC,GAAG,oBAAoB,EAAE,CAAC;IAC5C,MAAM,EAAC,KAAK,EAAE,SAAS,EAAE,cAAc,EAAC,GAAG,UAAU,CAAC;IACtD,OAAO,KAAK,EAAE,IAAI,EAAE,CAAC,MAAM;QACzB,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,IAAI,cAAc,IAAI,SAAS,EAAE;QAClD,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC"}
|
|
@@ -1,19 +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 useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Formats the page's title based on relevant site config and other contexts.
|
|
12
|
-
*/
|
|
13
|
-
export function useTitleFormatter(title?: string | undefined): string {
|
|
14
|
-
const {siteConfig} = useDocusaurusContext();
|
|
15
|
-
const {title: siteTitle, titleDelimiter} = siteConfig;
|
|
16
|
-
return title?.trim().length
|
|
17
|
-
? `${title.trim()} ${titleDelimiter} ${siteTitle}`
|
|
18
|
-
: siteTitle;
|
|
19
|
-
}
|