修复创建时间与阅读时间的问题
All checks were successful
Release / deploy (push) Successful in 5m20s

This commit is contained in:
王一之 2024-03-24 19:46:50 +08:00
parent e9c32c4118
commit ead6e839df
2 changed files with 9 additions and 33 deletions

View File

@ -37,6 +37,15 @@ const config: Config = {
],
["docusaurus-plugin-docs-info", { debug: true }],
],
markdown: {
preprocessor({ filePath, fileContent }) {
// 去掉第一行的#标题,因为不去掉的话会导致创建时间和阅读时间的错误
if (fileContent.startsWith("# ")) {
return fileContent.replace(/^# (.+?)[\r\n]+/, "");
}
return fileContent;
},
},
// Even if you don't use internationalization, you can use this field to set
// useful metadata like html lang. For example, if your site is Chinese, you

View File

@ -1,33 +0,0 @@
import React from "react";
import Heading from "@theme-original/Heading";
import { useSyntheticTitle } from "../DocItem/Content";
import { useDoc } from "@docusaurus/theme-common/internal";
import dayjs from "dayjs";
import { Detail } from "docusaurus-plugin-content-docs-ex/src";
export default function HeadingWrapper(props) {
const syntheticTitle = useSyntheticTitle();
const doc = useDoc();
const detail = (doc.metadata as any).detail as Detail;
return (
<>
<Heading {...props}>
{props.children}
{detail && !syntheticTitle && props.as.toString() === "h1" && doc.contentTitle==props.children && (
<span
style={{
display: "block",
fontSize: "14px",
fontWeight: "normal",
marginBottom: "10px",
marginTop: "10px",
}}
>
{dayjs(detail.create_date).format("YYYY年MM月DD日")} · {" "}
{Math.ceil(detail.reading_time.minutes)}
</span>
)}
</Heading>
</>
);
}