diff --git a/src/apps/menu.tsx b/src/apps/menu.tsx new file mode 100644 index 0000000..4c06d0f --- /dev/null +++ b/src/apps/menu.tsx @@ -0,0 +1,56 @@ +import { useMemo } from "react"; + +export type MenuProps = { + items: MenuItem[]; + basename?: string; +}; +export type MenuItem = { + id: string; + data: { + title: string; + tags: string[]; + hideInMenu?: boolean; + } +} +export const Menu = (props: MenuProps) => { + const { items, basename = '' } = props; + const list = useMemo(() => { + return items.filter(item => !item.data?.hideInMenu); + }, [items]); + if (list.length === 0) { + return null; + } + return ( + + ); +} + diff --git a/src/content.config.ts b/src/content.config.ts index 5a3e627..e958840 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -12,6 +12,11 @@ const docs = defineCollection({ // pubDate: z.coerce.date(), createdAt: z.coerce.date().optional(), updatedAt: z.coerce.date().optional(), + showMenu: z.boolean().optional().default(true), + /** + * 在侧边栏隐藏该文档 + */ + hideInMenu: z.boolean().optional().default(false), }), }); diff --git a/src/data/docs/menu.md b/src/data/docs/menu.md new file mode 100644 index 0000000..174df6d --- /dev/null +++ b/src/data/docs/menu.md @@ -0,0 +1,8 @@ +--- +title: 'astro 概览' +tags: ['astro', 'simple', 'template'] +createdAt: '2025-11-25 20:00:00' +hideInMenu: true +--- + +## 概览 diff --git a/src/data/docs/simpalte-template.md b/src/data/docs/simpalte-template.md index 3342b26..11cf32e 100644 --- a/src/data/docs/simpalte-template.md +++ b/src/data/docs/simpalte-template.md @@ -1,6 +1,8 @@ --- title: 'astro 例子' tags: ['astro', 'simple', 'template'] +createdAt: '2025-11-25 20:00:00' +hideInMenu: true --- ## astro-simplate-template diff --git a/src/layouts/mdx.astro b/src/layouts/mdx.astro index df6252a..384cb8d 100644 --- a/src/layouts/mdx.astro +++ b/src/layouts/mdx.astro @@ -5,29 +5,34 @@ export interface Props { import '../styles/global.css'; import '../styles/theme.css'; import 'github-markdown-css/github-markdown-light.css'; - +import { Menu, MenuItem } from '../apps/menu'; export interface Props { title?: string; description?: string; lang?: string; charset?: string; + showMenu?: boolean; + menu?: MenuItem[]; + basename?: string; } -const { title = 'Light Code', description = 'A lightweight code editor', lang = 'zh-CN', charset = 'UTF-8' } = Astro.props; +const { + title = 'Light Code', + description = 'A lightweight code editor', + lang = 'zh-CN', + charset = 'UTF-8', + showMenu = true, + menu, + basename = '', +} = Astro.props; --- - + - + - Docs - + {title} + - -
+ +
-
-
- +
+ { + showMenu && ( + + ) + } +
+
+ +
-