提交 6e9646e2 编写于 作者: D DCloud_LXH

feat: Improve toc display

上级 11c18837
...@@ -24,7 +24,7 @@ const config = { ...@@ -24,7 +24,7 @@ const config = {
logo: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-f184e7c3-1912-41b2-b81f-435d1b37c7b4/5a7f902b-21a7-4822-884f-925219eacc4b.png', logo: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-f184e7c3-1912-41b2-b81f-435d1b37c7b4/5a7f902b-21a7-4822-884f-925219eacc4b.png',
// TODO use plugin/theme // TODO use plugin/theme
sidebar: createSidebar(tabs), sidebar: createSidebar(tabs),
// sidebarDepth: 2, sidebarDepth: 0,
nextLinks: false, nextLinks: false,
prevLinks: false, prevLinks: false,
// TODO use theme // TODO use theme
...@@ -44,6 +44,7 @@ const config = { ...@@ -44,6 +44,7 @@ const config = {
} }
}, },
markdown: { markdown: {
// toc: { includeLevel: [1, 2, 3, 4] },
slugify(str) { slugify(str) {
if (typeof str !== 'string') return '' if (typeof str !== 'string') return ''
......
<template>
<div class="table-of-contents">
<div
v-for="item in $page.headers"
ref="chairTocItem"
:key="item.slug"
class="vuepress-toc-item-top"
:class="[`vuepress-toc-h${item.level}`]"
>
<a :href="`#${item.slug}`" :title="item.title">{{ item.title }}</a>
</div>
</div>
</template>
<style lang="stylus">
.table-of-contents
margin 0 auto
padding 2rem 2.5rem 0 2.5rem
@media (max-width: $MQNarrow)
padding 2rem 2rem 0 2rem
@media (max-width: $MQMobileNarrow)
padding 1.5rem 1.5rem 0 1.5rem
border-left: 2px solid #e6e6e6
.vuepress-toc-item-top
position relative
padding 0.1rem 0.6rem 0.1rem 1.5rem
line-height 1.5rem
border-left 2px solid rgba(0, 0, 0, 0.08)
overflow hidden
a
display block
// color $textColor
width 100%
box-sizing border-box
font-size 16px
font-weight 400
text-decoration none
transition color 0.3s
overflow hidden
text-overflow ellipsis
white-space nowrap
for i in range(2, 6)
.vuepress-toc-h{i} a
padding-left 1rem * (i - 1)
</style>
<template> <template>
<Sticker <Sticker
ref="sticker" ref="sticker"
:class="['vuepress-toc', visible ? '' : 'table-of-contents']" :class="['vuepress-toc', visible ? '' : 'table-of-contents-sticker']"
v-bind="$attrs" v-bind="$attrs"
> >
<h5>ON THIS PAGE</h5> <h5>文档结构</h5>
<div <div
v-for="(item, index) in $page.headers" v-for="(item, index) in $page.headers"
ref="chairTocItem" ref="chairTocItem"
:key="index" :key="item.slug"
class="vuepress-toc-item" class="vuepress-toc-item"
:class="[`vuepress-toc-h${item.level}`, { active: activeIndex === index }]" :class="[`vuepress-toc-h${item.level}`, { active: activeIndex === index }]"
> >
...@@ -114,7 +114,7 @@ ...@@ -114,7 +114,7 @@
</script> </script>
<style lang="stylus"> <style lang="stylus">
.table-of-contents .table-of-contents-sticker
display none !important display none !important
.vuepress-toc .vuepress-toc
position fixed position fixed
...@@ -157,7 +157,7 @@ ...@@ -157,7 +157,7 @@
.vuepress-toc-h1 a .vuepress-toc-h1 a
.vuepress-toc-h2 a .vuepress-toc-h2 a
font-weight bold font-weight bold
for i in range(3, 6) for i in range(2, 6)
.vuepress-toc-h{i} a .vuepress-toc-h{i} a
padding-left 1rem * (i - 2) padding-left 1rem * (i - 1)
</style> </style>
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
> >
<template #top> <template #top>
<slot name="page-top" /> <slot name="page-top" />
<TocTop/>
</template> </template>
<template #bottom> <template #bottom>
<slot name="page-bottom" /> <slot name="page-bottom" />
...@@ -57,6 +58,7 @@ import Sidebar from '@theme/components/Sidebar.vue' ...@@ -57,6 +58,7 @@ import Sidebar from '@theme/components/Sidebar.vue'
import Footer from '@theme/components/Footer.vue'; import Footer from '@theme/components/Footer.vue';
import SiderBarBottom from '../components/SiderBarBottom.vue'; import SiderBarBottom from '../components/SiderBarBottom.vue';
import Toc from '../components/Toc'; import Toc from '../components/Toc';
import TocTop from '../components/Toc-top';
import { resolveSidebarItems, forbidScroll, BaiduStat } from '../util' import { resolveSidebarItems, forbidScroll, BaiduStat } from '../util'
import navProvider from '../mixin/navProvider'; import navProvider from '../mixin/navProvider';
import toc from '../mixin/toc'; import toc from '../mixin/toc';
...@@ -71,7 +73,8 @@ export default { ...@@ -71,7 +73,8 @@ export default {
Navbar, Navbar,
Footer, Footer,
SiderBarBottom, SiderBarBottom,
Toc Toc,
TocTop
}, },
data () { data () {
return { return {
......
.custom-page-class{ .custom-page-class
position: relative; position relative
/* 首页几个logo的排版 */ /* 首页几个logo的排版 */
.flex-img-group-view { .flex-img-group-view
display flex display flex
flex-direction row flex-direction row
margin 10px 0 margin 10px 0
.barcode-view {
.barcode-view
display flex display flex
align-items center align-items center
flex-direction column flex-direction column
margin 0 5px margin 0 5px
margin-bottom 20px margin-bottom 20px
b {
b
text-align center text-align center
}
}
}
.uniapp-home-content { .uniapp-home-content
display flex display flex
flex-wrap wrap flex-wrap wrap
width 100% width 100%
justify-content center justify-content center
.uniapp-home-content-item {
.uniapp-home-content-item
margin-bottom 20px margin-bottom 20px
.uniapp-home-content-item-image {
.uniapp-home-content-item-image
width 55px width 55px
height 55px height 55px
flex-shrink 0 flex-shrink 0
img {
img
height 100% height 100%
}
} p.uniapp-home-content-item-text
p.uniapp-home-content-item-text {
margin-bottom 0px margin-bottom 0px
letter-spacing 0px letter-spacing 0px
color #333 color #333
}
.uniapp-home-content-item-title{ .uniapp-home-content-item-title
font-size 16px font-size 16px
}
} @media screen and (min-width 768px)
} .flex-img-group-view
@media screen and (min-width: 768px) {
.flex-img-group-view {
justify-content space-around justify-content space-around
}
.uniapp-home-content-item{ .uniapp-home-content-item
width 32% width 32%
}
} @media screen and (max-width 600px)
@media screen and (max-width: 600px) { .uniapp-home-content-item
.uniapp-home-content-item{
width 100% width 100%
display flex display flex
flex-direction row flex-direction row
}
.uniapp-home-content-item-header { .uniapp-home-content-item-header
display flex display flex
flex-direction column flex-direction column
padding-left 15px padding-left 15px
}
.uniapp-home-content-item-title{ .uniapp-home-content-item-title
line-height 10px line-height 10px
}
} img
} image-rendering -moz-crisp-edges /* Firefox */
image-rendering -o-crisp-edges /* Opera */
img { image-rendering -webkit-optimize-contrast /* Webkit (non-standard naming) */
image-rendering: -moz-crisp-edges; /* Firefox*/ image-rendering crisp-edges
image-rendering: -o-crisp-edges; /* Opera */ -ms-interpolation-mode nearest-neighbor /* I (non-standard property) */
image-rendering: -webkit-optimize-contrast; /*Webkit (non-standard naming) */
image-rendering: crisp-edges;
-ms-interpolation-mode: nearest-neighbor; /* I (non-standard property) */
}
body.forbid_scroll body.forbid_scroll
height 100% height 100%
...@@ -83,22 +78,36 @@ main.page ...@@ -83,22 +78,36 @@ main.page
padding-bottom 0px padding-bottom 0px
padding-right 0px padding-right 0px
@media (min-width: $vuepress-display-min-width) @media (min-width $vuepress-display-min-width)
& main.page
padding-right $vuepress-toc-width padding-right $vuepress-toc-width
@media (min-width: $vuepress-display-min-width)
.vuepress-toc .vuepress-toc
display block !important display block !important
.table-of-contents
display none !important
@media (max-width $vuepress-display-min-width)
.table-of-contents
display block !important
@media (min-width 2000px)
$vuepress-toc-width = 20rem
.vuepress-toc
width: $vuepress-toc-width !important
main.page
padding-right $vuepress-toc-width
{$contentClass}:not(.custom) {$contentClass}:not(.custom)
> *:first-child > *:first-child
margin-top 0 margin-top 0
@media (max-width: $MQMobile)
@media (max-width $MQMobile)
& &
margin-top $navbarHeight margin-top $navbarHeight
img img
max-width 100% !important max-width 100% !important
table table
position relative position relative
...@@ -106,18 +115,19 @@ main.page ...@@ -106,18 +115,19 @@ main.page
word-break break-all word-break break-all
h1, h2, h3, h4, h5, h6 h1, h2, h3, h4, h5, h6
{$contentClass}:not(.custom) > & {$contentClass}:not(.custom) > &
margin-top (5rem - $navbarHeight) margin-top 5rem - $navbarHeight
padding-top ($navbarHeight - 3rem) padding-top: ($navbarHeight - 3rem)
&:first-child &:first-child
margin-top (3rem - $navbarHeight) margin-top 3rem - $navbarHeight
padding-top ($navbarHeight - 3rem) padding-top: ($navbarHeight - 3rem)
@media (max-width: $MQMobile)
@media (max-width $MQMobile)
& &
margin-top 3rem margin-top 3rem
@media (min-width: $MQMobile)
@media (min-width $MQMobile)
.nav-dropdown .nav-dropdown
z-index 1 z-index 1
......
...@@ -5,5 +5,5 @@ $navbarHeight = 9rem ...@@ -5,5 +5,5 @@ $navbarHeight = 9rem
$navbar-sub-navbar-height = 5rem $navbar-sub-navbar-height = 5rem
$navbar-background-color = #f7f7f7 $navbar-background-color = #f7f7f7
$search-container-color = #f5f6f7 $search-container-color = #f5f6f7
$vuepress-toc-width = 220px $vuepress-toc-width = 14rem
$vuepress-display-min-width = 1500px $vuepress-display-min-width = 1500px
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册