完成目录架构变更

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')
// 计算属性:提取第一级数据
// 计算属性:提取docs目录下的第一级数据
const firstLevelItems = computed(() => {
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)
.map(item => ({
...item,

View File

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

View File

@@ -5,8 +5,23 @@ export default defineContentConfig({
docs: defineCollection({
type: 'page',
source: {
cwd: globalThis.__DOCS_DIR__,
include: '**',
include: 'docs/**',
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/**']
},
schema: z.object({