完成目录架构变更
This commit is contained in:
@@ -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,
|
||||||
|
@@ -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 // 提供默认值
|
||||||
}
|
}
|
@@ -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({
|
||||||
|
Reference in New Issue
Block a user