File tree 5 files changed +43
-13
lines changed
5 files changed +43
-13
lines changed Original file line number Diff line number Diff line change @@ -9,10 +9,14 @@ module.exports = {
9
9
[ 'link' , { rel : 'icon' , href : `${ base } logo.png` } ]
10
10
] ,
11
11
themeConfig : {
12
- nav : [
12
+ sidebar : [
13
13
'/' ,
14
- '/foo' ,
15
- '/bar'
14
+ '/markdown' ,
15
+ '/assets' ,
16
+ '/using-vue' ,
17
+ '/config' ,
18
+ '/theming' ,
19
+ '/deploy'
16
20
]
17
21
}
18
22
}
Original file line number Diff line number Diff line change 1
1
---
2
- navTitle : Intro
2
+ navTitle : Getting Started
3
3
---
4
4
5
5
# VuePress
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div class =" theme-container" >
3
- <div >
4
- {{ $site.themeConfig }}
5
- </div >
6
- <ul class =" nav" >
7
- <li v-for =" page in $site.pages" >
3
+ <ul class =" sidebar" >
4
+ <li v-for =" page in sortedPages" >
8
5
<router-link :to =" page.path" >
9
6
{{ page.frontmatter.navTitle || page.title || page.path }}
10
7
</router-link >
@@ -20,8 +17,37 @@ import nprogress from 'nprogress'
20
17
import Index from ' ./Index.vue'
21
18
import Page from ' ./Page.vue'
22
19
20
+ function normalize (path ) {
21
+ return path .replace (/ \. (md| html)$ / , ' ' )
22
+ }
23
+
24
+ function findIndex (order , page ) {
25
+ const pagePath = normalize (page .path )
26
+ for (let i = 0 ; i < order .length ; i++ ) {
27
+ if (normalize (order[i]) === pagePath) {
28
+ return i
29
+ }
30
+ }
31
+ return Infinity
32
+ }
33
+
23
34
export default {
24
35
components: { Index , Page },
36
+ computed: {
37
+ sortedPages () {
38
+ const pages = this .$site .pages
39
+ const order = this .$site .themeConfig .sidebar
40
+ if (! order) {
41
+ return pages
42
+ } else {
43
+ return pages .slice ().sort ((a , b ) => {
44
+ const aIndex = findIndex (order, a)
45
+ const bIndex = findIndex (order, b)
46
+ return aIndex - bIndex
47
+ })
48
+ }
49
+ }
50
+ },
25
51
mounted () {
26
52
nprogress .configure ({ showSpinner: false })
27
53
Original file line number Diff line number Diff line change 11
11
margin-left 300px
12
12
margin-bottom 30px
13
13
14
- .nav
14
+ .sidebar
15
15
position fixed
16
16
margin 0
17
17
top 30px
Original file line number Diff line number Diff line change @@ -127,11 +127,11 @@ async function resolveOptions (sourceDir) {
127
127
128
128
// resolve site data
129
129
options . siteData = {
130
- title : siteConfig . title ,
131
- description : siteConfig . description ,
130
+ title : siteConfig . title || '' ,
131
+ description : siteConfig . description || '' ,
132
132
base : siteConfig . base || '/' ,
133
133
pages : pagesData ,
134
- themeConfig : siteConfig . themeConfig
134
+ themeConfig : siteConfig . themeConfig || { }
135
135
}
136
136
137
137
return options
You can’t perform that action at this time.
0 commit comments