提交 b4ca0e4c 编写于 作者: E Evan You

nav ordering

上级 b4f82b7f
...@@ -9,10 +9,14 @@ module.exports = { ...@@ -9,10 +9,14 @@ module.exports = {
['link', { rel: 'icon', href: `${base}logo.png` }] ['link', { rel: 'icon', href: `${base}logo.png` }]
], ],
themeConfig: { themeConfig: {
nav: [ sidebar: [
'/', '/',
'/foo', '/markdown',
'/bar' '/assets',
'/using-vue',
'/config',
'/theming',
'/deploy'
] ]
} }
} }
--- ---
navTitle: Intro navTitle: Getting Started
--- ---
# VuePress # VuePress
......
<template> <template>
<div class="theme-container"> <div class="theme-container">
<div> <ul class="sidebar">
{{ $site.themeConfig }} <li v-for="page in sortedPages">
</div>
<ul class="nav">
<li v-for="page in $site.pages">
<router-link :to="page.path"> <router-link :to="page.path">
{{ page.frontmatter.navTitle || page.title || page.path }} {{ page.frontmatter.navTitle || page.title || page.path }}
</router-link> </router-link>
...@@ -20,8 +17,37 @@ import nprogress from 'nprogress' ...@@ -20,8 +17,37 @@ import nprogress from 'nprogress'
import Index from './Index.vue' import Index from './Index.vue'
import Page from './Page.vue' import Page from './Page.vue'
function normalize (path) {
return path.replace(/\.(md|html)$/, '')
}
function findIndex (order, page) {
const pagePath = normalize(page.path)
for (let i = 0; i < order.length; i++) {
if (normalize(order[i]) === pagePath) {
return i
}
}
return Infinity
}
export default { export default {
components: { Index, Page }, components: { Index, Page },
computed: {
sortedPages () {
const pages = this.$site.pages
const order = this.$site.themeConfig.sidebar
if (!order) {
return pages
} else {
return pages.slice().sort((a, b) => {
const aIndex = findIndex(order, a)
const bIndex = findIndex(order, b)
return aIndex - bIndex
})
}
}
},
mounted () { mounted () {
nprogress.configure({ showSpinner: false }) nprogress.configure({ showSpinner: false })
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
margin-left 300px margin-left 300px
margin-bottom 30px margin-bottom 30px
.nav .sidebar
position fixed position fixed
margin 0 margin 0
top 30px top 30px
......
...@@ -127,11 +127,11 @@ async function resolveOptions (sourceDir) { ...@@ -127,11 +127,11 @@ async function resolveOptions (sourceDir) {
// resolve site data // resolve site data
options.siteData = { options.siteData = {
title: siteConfig.title, title: siteConfig.title || '',
description: siteConfig.description, description: siteConfig.description || '',
base: siteConfig.base || '/', base: siteConfig.base || '/',
pages: pagesData, pages: pagesData,
themeConfig: siteConfig.themeConfig themeConfig: siteConfig.themeConfig || {}
} }
return options return options
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册