From 7e51f0b32bdf9cec6da77275a4fba4bdebb52d1a Mon Sep 17 00:00:00 2001 From: Yue-plus Date: Wed, 4 Sep 2024 02:37:01 +0800 Subject: [PATCH] refactor: mk DocsLayout.astro --- src/components/DemoSubNavigationItems.ts | 6 ++ src/components/DocsToolPanel.tsx | 2 + src/components/GoBackTool.tsx | 25 +++++++++ .../\345\270\203\345\261\200.md" | 1 + src/layouts/DocsLayout.astro | 55 +++++++++++++++++++ src/layouts/InfoLayout.astro | 29 +--------- src/pages/blog/[...slug].astro | 5 +- src/pages/blog/index.astro | 3 + src/pages/demo/DocsLayoutSlot.astro | 10 ++++ src/pages/demo/InfoLayoutSlot.astro | 6 +- src/pages/docs/[...slug].astro | 35 ++---------- src/pages/docs/index.astro | 12 +--- 12 files changed, 117 insertions(+), 72 deletions(-) create mode 100644 src/components/DemoSubNavigationItems.ts create mode 100644 src/components/GoBackTool.tsx create mode 100644 src/layouts/DocsLayout.astro create mode 100644 src/pages/demo/DocsLayoutSlot.astro diff --git a/src/components/DemoSubNavigationItems.ts b/src/components/DemoSubNavigationItems.ts new file mode 100644 index 0000000..9f58ce2 --- /dev/null +++ b/src/components/DemoSubNavigationItems.ts @@ -0,0 +1,6 @@ +import type {SubNavigationItem} from "../_types/SubNavigationItem.ts"; + +const DemoSubNavigationItems: SubNavigationItem[] = [...Array(100)] + .map((item, index): SubNavigationItem => ({title: `子导航项 - ${index}`, href: ""})) + +export default DemoSubNavigationItems diff --git a/src/components/DocsToolPanel.tsx b/src/components/DocsToolPanel.tsx index 525d130..c9ecfcc 100644 --- a/src/components/DocsToolPanel.tsx +++ b/src/components/DocsToolPanel.tsx @@ -1,4 +1,5 @@ import {IconArrow} from "./SvgIcons.tsx"; +import GoBackTool from "./GoBackTool.tsx"; function ToTop() { return
+ } diff --git a/src/components/GoBackTool.tsx b/src/components/GoBackTool.tsx new file mode 100644 index 0000000..a61150b --- /dev/null +++ b/src/components/GoBackTool.tsx @@ -0,0 +1,25 @@ +import {IconArrow} from "./SvgIcons.tsx"; + +export default function GoBackTool({goBackHref}: { goBackHref?: string }) { + const base = import.meta.env.BASE_URL + return <> + + +
+
{goBackHref ? "返回列表" : "返回首页"}
+
GO BACK
+
+
+ { + goBackHref && + +
+
返回首页
+
HOMEPAGE
+
+
+ } + +} diff --git "a/src/content/docs/02-\345\274\200\345\217\221\350\200\205\346\226\207\346\241\243/\345\270\203\345\261\200.md" "b/src/content/docs/02-\345\274\200\345\217\221\350\200\205\346\226\207\346\241\243/\345\270\203\345\261\200.md" index dab49b9..ef2c170 100644 --- "a/src/content/docs/02-\345\274\200\345\217\221\350\200\205\346\226\207\346\241\243/\345\270\203\345\261\200.md" +++ "b/src/content/docs/02-\345\274\200\345\217\221\350\200\205\346\226\207\346\241\243/\345\270\203\345\261\200.md" @@ -10,3 +10,4 @@ title: 布局 - [RootLayout](../../demo/RootLayoutSlot) + [InfoLayout](../../demo/InfoLayoutSlot) + * [DocsLayout](../../demo/DocsLayoutSlot) diff --git a/src/layouts/DocsLayout.astro b/src/layouts/DocsLayout.astro new file mode 100644 index 0000000..0389dfd --- /dev/null +++ b/src/layouts/DocsLayout.astro @@ -0,0 +1,55 @@ +--- +import type {MarkdownHeading} from "astro" +import type {SubNavigationItem} from "../_types/SubNavigationItem" +import InfoLayout from "./InfoLayout.astro" +import DocsLeftAside from "../components/DocsLeftAside.astro" +import DocsLeftAsideSwitch from "../components/DocsLeftAsideSwitch" +import DemoSubNavigationItems from "../components/DemoSubNavigationItems" +import DocumentIndexUL from "../components/DocumentIndexUL.astro" +import DocsToolPanel from "../components/DocsToolPanel" + +interface Props { + title?: string + subNavigationItems?: SubNavigationItem[] + headings?: MarkdownHeading[] +} + +const {title, subNavigationItems, headings} = Astro.props +const tabTitle = title ? title + " - 文档" : "文档" +--- + + + + + +
+ {/* TODO: 面包屑导航 */} + { + headings && headings.length > 0 && +
+ + Document Index - 文档索引 + + +
+ } + +
+ + { + headings && headings.length > 0 && + + } + + +
diff --git a/src/layouts/InfoLayout.astro b/src/layouts/InfoLayout.astro index 928c21d..4b47a8c 100644 --- a/src/layouts/InfoLayout.astro +++ b/src/layouts/InfoLayout.astro @@ -1,7 +1,6 @@ --- -import type {SubNavigationItem} from "../_types/SubNavigationItem"; +import type {SubNavigationItem} from "../_types/SubNavigationItem" import RootLayout from "./RootLayout.astro" -import {IconArrow} from "../components/SvgIcons" import LineDecorator from "../components/LineDecorator" import PageTracker from "../components/PageTracker" @@ -9,15 +8,12 @@ interface Props { title?: string subTitle?: string tabTitle?: string - goBackHref?: string subNavigationItems?: SubNavigationItem[] } -const base = import.meta.env.BASE_URL const title = Astro.props.title ?? "INFO" const subTitle = Astro.props.subTitle ?? "情报中心" const tabTitle = Astro.props.tabTitle ?? "情报中心" -const goBackHref = Astro.props.goBackHref const subNavigationItems = Astro.props.subNavigationItems --- @@ -75,31 +71,10 @@ const subNavigationItems = Astro.props.subNavigationItems { Astro.slots.has("tool-panel") &&
+ class="h-[3.75rem] mb-[9.5rem] portrait:mb-[5.75rem] absolute bottom-0 right-0 flex z-10">
} - -