This commit is contained in:
xugaoyi 2022-03-18 14:56:57 +08:00
parent 6b7ad009c5
commit 6c8f2ebfbf
6 changed files with 83 additions and 24 deletions

View File

@ -328,7 +328,8 @@ export default defineConfig4CustomTheme<VdoingThemeConfig>({
], ],
markdown: { markdown: {
lineNumbers: true lineNumbers: true,
extractHeaders: ['h2', 'h3', 'h4', 'h5', 'h6'], // 提取标题到侧边栏的级别,默认['h2', 'h3']
}, },
// 监听文件变化并重新构建 // 监听文件变化并重新构建

View File

@ -24,7 +24,7 @@
"vuepress-plugin-one-click-copy": "^1.0.2", "vuepress-plugin-one-click-copy": "^1.0.2",
"vuepress-plugin-thirdparty-search": "^1.0.2", "vuepress-plugin-thirdparty-search": "^1.0.2",
"vuepress-plugin-zooming": "^1.1.7", "vuepress-plugin-zooming": "^1.1.7",
"vuepress-theme-vdoing": "^1.9.5", "vuepress-theme-vdoing": "^1.10.0",
"yamljs": "^0.3.0" "yamljs": "^0.3.0"
} }
} }

View File

@ -1,6 +1,7 @@
<template> <template>
<div class="right-menu-wrapper"> <div class="right-menu-wrapper">
<div class="right-menu-margin"> <div class="right-menu-margin">
<div class="right-menu-title">目录</div>
<div class="right-menu-content"> <div class="right-menu-content">
<div <div
:class="[ :class="[
@ -51,49 +52,94 @@ export default {
.right-menu-wrapper .right-menu-wrapper
width $rightMenuWidth width $rightMenuWidth
float right float right
margin-right -($rightMenuWidth + 60px) margin-right -($rightMenuWidth + 55px)
// margin-top -($navbarHeight *2 + 1.5rem)
position sticky position sticky
top 0 top 0
font-size 0.9rem font-size 0.75rem
.right-menu-margin .right-menu-margin
margin-top: ($navbarHeight + 1rem) margin-top: ($navbarHeight + 1rem)
border-radius 3px
overflow hidden
.right-menu-title
padding 10px 15px 0 15px
background var(--mainBg)
font-size 1rem
&:after
content ''
display block
width 100%
height 1px
background var(--borderColor)
margin-top 10px
.right-menu-content .right-menu-content
max-height 80vh max-height 80vh
position relative position relative
overflow hidden overflow hidden
background var(--mainBg)
padding 4px 3px 4px 0
&::-webkit-scrollbar
width 3px
height 3px
&::-webkit-scrollbar-track-piece &::-webkit-scrollbar-track-piece
background none background none
&::-webkit-scrollbar-thumb:vertical &::-webkit-scrollbar-thumb:vertical
background-color hsla(0, 0%, 49%, 0.3) background-color hsla(0, 0%, 49%, 0.3)
&:hover &:hover
overflow-y auto overflow-y auto
padding-right 0
.right-menu-item .right-menu-item
padding 4px 15px padding 4px 15px
border-left 1px solid var(--borderColor) // border-left 1px solid var(--borderColor)
overflow hidden
white-space nowrap
text-overflow ellipsis
position relative
&.level2
font-size 0.8rem
&.level3 &.level3
padding-left 28px padding-left 27px
&.level4
padding-left 37px
&.level5
padding-left 47px
&.level6
padding-left 57px
&.active &.active
border-color $accentColor &:before
content ''
position absolute
top 5px
left 0
width 3px
height 14px
background $accentColor
border-radius 0 4px 4px 0
a a
color $accentColor color $accentColor
opacity 1 opacity 1
a a
color var(--textColor) color var(--textColor)
opacity 0.75 opacity 0.75
display block display inline-block
width: ($rightMenuWidth - 30px) width 100%
overflow hidden
white-space nowrap
text-overflow ellipsis
&:hover &:hover
color $accentColor opacity 1
&:hover
color $accentColor
.have-body-img .have-body-img
.right-menu-wrapper .right-menu-wrapper
.right-menu-margin .right-menu-margin
padding 0.3rem 0 // padding 0.3rem 0
background var(--sidebarBg) // background var(--sidebarBg)
border-radius 5px // border-radius 5px
.right-menu-item .right-menu-item
border-color transparent // border-color transparent
&.active // &.active
border-left 0.2rem solid $accentColor // border-left 0.2rem solid $accentColor
&:hover // &:hover
border-left 0.2rem solid $accentColor // border-left 0.2rem solid $accentColor
</style> </style>

View File

@ -6,7 +6,7 @@ export default {
props: ['item', 'sidebarDepth'], props: ['item', 'sidebarDepth'],
render (h, render(h,
{ {
parent: { parent: {
$page, $page,
@ -54,7 +54,7 @@ export default {
} }
} }
function renderLink (h, to, text, active) { function renderLink(h, to, text, active) {
return h('router-link', { return h('router-link', {
props: { props: {
to, to,
@ -68,18 +68,18 @@ function renderLink (h, to, text, active) {
}, text) }, text)
} }
function renderChildren (h, children, path, route, maxDepth, depth = 1) { function renderChildren(h, children, path, route, maxDepth, depth = 1) {
if (!children || depth > maxDepth) return null if (!children || depth > maxDepth) return null
return h('ul', { class: 'sidebar-sub-headers' }, children.map(c => { return h('ul', { class: 'sidebar-sub-headers' }, children.map(c => {
const active = isActive(route, path + '#' + c.slug) const active = isActive(route, path + '#' + c.slug)
return h('li', { class: 'sidebar-sub-header' }, [ return h('li', { class: 'sidebar-sub-header level' + c.level }, [
renderLink(h, path + '#' + c.slug, c.title, active), renderLink(h, path + '#' + c.slug, c.title, active),
renderChildren(h, c.children, path, route, maxDepth, depth + 1) renderChildren(h, c.children, path, route, maxDepth, depth + 1)
]) ])
})) }))
} }
function renderExternal (h, to, text) { function renderExternal(h, to, text) {
return h('a', { return h('a', {
attrs: { attrs: {
href: to, href: to,
@ -97,6 +97,12 @@ function renderExternal (h, to, text) {
.sidebar .sidebar-sub-headers .sidebar .sidebar-sub-headers
padding-left 1rem padding-left 1rem
font-size 0.95em font-size 0.95em
.level4
padding-left 0.2rem
.level5
padding-left 0.4rem
.level6
padding-left 0.6rem
a.sidebar-link a.sidebar-link
font-size 1em font-size 1em
font-weight 400 font-weight 400

View File

@ -1,6 +1,6 @@
{ {
"name": "vuepress-theme-vdoing", "name": "vuepress-theme-vdoing",
"version": "1.9.5", "version": "1.10.0",
"description": "Vdoing theme for VuePress. 一个基于VuePress的知识管理兼博客主题。", "description": "Vdoing theme for VuePress. 一个基于VuePress的知识管理兼博客主题。",
"author": { "author": {
"name": "gaoyi(Evan) Xu" "name": "gaoyi(Evan) Xu"

View File

@ -222,6 +222,12 @@ h2
h3 h3
font-size 1.35rem font-size 1.35rem
h4
font-size 1.25rem
h5
font-size 1.15rem
h6
font-size 1.05rem
a.header-anchor a.header-anchor
font-size 0.85em font-size 0.85em