✨ docs时间和阅读耗时
This commit is contained in:
28
src/theme/DocItem/index.tsx
Normal file
28
src/theme/DocItem/index.tsx
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 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 from "react";
|
||||
import { HtmlClassNameProvider } from "@docusaurus/theme-common";
|
||||
import { DocProvider } from "@docusaurus/theme-common/internal";
|
||||
import DocItemMetadata from "@theme/DocItem/Metadata";
|
||||
import DocItemLayout from "@theme/DocItem/Layout";
|
||||
import type { Props } from "@theme/DocItem";
|
||||
|
||||
export default function DocItem(props: Props): JSX.Element {
|
||||
const docHtmlClassName = `docs-doc-id-${props.content.metadata.id}`;
|
||||
const MDXComponent = props.content;
|
||||
return (
|
||||
<DocProvider content={props.content}>
|
||||
<HtmlClassNameProvider className={docHtmlClassName}>
|
||||
<DocItemMetadata />
|
||||
<DocItemLayout>
|
||||
<MDXComponent />
|
||||
</DocItemLayout>
|
||||
</HtmlClassNameProvider>
|
||||
</DocProvider>
|
||||
);
|
||||
}
|
17
src/theme/Layout/Provider/antd.tsx
Normal file
17
src/theme/Layout/Provider/antd.tsx
Normal file
@ -0,0 +1,17 @@
|
||||
import { ConfigProvider, theme } from "antd";
|
||||
import { useColorMode } from "@docusaurus/theme-common";
|
||||
|
||||
export default function AntdProvider({ children }) {
|
||||
const colorMode = useColorMode();
|
||||
return (
|
||||
<ConfigProvider
|
||||
theme={{
|
||||
algorithm: colorMode.isDarkTheme
|
||||
? theme.darkAlgorithm
|
||||
: theme.defaultAlgorithm,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</ConfigProvider>
|
||||
);
|
||||
}
|
33
src/theme/Layout/Provider/index.tsx
Normal file
33
src/theme/Layout/Provider/index.tsx
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* 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 from "react";
|
||||
import { composeProviders } from "@docusaurus/theme-common";
|
||||
import {
|
||||
ColorModeProvider,
|
||||
AnnouncementBarProvider,
|
||||
DocsPreferredVersionContextProvider,
|
||||
ScrollControllerProvider,
|
||||
NavbarProvider,
|
||||
PluginHtmlClassNameProvider,
|
||||
} from "@docusaurus/theme-common/internal";
|
||||
import type { Props } from "@theme/Layout/Provider";
|
||||
import AntdProvider from "./antd";
|
||||
|
||||
const Provider = composeProviders([
|
||||
ColorModeProvider,
|
||||
AnnouncementBarProvider,
|
||||
ScrollControllerProvider,
|
||||
DocsPreferredVersionContextProvider,
|
||||
PluginHtmlClassNameProvider,
|
||||
NavbarProvider,
|
||||
AntdProvider,
|
||||
]);
|
||||
|
||||
export default function LayoutProvider({ children }: Props): JSX.Element {
|
||||
return <Provider>{children}</Provider>;
|
||||
}
|
43
src/theme/MDXComponents/Heading.tsx
Normal file
43
src/theme/MDXComponents/Heading.tsx
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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 from "react";
|
||||
import Heading from "@theme/Heading";
|
||||
import type { Props } from "@theme/MDXComponents/Heading";
|
||||
import { useDoc } from "@docusaurus/theme-common/internal";
|
||||
import { Detail } from "packages/docusaurus-plugin-content-docs/src";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
export default function MDXHeading(props: Props): JSX.Element {
|
||||
const doc = useDoc();
|
||||
const detail = (doc.metadata as any).detail as Detail;
|
||||
return (
|
||||
<>
|
||||
<Heading
|
||||
{...props}
|
||||
style={{
|
||||
marginBottom: "6px",
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
</Heading>
|
||||
{detail && (
|
||||
<span
|
||||
style={{
|
||||
display: "block",
|
||||
fontSize: ".9rem",
|
||||
fontWeight: "normal",
|
||||
marginBottom: "1rem",
|
||||
}}
|
||||
>
|
||||
{dayjs(detail.create_date).format("YYYY年MM月DD日")} · 阅读需{" "}
|
||||
{Math.ceil(detail.reading_time.minutes)} 分钟
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
0
src/utils/index.ts
Normal file
0
src/utils/index.ts
Normal file
Reference in New Issue
Block a user