完成目录架构变更

This commit is contained in:
2025-08-06 23:14:36 +08:00
parent cca2b53694
commit 41e273ed07
34 changed files with 25 additions and 20 deletions

View File

@@ -67,10 +67,14 @@ import type { ContentNavigationItem } from '@nuxt/content'
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation') const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
// 计算属性:提取第一级数据 // 计算属性:提取docs目录下的第一级数据
const firstLevelItems = computed(() => { const firstLevelItems = computed(() => {
if (!navigation?.value) return [] if (!navigation?.value) return []
return navigation.value // 查找docs目录
const docsItem = navigation.value.find(item => item.title === 'docs' || item.path === '/docs')
if (!docsItem?.children) return []
// 返回docs目录下的子目录
return docsItem.children
.filter(item => item.title && item.path) .filter(item => item.title && item.path)
.map(item => ({ .map(item => ({
...item, ...item,

View File

@@ -19,21 +19,7 @@ const pageFontSizeClass = computed(() => {
}) })
// //
const path = computed(() => { const path = computed(() => route.path)
const slug = route.params.slug
// slug
if (!slug) {
return '/' // slug
}
const pathValue = Array.isArray(slug) ? slug.join('/') : slug
// / /
const normalizedPath = `/${pathValue}`.replace(/\/+$/, '') // 使用 /+ 匹配多个连续的斜杠
return normalizedPath
})
// URL // URL
const queryPath = computed(() => { const queryPath = computed(() => {
@@ -47,7 +33,7 @@ const queryPath = computed(() => {
const { data: page } = await useAsyncData( const { data: page } = await useAsyncData(
`page-${route.path}`, // 使 key `page-${route.path}`, // 使 key
() => queryCollection('docs').path(queryPath.value).first(), () => queryCollection('docs').path(decodeURIComponent(path.value)).first(),
{ {
default: () => null // default: () => null //
} }

View File

@@ -5,8 +5,23 @@ export default defineContentConfig({
docs: defineCollection({ docs: defineCollection({
type: 'page', type: 'page',
source: { source: {
cwd: globalThis.__DOCS_DIR__, include: 'docs/**',
include: '**', exclude: ['/web/**']
},
schema: z.object({
rawbody: z.string(),
links: z.array(z.object({
label: z.string(),
icon: z.string(),
to: z.string(),
target: z.string().optional()
})).optional()
})
}),
blog: defineCollection({
type: 'page',
source: {
include: 'blog/**',
exclude: ['/web/**'] exclude: ['/web/**']
}, },
schema: z.object({ schema: z.object({