Skip to content

Commit b4ca0e4

Browse files
committed
nav ordering
1 parent b4f82b7 commit b4ca0e4

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed

docs/.vuepress/config.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ module.exports = {
99
['link', { rel: 'icon', href: `${base}logo.png` }]
1010
],
1111
themeConfig: {
12-
nav: [
12+
sidebar: [
1313
'/',
14-
'/foo',
15-
'/bar'
14+
'/markdown',
15+
'/assets',
16+
'/using-vue',
17+
'/config',
18+
'/theming',
19+
'/deploy'
1620
]
1721
}
1822
}

docs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
navTitle: Intro
2+
navTitle: Getting Started
33
---
44

55
# VuePress

lib/default-theme/Layout.vue

+31-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
<template>
22
<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">
85
<router-link :to="page.path">
96
{{ page.frontmatter.navTitle || page.title || page.path }}
107
</router-link>
@@ -20,8 +17,37 @@ import nprogress from 'nprogress'
2017
import Index from './Index.vue'
2118
import Page from './Page.vue'
2219
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+
2334
export default {
2435
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+
},
2551
mounted () {
2652
nprogress.configure({ showSpinner: false })
2753

lib/default-theme/theme.stylus

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
margin-left 300px
1212
margin-bottom 30px
1313

14-
.nav
14+
.sidebar
1515
position fixed
1616
margin 0
1717
top 30px

lib/prepare.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ async function resolveOptions (sourceDir) {
127127

128128
// resolve site data
129129
options.siteData = {
130-
title: siteConfig.title,
131-
description: siteConfig.description,
130+
title: siteConfig.title || '',
131+
description: siteConfig.description || '',
132132
base: siteConfig.base || '/',
133133
pages: pagesData,
134-
themeConfig: siteConfig.themeConfig
134+
themeConfig: siteConfig.themeConfig || {}
135135
}
136136

137137
return options

0 commit comments

Comments
 (0)