Merge pull request #211 from vuepress-reco/feature/add-sub-sidebar
feat(vuepress-theme-reco): add sub sidebar
This commit is contained in:
commit
6ad09c222e
@ -7,42 +7,38 @@ module.exports = {
|
|||||||
['meta', { name: 'viewport', content: 'width=device-width,initial-scale=1,user-scalable=no' }]
|
['meta', { name: 'viewport', content: 'width=device-width,initial-scale=1,user-scalable=no' }]
|
||||||
],
|
],
|
||||||
// theme: 'reco',
|
// theme: 'reco',
|
||||||
locales: {
|
|
||||||
'/': {
|
|
||||||
lang: 'ja-JP',
|
|
||||||
title: "vuepress-theme-reco",
|
|
||||||
description: 'A simple and beautiful vuepress blog theme.',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
theme: require.resolve('../../packages/vuepress-theme-reco'),
|
theme: require.resolve('../../packages/vuepress-theme-reco'),
|
||||||
themeConfig: {
|
themeConfig: {
|
||||||
locales: {
|
|
||||||
'/': {
|
|
||||||
recoLocales: {
|
|
||||||
pagation: {
|
|
||||||
prev: '上壹頁',
|
|
||||||
next: '下壹頁',
|
|
||||||
go: '前往',
|
|
||||||
jump: '跳轉至'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
nav: [
|
nav: [
|
||||||
{ text: 'Home', link: '/', icon: 'reco-home' },
|
{ text: 'Home', link: '/', icon: 'reco-home' },
|
||||||
{ text: 'TimeLine', link: '/timeline/', icon: 'reco-date' },
|
{ text: 'TimeLine', link: '/timeline/', icon: 'reco-date' },
|
||||||
{ text: 'Contact',
|
{ text: 'sidebar', link: '/views/sidebar/' },
|
||||||
icon: 'reco-message',
|
{ text: 'sidebar', link: '/views/sidebargroup/' }
|
||||||
items: [
|
|
||||||
{ text: 'NPM', link: 'https://www.npmjs.com/~reco_luan', icon: 'reco-npm' },
|
|
||||||
{ text: 'GitHub', link: 'https://github.com/recoluan', icon: 'reco-github' },
|
|
||||||
{ text: '简书', link: 'https://www.jianshu.com/u/cd674a19515e', icon: 'reco-jianshu' },
|
|
||||||
{ text: 'CSDN', link: 'https://blog.csdn.net/recoluan', icon: 'reco-csdn' },
|
|
||||||
{ text: '博客圆', link: 'https://www.cnblogs.com/luanhewei/', icon: 'reco-bokeyuan' },
|
|
||||||
{ text: 'WeChat', link: 'https://mp.weixin.qq.com/s/mXFqeUTegdvPliXknAAG_A', icon: 'reco-wechat' },
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
|
sidebar: {
|
||||||
|
'/views/sidebar/': [
|
||||||
|
'',
|
||||||
|
'bar1',
|
||||||
|
'bar2'
|
||||||
|
],
|
||||||
|
'/views/sidebargroup/': [
|
||||||
|
{
|
||||||
|
title: '基础',
|
||||||
|
collapsable: true,
|
||||||
|
children: [
|
||||||
|
'',
|
||||||
|
'bar1'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '进阶',
|
||||||
|
collapsable: true,
|
||||||
|
children: [
|
||||||
|
'bar2'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
type: 'blog',
|
type: 'blog',
|
||||||
// 博客设置
|
// 博客设置
|
||||||
blogConfig: {
|
blogConfig: {
|
||||||
@ -55,14 +51,14 @@ module.exports = {
|
|||||||
text: 'Tag' // 默认 “标签”
|
text: 'Tag' // 默认 “标签”
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
type: 'blog',
|
|
||||||
logo: '/head.png',
|
logo: '/head.png',
|
||||||
authorAvatar: '/head.png',
|
authorAvatar: '/head.png',
|
||||||
// 搜索设置
|
// 搜索设置
|
||||||
search: true,
|
search: true,
|
||||||
searchMaxSuggestions: 10,
|
searchMaxSuggestions: 10,
|
||||||
// 自动形成侧边导航
|
// 自动形成侧边导航
|
||||||
sidebar: 'auto',
|
// sidebar: 'auto',
|
||||||
|
sidebarDepth: 4,
|
||||||
// 最后更新时间
|
// 最后更新时间
|
||||||
lastUpdated: 'Last Updated',
|
lastUpdated: 'Last Updated',
|
||||||
// 作者
|
// 作者
|
||||||
|
@ -1,10 +1,69 @@
|
|||||||
---
|
---
|
||||||
title: second page in category1
|
title: sidebar test
|
||||||
date: 2019-09-21
|
date: 2019-09-21
|
||||||
|
sidebarDepth: 5
|
||||||
tags:
|
tags:
|
||||||
- tag2
|
- tag2
|
||||||
categories:
|
categories:
|
||||||
- category1
|
- category1
|
||||||
---
|
---
|
||||||
|
|
||||||
second page in category1
|
## 二级标题1
|
||||||
|
|
||||||
|
### 三级标题1-1
|
||||||
|
|
||||||
|
#### 四级标题1-1-1
|
||||||
|
#### 四级标题1-1-2
|
||||||
|
#### 四级标题1-1-3
|
||||||
|
|
||||||
|
### 三体标题1-2
|
||||||
|
|
||||||
|
#### 四级标题1-2-1
|
||||||
|
#### 四级标题1-2-2
|
||||||
|
#### 四级标题1-2-3
|
||||||
|
|
||||||
|
### 三体标题1-3
|
||||||
|
|
||||||
|
#### 四级标题1-3-1
|
||||||
|
#### 四级标题1-3-2
|
||||||
|
#### 四级标题1-3-3
|
||||||
|
|
||||||
|
## 二级标题2
|
||||||
|
|
||||||
|
### 三级标题2-1
|
||||||
|
|
||||||
|
#### 四级标题2-1-1
|
||||||
|
#### 四级标题2-1-2
|
||||||
|
#### 四级标题2-1-3
|
||||||
|
|
||||||
|
### 三体标题2-2
|
||||||
|
|
||||||
|
#### 四级标题2-2-1
|
||||||
|
#### 四级标题2-2-2
|
||||||
|
#### 四级标题2-2-3
|
||||||
|
|
||||||
|
### 三体标题2-3
|
||||||
|
|
||||||
|
#### 四级标题2-3-1
|
||||||
|
#### 四级标题2-3-2
|
||||||
|
#### 四级标题2-3-3
|
||||||
|
|
||||||
|
## 二级标题3
|
||||||
|
|
||||||
|
### 三级标题3-1
|
||||||
|
|
||||||
|
#### 四级标题3-1-1
|
||||||
|
#### 四级标题3-1-2
|
||||||
|
#### 四级标题3-1-3
|
||||||
|
|
||||||
|
### 三体标题3-2
|
||||||
|
|
||||||
|
#### 四级标题3-2-1
|
||||||
|
#### 四级标题3-2-2
|
||||||
|
#### 四级标题3-2-3
|
||||||
|
|
||||||
|
### 三体标题3-3
|
||||||
|
|
||||||
|
#### 四级标题3-3-1
|
||||||
|
#### 四级标题3-3-2
|
||||||
|
#### 四级标题3-3-3
|
2244
example/views/other/webpack.md
Normal file
2244
example/views/other/webpack.md
Normal file
File diff suppressed because it is too large
Load Diff
5
example/views/sidebar/README.md
Normal file
5
example/views/sidebar/README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
title: 介绍
|
||||||
|
---
|
||||||
|
|
||||||
|
介绍
|
5
example/views/sidebar/bar1.md
Normal file
5
example/views/sidebar/bar1.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
title: bar1
|
||||||
|
---
|
||||||
|
|
||||||
|
bar1
|
65
example/views/sidebar/bar2.md
Normal file
65
example/views/sidebar/bar2.md
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
---
|
||||||
|
title: bar2
|
||||||
|
---
|
||||||
|
|
||||||
|
bar2
|
||||||
|
|
||||||
|
## 二级标题1
|
||||||
|
|
||||||
|
### 三级标题1-1
|
||||||
|
|
||||||
|
#### 四级标题1-1-1
|
||||||
|
#### 四级标题1-1-2
|
||||||
|
#### 四级标题1-1-3
|
||||||
|
|
||||||
|
### 三体标题1-2
|
||||||
|
|
||||||
|
#### 四级标题1-2-1
|
||||||
|
#### 四级标题1-2-2
|
||||||
|
#### 四级标题1-2-3
|
||||||
|
|
||||||
|
### 三体标题1-3
|
||||||
|
|
||||||
|
#### 四级标题1-3-1
|
||||||
|
#### 四级标题1-3-2
|
||||||
|
#### 四级标题1-3-3
|
||||||
|
|
||||||
|
## 二级标题2
|
||||||
|
|
||||||
|
### 三级标题2-1
|
||||||
|
|
||||||
|
#### 四级标题2-1-1
|
||||||
|
#### 四级标题2-1-2
|
||||||
|
#### 四级标题2-1-3
|
||||||
|
|
||||||
|
### 三体标题2-2
|
||||||
|
|
||||||
|
#### 四级标题2-2-1
|
||||||
|
#### 四级标题2-2-2
|
||||||
|
#### 四级标题2-2-3
|
||||||
|
|
||||||
|
### 三体标题2-3
|
||||||
|
|
||||||
|
#### 四级标题2-3-1
|
||||||
|
#### 四级标题2-3-2
|
||||||
|
#### 四级标题2-3-3
|
||||||
|
|
||||||
|
## 二级标题3
|
||||||
|
|
||||||
|
### 三级标题3-1
|
||||||
|
|
||||||
|
#### 四级标题3-1-1
|
||||||
|
#### 四级标题3-1-2
|
||||||
|
#### 四级标题3-1-3
|
||||||
|
|
||||||
|
### 三体标题3-2
|
||||||
|
|
||||||
|
#### 四级标题3-2-1
|
||||||
|
#### 四级标题3-2-2
|
||||||
|
#### 四级标题3-2-3
|
||||||
|
|
||||||
|
### 三体标题3-3
|
||||||
|
|
||||||
|
#### 四级标题3-3-1
|
||||||
|
#### 四级标题3-3-2
|
||||||
|
#### 四级标题3-3-3
|
5
example/views/sidebargroup/README.md
Normal file
5
example/views/sidebargroup/README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
title: 介绍
|
||||||
|
---
|
||||||
|
|
||||||
|
介绍
|
5
example/views/sidebargroup/bar1.md
Normal file
5
example/views/sidebargroup/bar1.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
title: bar1
|
||||||
|
---
|
||||||
|
|
||||||
|
bar1
|
65
example/views/sidebargroup/bar2.md
Normal file
65
example/views/sidebargroup/bar2.md
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
---
|
||||||
|
title: bar2
|
||||||
|
---
|
||||||
|
|
||||||
|
bar2
|
||||||
|
|
||||||
|
## 二级标题1
|
||||||
|
|
||||||
|
### 三级标题1-1
|
||||||
|
|
||||||
|
#### 四级标题1-1-1
|
||||||
|
#### 四级标题1-1-2
|
||||||
|
#### 四级标题1-1-3
|
||||||
|
|
||||||
|
### 三体标题1-2
|
||||||
|
|
||||||
|
#### 四级标题1-2-1
|
||||||
|
#### 四级标题1-2-2
|
||||||
|
#### 四级标题1-2-3
|
||||||
|
|
||||||
|
### 三体标题1-3
|
||||||
|
|
||||||
|
#### 四级标题1-3-1
|
||||||
|
#### 四级标题1-3-2
|
||||||
|
#### 四级标题1-3-3
|
||||||
|
|
||||||
|
## 二级标题2
|
||||||
|
|
||||||
|
### 三级标题2-1
|
||||||
|
|
||||||
|
#### 四级标题2-1-1
|
||||||
|
#### 四级标题2-1-2
|
||||||
|
#### 四级标题2-1-3
|
||||||
|
|
||||||
|
### 三体标题2-2
|
||||||
|
|
||||||
|
#### 四级标题2-2-1
|
||||||
|
#### 四级标题2-2-2
|
||||||
|
#### 四级标题2-2-3
|
||||||
|
|
||||||
|
### 三体标题2-3
|
||||||
|
|
||||||
|
#### 四级标题2-3-1
|
||||||
|
#### 四级标题2-3-2
|
||||||
|
#### 四级标题2-3-3
|
||||||
|
|
||||||
|
## 二级标题3
|
||||||
|
|
||||||
|
### 三级标题3-1
|
||||||
|
|
||||||
|
#### 四级标题3-1-1
|
||||||
|
#### 四级标题3-1-2
|
||||||
|
#### 四级标题3-1-3
|
||||||
|
|
||||||
|
### 三体标题3-2
|
||||||
|
|
||||||
|
#### 四级标题3-2-1
|
||||||
|
#### 四级标题3-2-2
|
||||||
|
#### 四级标题3-2-3
|
||||||
|
|
||||||
|
### 三体标题3-3
|
||||||
|
|
||||||
|
#### 四级标题3-3-1
|
||||||
|
#### 四级标题3-3-2
|
||||||
|
#### 四级标题3-3-3
|
@ -23,9 +23,9 @@
|
|||||||
<Sidebar
|
<Sidebar
|
||||||
:items="sidebarItems"
|
:items="sidebarItems"
|
||||||
@toggle-sidebar="toggleSidebar">
|
@toggle-sidebar="toggleSidebar">
|
||||||
<slot
|
<template slot="top">
|
||||||
name="sidebar-top"
|
<PersonalInfo />
|
||||||
slot="top"/>
|
</template>
|
||||||
<slot
|
<slot
|
||||||
name="sidebar-bottom"
|
name="sidebar-bottom"
|
||||||
slot="bottom"/>
|
slot="bottom"/>
|
||||||
@ -53,9 +53,9 @@
|
|||||||
<Sidebar
|
<Sidebar
|
||||||
:items="sidebarItems"
|
:items="sidebarItems"
|
||||||
@toggle-sidebar="toggleSidebar">
|
@toggle-sidebar="toggleSidebar">
|
||||||
<slot
|
<template slot="top">
|
||||||
name="sidebar-top"
|
<PersonalInfo />
|
||||||
slot="top"/>
|
</template>
|
||||||
<slot
|
<slot
|
||||||
name="sidebar-bottom"
|
name="sidebar-bottom"
|
||||||
slot="bottom"/>
|
slot="bottom"/>
|
||||||
@ -74,7 +74,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import Navbar from '@theme/components/Navbar'
|
import Navbar from '@theme/components/Navbar'
|
||||||
import Sidebar from '@theme/components/Sidebar'
|
import Sidebar from '@theme/components/Sidebar'
|
||||||
import { resolveSidebarItems } from '@theme/helpers/utils'
|
import PersonalInfo from '@theme/components/PersonalInfo'
|
||||||
import Password from '@theme/components/Password'
|
import Password from '@theme/components/Password'
|
||||||
import { setTimeout } from 'timers'
|
import { setTimeout } from 'timers'
|
||||||
import moduleTransitonMixin from '@theme/mixins/moduleTransiton'
|
import moduleTransitonMixin from '@theme/mixins/moduleTransiton'
|
||||||
@ -82,12 +82,16 @@ import moduleTransitonMixin from '@theme/mixins/moduleTransiton'
|
|||||||
export default {
|
export default {
|
||||||
mixins: [moduleTransitonMixin],
|
mixins: [moduleTransitonMixin],
|
||||||
|
|
||||||
components: { Sidebar, Navbar, Password },
|
components: { Sidebar, Navbar, Password, PersonalInfo },
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
sidebar: {
|
sidebar: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: true
|
||||||
|
},
|
||||||
|
sidebarItems: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -124,22 +128,14 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
shouldShowSidebar () {
|
shouldShowSidebar () {
|
||||||
const { frontmatter } = this.$page
|
// const { frontmatter } = this.$page
|
||||||
return (
|
// return (
|
||||||
this.sidebar !== false &&
|
// this.sidebar !== false &&
|
||||||
!frontmatter.home &&
|
// !frontmatter.home &&
|
||||||
frontmatter.sidebar !== false &&
|
// frontmatter.sidebar !== false &&
|
||||||
this.sidebarItems.length
|
// this.sidebarItems.length
|
||||||
)
|
// )
|
||||||
},
|
return this.sidebarItems.length > 0
|
||||||
|
|
||||||
sidebarItems () {
|
|
||||||
return resolveSidebarItems(
|
|
||||||
this.$page,
|
|
||||||
this.$page.regularPath,
|
|
||||||
this.$site,
|
|
||||||
this.$localePath
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
pageClasses () {
|
pageClasses () {
|
||||||
|
@ -208,7 +208,7 @@ export default {
|
|||||||
display flex
|
display flex
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
margin 20px auto 0
|
margin 20px auto 0
|
||||||
max-width 1126px
|
max-width $homePageWidth
|
||||||
.blog-list {
|
.blog-list {
|
||||||
flex auto
|
flex auto
|
||||||
width 0
|
width 0
|
||||||
|
@ -11,7 +11,7 @@ const modeOptions = {
|
|||||||
'--default-color-2': 'rgba(255, 255, 255, .2)',
|
'--default-color-2': 'rgba(255, 255, 255, .2)',
|
||||||
'--default-color-1': 'rgba(255, 255, 255, .1)',
|
'--default-color-1': 'rgba(255, 255, 255, .1)',
|
||||||
'--background-color': '#fff',
|
'--background-color': '#fff',
|
||||||
'--box-shadow': '0 1px 6px 0 rgba(0, 0, 0, 0.2)',
|
'--box-shadow': '0 1px 8px 0 rgba(0, 0, 0, 0.1)',
|
||||||
'--box-shadow-hover': '0 2px 16px 0 rgba(0, 0, 0, 0.2)',
|
'--box-shadow-hover': '0 2px 16px 0 rgba(0, 0, 0, 0.2)',
|
||||||
'--text-color': '#242424',
|
'--text-color': '#242424',
|
||||||
'--text-color-sub': '#7F7F7F',
|
'--text-color-sub': '#7F7F7F',
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<main class="page">
|
<main class="page" :style="{ paddingRight: (this.$page.headers || []).length > 0 ? '14rem' : '0' }">
|
||||||
<ModuleTransition>
|
<ModuleTransition>
|
||||||
<div v-show="recoShowModule && $page.title" class="page-title">
|
<div v-show="recoShowModule && $page.title" class="page-title">
|
||||||
<h1>{{$page.title}}</h1>
|
<h1>{{$page.title}}</h1>
|
||||||
@ -72,6 +72,10 @@
|
|||||||
<ModuleTransition delay="0.32">
|
<ModuleTransition delay="0.32">
|
||||||
<Comments v-if="recoShowModule" :isShowComments="shouldShowComments"/>
|
<Comments v-if="recoShowModule" :isShowComments="shouldShowComments"/>
|
||||||
</ModuleTransition>
|
</ModuleTransition>
|
||||||
|
|
||||||
|
<ModuleTransition delay="0.4">
|
||||||
|
<SubSidebar class="side-bar" />
|
||||||
|
</ModuleTransition>
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -80,10 +84,11 @@ import PageInfo from '@theme/components/PageInfo'
|
|||||||
import { resolvePage, outboundRE, endingSlashRE } from '@theme/helpers/utils'
|
import { resolvePage, outboundRE, endingSlashRE } from '@theme/helpers/utils'
|
||||||
import ModuleTransition from '@theme/components/ModuleTransition'
|
import ModuleTransition from '@theme/components/ModuleTransition'
|
||||||
import moduleTransitonMixin from '@theme/mixins/moduleTransiton'
|
import moduleTransitonMixin from '@theme/mixins/moduleTransiton'
|
||||||
|
import SubSidebar from '@theme/components/SubSidebar'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
mixins: [moduleTransitonMixin],
|
mixins: [moduleTransitonMixin],
|
||||||
components: { PageInfo, ModuleTransition },
|
components: { PageInfo, ModuleTransition, SubSidebar },
|
||||||
|
|
||||||
props: ['sidebarItems'],
|
props: ['sidebarItems'],
|
||||||
|
|
||||||
@ -234,9 +239,19 @@ function flatten (items, res) {
|
|||||||
@require '../styles/wrapper.styl'
|
@require '../styles/wrapper.styl'
|
||||||
|
|
||||||
.page
|
.page
|
||||||
|
position relative
|
||||||
padding-top 5rem
|
padding-top 5rem
|
||||||
padding-bottom 2rem
|
padding-bottom 2rem
|
||||||
display block
|
display block
|
||||||
|
.side-bar
|
||||||
|
position fixed
|
||||||
|
top 10rem
|
||||||
|
bottom 10rem
|
||||||
|
right 2rem
|
||||||
|
overflow-y scroll
|
||||||
|
&::-webkit-scrollbar
|
||||||
|
width: 0
|
||||||
|
height: 0
|
||||||
.page-title
|
.page-title
|
||||||
max-width: $contentWidth;
|
max-width: $contentWidth;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
@ -278,6 +293,10 @@ function flatten (items, res) {
|
|||||||
float right
|
float right
|
||||||
|
|
||||||
@media (max-width: $MQMobile)
|
@media (max-width: $MQMobile)
|
||||||
|
.page
|
||||||
|
padding-right 0
|
||||||
|
.side-bar
|
||||||
|
display none
|
||||||
.page-title
|
.page-title
|
||||||
padding: 0 1rem;
|
padding: 0 1rem;
|
||||||
.page-edit
|
.page-edit
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<aside class="sidebar">
|
<aside class="sidebar">
|
||||||
<PersonalInfo/>
|
|
||||||
<NavLinks/>
|
|
||||||
<slot name="top"/>
|
<slot name="top"/>
|
||||||
|
<NavLinks/>
|
||||||
<SidebarLinks :depth="0" :items="items"/>
|
<SidebarLinks :depth="0" :items="items"/>
|
||||||
<slot name="bottom"/>
|
<slot name="bottom"/>
|
||||||
</aside>
|
</aside>
|
||||||
@ -10,13 +9,12 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import SidebarLinks from '@theme/components/SidebarLinks'
|
import SidebarLinks from '@theme/components/SidebarLinks'
|
||||||
import PersonalInfo from '@theme/components/PersonalInfo'
|
|
||||||
import NavLinks from '@theme/components/NavLinks'
|
import NavLinks from '@theme/components/NavLinks'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Sidebar',
|
name: 'Sidebar',
|
||||||
|
|
||||||
components: { SidebarLinks, NavLinks, PersonalInfo },
|
components: { SidebarLinks, NavLinks },
|
||||||
|
|
||||||
props: ['items']
|
props: ['items']
|
||||||
}
|
}
|
||||||
@ -24,6 +22,9 @@ export default {
|
|||||||
|
|
||||||
<style lang="stylus">
|
<style lang="stylus">
|
||||||
.sidebar
|
.sidebar
|
||||||
|
&&::-webkit-scrollbar
|
||||||
|
width: 0
|
||||||
|
height: 0
|
||||||
.personal-info-wrapper
|
.personal-info-wrapper
|
||||||
display none
|
display none
|
||||||
ul
|
ul
|
||||||
@ -46,9 +47,9 @@ export default {
|
|||||||
& > .sidebar-links
|
& > .sidebar-links
|
||||||
padding 1.5rem 0
|
padding 1.5rem 0
|
||||||
& > li > a.sidebar-link
|
& > li > a.sidebar-link
|
||||||
font-size 1.1em
|
font-size 1em
|
||||||
line-height 1.7
|
line-height 1.7
|
||||||
font-weight bold
|
font-weight 500
|
||||||
& > li:not(:first-child)
|
& > li:not(:first-child)
|
||||||
margin-top .75rem
|
margin-top .75rem
|
||||||
|
|
||||||
|
@ -97,23 +97,24 @@ export default {
|
|||||||
border-left none
|
border-left none
|
||||||
|
|
||||||
.sidebar-heading
|
.sidebar-heading
|
||||||
|
position relative
|
||||||
color var(--text-color)
|
color var(--text-color)
|
||||||
transition color .15s ease
|
transition color .15s ease
|
||||||
cursor pointer
|
cursor pointer
|
||||||
font-size 1.1em
|
font-size 1em
|
||||||
font-weight bold
|
font-weight 500
|
||||||
// text-transform uppercase
|
|
||||||
padding 0.35rem 1.5rem 0.35rem 1.25rem
|
padding 0.35rem 1.5rem 0.35rem 1.25rem
|
||||||
width 100%
|
width 100%
|
||||||
box-sizing border-box
|
box-sizing border-box
|
||||||
margin 0
|
margin 0
|
||||||
border-left 0.25rem solid transparent
|
|
||||||
&.open, &:hover
|
&.open, &:hover
|
||||||
color $accentColor
|
color $accentColor
|
||||||
.arrow
|
.arrow
|
||||||
position relative
|
position absolute
|
||||||
top -0.12em
|
top 0
|
||||||
left 0.5em
|
bottom 0
|
||||||
|
right 0.5em
|
||||||
|
margin auto
|
||||||
&.clickable
|
&.clickable
|
||||||
&.active
|
&.active
|
||||||
font-weight 600
|
font-weight 600
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
import { isActive, hashRE, groupHeaders } from '@theme/helpers/utils'
|
import { isActive } from '@theme/helpers/utils'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
functional: true,
|
functional: true,
|
||||||
@ -29,25 +29,26 @@ export default {
|
|||||||
? selfActive || item.children.some(c => isActive($route, item.basePath + '#' + c.slug))
|
? selfActive || item.children.some(c => isActive($route, item.basePath + '#' + c.slug))
|
||||||
: selfActive
|
: selfActive
|
||||||
const link = renderLink(h, item.path, item.title || item.path, active)
|
const link = renderLink(h, item.path, item.title || item.path, active)
|
||||||
|
|
||||||
const configDepth = $page.frontmatter.sidebarDepth ||
|
|
||||||
sidebarDepth ||
|
|
||||||
$themeLocaleConfig.sidebarDepth ||
|
|
||||||
$themeConfig.sidebarDepth
|
|
||||||
|
|
||||||
const maxDepth = configDepth == null ? 1 : configDepth
|
|
||||||
|
|
||||||
const displayAllHeaders = $themeLocaleConfig.displayAllHeaders ||
|
|
||||||
$themeConfig.displayAllHeaders
|
|
||||||
|
|
||||||
if (item.type === 'auto') {
|
|
||||||
return [link, renderChildren(h, item.children, item.basePath, $route, maxDepth)]
|
|
||||||
} else if ((active || displayAllHeaders) && item.headers && !hashRE.test(item.path)) {
|
|
||||||
const children = groupHeaders(item.headers)
|
|
||||||
return [link, renderChildren(h, children, item.path, $route, maxDepth)]
|
|
||||||
} else {
|
|
||||||
return link
|
return link
|
||||||
}
|
|
||||||
|
// const configDepth = $page.frontmatter.sidebarDepth ||
|
||||||
|
// sidebarDepth ||
|
||||||
|
// $themeLocaleConfig.sidebarDepth ||
|
||||||
|
// $themeConfig.sidebarDepth
|
||||||
|
|
||||||
|
// const maxDepth = configDepth == null ? 1 : configDepth
|
||||||
|
|
||||||
|
// const displayAllHeaders = $themeLocaleConfig.displayAllHeaders ||
|
||||||
|
// $themeConfig.displayAllHeaders
|
||||||
|
|
||||||
|
// if (item.type === 'auto') {
|
||||||
|
// return [link, renderChildren(h, item.children, item.basePath, $route, maxDepth)]
|
||||||
|
// } else if ((active || displayAllHeaders) && item.headers && !hashRE.test(item.path)) {
|
||||||
|
// const children = groupHeaders(item.headers)
|
||||||
|
// return [link, renderChildren(h, children, item.path, $route, maxDepth)]
|
||||||
|
// } else {
|
||||||
|
// return link
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,16 +66,16 @@ 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' }, [
|
||||||
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)
|
||||||
])
|
// ])
|
||||||
}))
|
// }))
|
||||||
}
|
// }
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="stylus">
|
<style lang="stylus">
|
||||||
@ -90,18 +91,17 @@ a.sidebar-link
|
|||||||
font-weight 400
|
font-weight 400
|
||||||
display block!important
|
display block!important
|
||||||
color var(--text-color)
|
color var(--text-color)
|
||||||
padding 0.35rem 1rem 0.35rem .75rem
|
padding 0.35rem 1rem 0.35rem 2.25rem
|
||||||
line-height 1.4
|
line-height 1.4
|
||||||
margin 0 1rem 0 1.5rem
|
// margin 0 0 0 1.5rem
|
||||||
box-sizing: border-box
|
box-sizing: border-box
|
||||||
border-radius .25rem
|
|
||||||
&:hover
|
&:hover
|
||||||
color $accentColor
|
color $accentColor
|
||||||
&.active
|
&.active
|
||||||
font-weight 600
|
font-weight 600
|
||||||
color #fff
|
color $accentColor
|
||||||
background $accentColor
|
background lighten($accentColor, 92%)
|
||||||
// border-left-color $accentColor
|
border-right 3px solid $accentColor
|
||||||
.sidebar-group &
|
.sidebar-group &
|
||||||
// padding-left 2rem
|
// padding-left 2rem
|
||||||
.sidebar-sub-headers &
|
.sidebar-sub-headers &
|
||||||
|
@ -88,24 +88,24 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
isInViewPortOfOne () {
|
isInViewPortOfOne () {
|
||||||
const siderbarScroll = document.getElementsByClassName('sidebar')[0]
|
const sidebarScroll = document.getElementsByClassName('sidebar')[0]
|
||||||
let el = document.getElementsByClassName('active sidebar-link')[1]
|
let el = document.getElementsByClassName('active sidebar-link')[1]
|
||||||
if (el == null || el == undefined || el.offsetTop == undefined) {
|
if (el == null || el == undefined || el.offsetTop == undefined) {
|
||||||
el = document.getElementsByClassName('active sidebar-link')[0]
|
el = document.getElementsByClassName('active sidebar-link')[0]
|
||||||
}
|
}
|
||||||
if (el == null || el == undefined || el.offsetTop == undefined) return
|
if (el == null || el == undefined || el.offsetTop == undefined) return
|
||||||
|
|
||||||
const viewPortHeight = siderbarScroll.clientHeight || window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
|
const viewPortHeight = sidebarScroll.clientHeight || window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
|
||||||
const offsetTop = el.offsetTop
|
const offsetTop = el.offsetTop
|
||||||
const offsetBottom = el.offsetTop + el.offsetHeight
|
const offsetBottom = el.offsetTop + el.offsetHeight
|
||||||
const scrollTop = siderbarScroll.scrollTop
|
const scrollTop = sidebarScroll.scrollTop
|
||||||
const bottomVisible = (offsetBottom <= viewPortHeight + scrollTop)
|
const bottomVisible = (offsetBottom <= viewPortHeight + scrollTop)
|
||||||
if (!bottomVisible) {
|
if (!bottomVisible) {
|
||||||
siderbarScroll.scrollTop = (offsetBottom + 5 - viewPortHeight)
|
sidebarScroll.scrollTop = (offsetBottom + 5 - viewPortHeight)
|
||||||
}
|
}
|
||||||
const topVisible = (offsetTop >= scrollTop)
|
const topVisible = (offsetTop >= scrollTop)
|
||||||
if (!topVisible) {
|
if (!topVisible) {
|
||||||
siderbarScroll.scrollTop = (offsetTop - 5)
|
sidebarScroll.scrollTop = (offsetTop - 5)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
68
packages/vuepress-theme-reco/components/SubSideBar.vue
Normal file
68
packages/vuepress-theme-reco/components/SubSideBar.vue
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<script>
|
||||||
|
import { isActive } from '@theme/helpers/utils'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
computed: {
|
||||||
|
headers () {
|
||||||
|
const headers = (this.$page.headers || []).filter(header => header.level === 2)
|
||||||
|
return headers
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
isLinkActive (header) {
|
||||||
|
return isActive(this.$route, this.$page.path + '#' + header.slug)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
render (h) {
|
||||||
|
return h('ul', {
|
||||||
|
class: { 'sub-sidebar-wrapper': true },
|
||||||
|
style: { width: (this.$page.headers || []).length > 0 ? '12rem' : '0' }
|
||||||
|
}, [
|
||||||
|
...(this.$page.headers || []).map(header => {
|
||||||
|
return h('li', {
|
||||||
|
class: {
|
||||||
|
active: this.isLinkActive(header),
|
||||||
|
[`level-${header.level}`]: true
|
||||||
|
},
|
||||||
|
attr: { key: header.title }
|
||||||
|
}, [
|
||||||
|
h('router-link', {
|
||||||
|
class: { 'sidebar-link': true },
|
||||||
|
props: { to: `${this.$page.path}#${header.slug}` }
|
||||||
|
}, header.title)
|
||||||
|
])
|
||||||
|
})
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="stylus" scoped>
|
||||||
|
.sub-sidebar-wrapper
|
||||||
|
width 12rem
|
||||||
|
padding-left 0
|
||||||
|
list-style none
|
||||||
|
font-size 12px
|
||||||
|
li
|
||||||
|
padding .2rem 0
|
||||||
|
cursor pointer
|
||||||
|
border-left 1px solid var(--border-color)
|
||||||
|
a
|
||||||
|
padding 0.35rem 1rem 0.35rem 0rem
|
||||||
|
color var(--text-color)
|
||||||
|
&:hover
|
||||||
|
a
|
||||||
|
color $accentColor
|
||||||
|
&.active
|
||||||
|
border-left 1px solid $accentColor
|
||||||
|
a
|
||||||
|
color $accentColor
|
||||||
|
&.level-1
|
||||||
|
padding-left .4rem
|
||||||
|
&.level-2
|
||||||
|
padding-left .9rem
|
||||||
|
&.level-3
|
||||||
|
padding-left 1.5rem
|
||||||
|
</style>
|
||||||
|
|
@ -122,42 +122,49 @@ export function resolveSidebarItems (page, regularPath, site, localePath) {
|
|||||||
? themeConfig.locales[localePath] || themeConfig
|
? themeConfig.locales[localePath] || themeConfig
|
||||||
: themeConfig
|
: themeConfig
|
||||||
|
|
||||||
const pageSidebarConfig = page.frontmatter.sidebar || localeConfig.sidebar || themeConfig.sidebar
|
// 计算页面的菜单层级
|
||||||
if (pageSidebarConfig === 'auto') {
|
// const pageSidebarConfig = page.frontmatter.sidebar || localeConfig.sidebar || themeConfig.sidebar
|
||||||
return resolveHeaders(page)
|
// if (pageSidebarConfig === 'auto') {
|
||||||
}
|
// return resolveHeaders(page)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const sidebarConfig = localeConfig.sidebar || themeConfig.sidebar
|
||||||
|
// if (!sidebarConfig) {
|
||||||
|
// return []
|
||||||
|
// } else {
|
||||||
|
// const { base, config } = resolveMatchingConfig(regularPath, sidebarConfig)
|
||||||
|
// return config
|
||||||
|
// ? config.map(item => resolveItem(item, pages, base))
|
||||||
|
// : []
|
||||||
|
// }
|
||||||
const sidebarConfig = localeConfig.sidebar || themeConfig.sidebar
|
const sidebarConfig = localeConfig.sidebar || themeConfig.sidebar
|
||||||
if (!sidebarConfig) {
|
|
||||||
return []
|
|
||||||
} else {
|
|
||||||
const { base, config } = resolveMatchingConfig(regularPath, sidebarConfig)
|
const { base, config } = resolveMatchingConfig(regularPath, sidebarConfig)
|
||||||
return config
|
return config
|
||||||
? config.map(item => resolveItem(item, pages, base))
|
? config.map(item => resolveItem(item, pages, base))
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param { Page } page
|
* @param { Page } page
|
||||||
* @returns { SidebarGroup }
|
* @returns { SidebarGroup }
|
||||||
*/
|
*/
|
||||||
function resolveHeaders (page) {
|
// function resolveHeaders (page) {
|
||||||
const headers = groupHeaders(page.headers || [])
|
// const headers = groupHeaders(page.headers || [])
|
||||||
return [{
|
// return [{
|
||||||
type: 'group',
|
// type: 'group',
|
||||||
collapsable: false,
|
// collapsable: false,
|
||||||
title: page.title,
|
// title: page.title,
|
||||||
path: null,
|
// path: null,
|
||||||
children: headers.map(h => ({
|
// children: headers.map(h => ({
|
||||||
type: 'auto',
|
// type: 'auto',
|
||||||
title: h.title,
|
// title: h.title,
|
||||||
basePath: page.path,
|
// basePath: page.path,
|
||||||
path: page.path + '#' + h.slug,
|
// path: page.path + '#' + h.slug,
|
||||||
children: h.children || []
|
// children: h.children || []
|
||||||
}))
|
// }))
|
||||||
}]
|
// }]
|
||||||
}
|
// }
|
||||||
|
|
||||||
export function groupHeaders (headers) {
|
export function groupHeaders (headers) {
|
||||||
// group h3s under h2
|
// group h3s under h2
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<Common>
|
<Common :sidebarItems="sidebarItems">
|
||||||
<component v-if="$frontmatter.home" :is="homeCom"/>
|
<component v-if="$frontmatter.home" :is="homeCom"/>
|
||||||
<Page v-else :sidebar-items="sidebarItems"/>
|
<Page v-else :sidebar-items="sidebarItems"/>
|
||||||
<Footer v-if="$frontmatter.home" class="footer" />
|
<Footer v-if="$frontmatter.home" class="footer" />
|
||||||
|
@ -27,8 +27,8 @@ $lineNumbersWrapperWidth = 2.5rem
|
|||||||
$backgroundColor ?= #fff
|
$backgroundColor ?= #fff
|
||||||
$backgroundColorDark ?= #181818
|
$backgroundColorDark ?= #181818
|
||||||
|
|
||||||
$boxShadow = 0 1px 6px 0 $darkColor2
|
$boxShadow = 0 1px 8px 0 $darkColor1
|
||||||
$boxShadowHover = 0 2px 16px 0 $darkColor2
|
$boxShadowHover = 0 2px 16px 0 $darkColor1
|
||||||
$boxShadowDark = 0 1px 6px 0 $darkColor6
|
$boxShadowDark = 0 1px 6px 0 $darkColor6
|
||||||
$boxShadowHoverDark = 0 2px 16px 0 $darkColor6
|
$boxShadowHoverDark = 0 2px 16px 0 $darkColor6
|
||||||
|
|
||||||
@ -45,3 +45,7 @@ $codeColorDark ?= $darkColor3
|
|||||||
|
|
||||||
$maskColor ?= #888
|
$maskColor ?= #888
|
||||||
$maskColorDark ?= #000
|
$maskColorDark ?= #000
|
||||||
|
|
||||||
|
$homePageWidth = 1126px
|
||||||
|
$contentWidth = 860px
|
||||||
|
$sidebarWidth = 18rem
|
||||||
|
Loading…
Reference in New Issue
Block a user