docs时间和阅读耗时

This commit is contained in:
2024-03-22 16:54:41 +08:00
parent 199bbf2628
commit 5a4efad893
24 changed files with 2577 additions and 2542 deletions

View 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>
);
}

View 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>
);
}

View 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>;
}

View 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
View File