1
This commit is contained in:
@@ -1,41 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useData } from 'vitepress'
|
||||
import sidebarData from '../data/sidebar.json'
|
||||
|
||||
const { page } = useData()
|
||||
|
||||
const sidebarItems = {
|
||||
'/java/': [
|
||||
{ text: '概述', link: '/java/' },
|
||||
{ text: '基础语法', link: '/java/basic' },
|
||||
{ text: '面向对象', link: '/java/oop' },
|
||||
{ text: '集合框架', link: '/java/collection' },
|
||||
{ text: '多线程', link: '/java/thread' }
|
||||
],
|
||||
'/vue/': [
|
||||
{ text: '概述', link: '/vue/' },
|
||||
{ text: 'Vue3基础', link: '/vue/basic' },
|
||||
{ text: '组件开发', link: '/vue/component' },
|
||||
{ text: '组合式API', link: '/vue/composition' },
|
||||
{ text: '状态管理', link: '/vue/pinia' }
|
||||
]
|
||||
}
|
||||
|
||||
function getCurrentSidebar() {
|
||||
const currentSidebar = computed(() => {
|
||||
const path = page.value.relativePath
|
||||
for (const [prefix, items] of Object.entries(sidebarItems)) {
|
||||
if (path.startsWith(prefix.replace(/^\//, ''))) {
|
||||
return { title: prefix === '/java/' ? 'Java 笔记' : 'Vue 笔记', items }
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const currentSidebar = getCurrentSidebar()
|
||||
const pathPrefix = path.split('/')[0]
|
||||
return sidebarData.find(group => group.path === `/${pathPrefix}/`)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="sidebar" v-if="currentSidebar">
|
||||
<h2 class="sidebar-title">{{ currentSidebar.title }}</h2>
|
||||
<h2 class="sidebar-title">{{ currentSidebar.title }} 笔记</h2>
|
||||
<ul class="sidebar-list">
|
||||
<li v-for="item in currentSidebar.items" :key="item.link">
|
||||
<a :href="item.link" class="sidebar-link">{{ item.text }}</a>
|
||||
|
||||
Reference in New Issue
Block a user