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

prev/next links

上级 f60d8777
...@@ -9,18 +9,19 @@ module.exports = { ...@@ -9,18 +9,19 @@ module.exports = {
['link', { rel: 'icon', href: `${base}logo.png` }] ['link', { rel: 'icon', href: `${base}logo.png` }]
], ],
themeConfig: { themeConfig: {
github: 'vuejs/vuepress',
// sidebar config // sidebar config
sidebar: [ sidebar: [
{ {
title: 'Guide', title: 'Guide',
children: [ children: [
['/', 'Intro'], '/',
'/getting-started', '/getting-started',
'/markdown', '/markdown',
'/assets', '/assets',
'/using-vue', '/using-vue',
'/default-theme', '/default-theme',
'/theming', '/custom-themes',
'/deploy' '/deploy'
] ]
}, },
......
---
title: Intro
next: /getting-started
---
# VuePress # VuePress
> Minimalistic docs generator with Vue component based layout system > Minimalistic docs generator with Vue component based layout system
......
---
prev: /markdown
next: /using-vue
---
# Asset Handling # Asset Handling
## Relative URLs ## Relative URLs
......
---
prev: /default-theme
next: /deploy
---
# Custom Themes # Custom Themes
VuePress uses Vue single file components for custom themes. To use a custom layout, create a `.vuepress/theme` directory in your docs root, and then create a `Layout.vue` file: VuePress uses Vue single file components for custom themes. To use a custom layout, create a `.vuepress/theme` directory in your docs root, and then create a `Layout.vue` file:
......
---
prev: /using-vue
next: /custom-themes
---
# Default Theme Configuration # Default Theme Configuration
---
prev: /custom-themes
next: /config
---
# Deploying # Deploying
## GitHub Pages ## GitHub Pages
......
---
prev: /
next: /markdown
---
# Getting Started # Getting Started
## Quickstart ## Quickstart
......
--- ---
prev: /getting-started
next: /assets
meta: meta:
- name: keywords - name: keywords
content: static docs generator vue content: static docs generator vue
......
---
prev: /assets
next: /default-theme
---
# Using Vue in Markdown # Using Vue in Markdown
## Templating ## Templating
......
...@@ -30,6 +30,8 @@ export function createApp () { ...@@ -30,6 +30,8 @@ export function createApp () {
base: siteData.base, base: siteData.base,
mode: 'history', mode: 'history',
fallback: false, fallback: false,
linkActiveClass: '',
linkExactActiveClass: '',
routes routes
}) })
......
<template> <template>
<div class="page"> <div class="page">
<Content/> <Content/>
<div class="content page-nav" v-if="prev || next">
<p>
<span v-if="prev" class="prev">
<router-link v-if="prev" class="prev" :to="prev.path">
{{ prev.title || prev.path }}
</router-link>
</span>
<span v-if="next" class="next">
<router-link v-if="next" :to="next.path">
{{ next.title || next.path }}
</router-link>
</span>
</p>
</div>
</div> </div>
</template> </template>
<script>
import { resolvePage } from './util'
export default {
computed: {
prev () {
const prev = this.$page.frontmatter.prev
return prev && resolvePage(this.$site.pages, prev)
},
next () {
const next = this.$page.frontmatter.next
return next && resolvePage(this.$site.pages, next)
}
}
}
</script>
<style lang="stylus">
@import './styles/config.stylus'
.page-nav.content
p
border-top 1px solid $borderColor
padding-top 1rem
.next
float right
</style>
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
<script> <script>
import SidebarGroup from './SidebarGroup.vue' import SidebarGroup from './SidebarGroup.vue'
import SidebarLink, { isActive, normalize, ensureExt } from './SidebarLink.vue' import SidebarLink, { isActive } from './SidebarLink.vue'
import { resolvePage } from './util'
export default { export default {
components: { SidebarGroup, SidebarLink }, components: { SidebarGroup, SidebarLink },
...@@ -34,7 +35,7 @@ export default { ...@@ -34,7 +35,7 @@ export default {
}, },
computed: { computed: {
sidebarItems () { sidebarItems () {
return resolveSidebar( return resolveSidebarItems(
this.$route, this.$route,
this.$site this.$site
) )
...@@ -66,18 +67,18 @@ function resolveOpenGroupIndex (route, items) { ...@@ -66,18 +67,18 @@ function resolveOpenGroupIndex (route, items) {
return -1 return -1
} }
function resolveSidebar (route, site) { function resolveSidebarItems (route, site) {
const { pages, themeConfig } = site const { pages, themeConfig } = site
const sidebarConfig = themeConfig.sidebar const sidebarConfig = themeConfig.sidebar
if (!sidebarConfig) { if (!sidebarConfig) {
return pages.map(p => Object.assign({ page: 'type' }, p)) return pages.map(p => Object.assign({ page: 'type' }, p))
} else { } else {
const matchingConfig = resolveMatchingSidebar(route, sidebarConfig) const matchingConfig = resolveMatchingSidebarConfig(route, sidebarConfig)
return matchingConfig.map(item => resolveItem(item, pages)) return matchingConfig.map(item => resolveItem(item, pages))
} }
} }
function resolveMatchingSidebar (route, sidebarConfig) { function resolveMatchingSidebarConfig (route, sidebarConfig) {
if (Array.isArray(sidebarConfig)) { if (Array.isArray(sidebarConfig)) {
return sidebarConfig return sidebarConfig
} }
...@@ -117,20 +118,6 @@ function resolveItem (item, pages, isNested) { ...@@ -117,20 +118,6 @@ function resolveItem (item, pages, isNested) {
} }
} }
} }
function resolvePage (pages, rawPath) {
const path = normalize(rawPath)
for (let i = 0; i < pages.length; i++) {
if (normalize(pages[i].path) === path) {
return Object.assign({}, pages[i], {
type: 'page',
path: ensureExt(rawPath)
})
}
}
console.error(`[vuepress] No matching page found for sidebar item "${rawPath}"`)
return {}
}
</script> </script>
<style lang="stylus"> <style lang="stylus">
......
<script> <script>
import { normalize, ensureExt } from './util'
export default { export default {
functional: true, functional: true,
props: ['item'], props: ['item'],
render (h, { parent: { $route }, props: { item }}) { render (h, { parent: { $route }, props: { item }}) {
return h('router-link', { return h('router-link', {
props: { props: {
to: item.path, to: item.path
activeClass: '',
exactActiveClass: ''
}, },
class: { class: {
'sidebar-link': true, 'sidebar-link': true,
...@@ -19,10 +19,6 @@ export default { ...@@ -19,10 +19,6 @@ export default {
} }
} }
const hashRE = /#.*$/
const extRE = /\.(md|html)$/
const slashRE = /\/$/
export function isActive (route, page) { export function isActive (route, page) {
const routePath = normalize(route.path) const routePath = normalize(route.path)
const pagePath = normalize(page.path) const pagePath = normalize(page.path)
...@@ -32,27 +28,13 @@ export function isActive (route, page) { ...@@ -32,27 +28,13 @@ export function isActive (route, page) {
return routePath.indexOf(pagePath) === 0 return routePath.indexOf(pagePath) === 0
} }
} }
export function normalize (path) {
return path
.replace(hashRE, '')
.replace(extRE, '')
}
export function ensureExt (path) {
if (slashRE.test(path)) {
return path
}
const hashMatch = path.match(hashRE)
const hash = hashMatch ? hashMatch[0] : ''
return normalize(path) + '.html' + hash
}
</script> </script>
<style lang="stylus"> <style lang="stylus">
@import './styles/config.stylus' @import './styles/config.stylus'
a.sidebar-link a.sidebar-link
font-weight 400
display inline-block display inline-block
color $textColor color $textColor
border-left 0.25rem solid transparent border-left 0.25rem solid transparent
......
@import './config.stylus' @import './config.stylus'
@import './nprogress.stylus' @import './nprogress.stylus'
html, body
padding 0
margin 0
body body
font-family -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif font-family -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif
-webkit-font-smoothing antialiased -webkit-font-smoothing antialiased
...@@ -24,10 +28,21 @@ body ...@@ -24,10 +28,21 @@ body
border-right 1px solid $borderColor border-right 1px solid $borderColor
overflow-y scroll overflow-y scroll
.markdown .content
max-width 760px max-width $contentWidth
margin 2rem auto margin 2rem auto 3rem
padding 0 2rem padding 0 2rem
a:hover
text-decoration underline
a
font-weight 500
color $accentColor
text-decoration none
p a code
font-weight 400
color $accentColor
blockquote blockquote
font-size 1.25rem font-size 1.25rem
...@@ -39,10 +54,6 @@ blockquote ...@@ -39,10 +54,6 @@ blockquote
ul, ol ul, ol
padding-left 1.2em padding-left 1.2em
a, p a code
color $accentColor
text-decoration none
strong strong
font-weight 600 font-weight 600
...@@ -55,15 +66,15 @@ h1, h2, h3, h4, h5, h6 ...@@ -55,15 +66,15 @@ h1, h2, h3, h4, h5, h6
opacity: 1 opacity: 1
h1 h1
font-size 2.3rem font-size 2.2rem
h2 h2
font-size 1.8rem font-size 1.65rem
padding-bottom .3rem padding-bottom .3rem
border-bottom 1px solid $borderColor border-bottom 1px solid $borderColor
h3 h3
font-size 1.4rem font-size 1.35rem
a.header-anchor a.header-anchor
font-size 0.85em font-size 0.85em
...@@ -72,6 +83,8 @@ a.header-anchor ...@@ -72,6 +83,8 @@ a.header-anchor
padding-right 0.23em padding-right 0.23em
margin-top 0.125em margin-top 0.125em
opacity 0 opacity 0
&:hover
text-decoration none
code code
font-family source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace font-family source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace
...@@ -81,15 +94,13 @@ p, ul, ol ...@@ -81,15 +94,13 @@ p, ul, ol
p, h1, h2, h3, h4, h5, h6 p, h1, h2, h3, h4, h5, h6
code code
color lighten($textColor, 20%)
padding 0.2rem 0.5rem padding 0.2rem 0.5rem
margin 0 margin 0
font-size 0.85rem font-size 0.85rem
background-color rgba(27,31,35,0.05) background-color rgba(27,31,35,0.05)
border-radius 3px border-radius 3px
p code
color lighten($textColor, 20%)
pre, pre[class*="language-"] pre, pre[class*="language-"]
background-color $codeBgColor background-color $codeBgColor
color #fff color #fff
...@@ -172,7 +183,7 @@ $mobileSidebarWidth = $sidebarWidth * 0.82 ...@@ -172,7 +183,7 @@ $mobileSidebarWidth = $sidebarWidth * 0.82
width $mobileSidebarWidth width $mobileSidebarWidth
.page .page
padding-left $mobileSidebarWidth padding-left $mobileSidebarWidth
.markdown .content
margin 1.5rem 0 margin 1.5rem 0
padding 0 1.5rem padding 0 1.5rem
...@@ -192,6 +203,6 @@ $mobileSidebarWidth = $sidebarWidth * 0.82 ...@@ -192,6 +203,6 @@ $mobileSidebarWidth = $sidebarWidth * 0.82
pre, pre[class*="language-"] pre, pre[class*="language-"]
margin 0 -1.5rem margin 0 -1.5rem
border-radius 0 border-radius 0
.markdown .content
margin 1rem 0 margin 1rem 0
padding 0 1rem padding 0 1rem
const hashRE = /#.*$/
const extRE = /\.(md|html)$/
const slashRE = /\/$/
export function normalize (path) {
return path
.replace(hashRE, '')
.replace(extRE, '')
}
export function ensureExt (path) {
if (slashRE.test(path)) {
return path
}
const hashMatch = path.match(hashRE)
const hash = hashMatch ? hashMatch[0] : ''
return normalize(path) + '.html' + hash
}
export function resolvePage (pages, rawPath) {
const path = normalize(rawPath)
for (let i = 0; i < pages.length; i++) {
if (normalize(pages[i].path) === path) {
return Object.assign({}, pages[i], {
type: 'page',
path: ensureExt(rawPath)
})
}
}
console.error(`[vuepress] No matching page found for sidebar item "${rawPath}"`)
return {}
}
...@@ -32,7 +32,7 @@ module.exports = function (src) { ...@@ -32,7 +32,7 @@ module.exports = function (src) {
const { html, hoistedTags } = markdown.renderWithHoisting(content) const { html, hoistedTags } = markdown.renderWithHoisting(content)
return ( return (
`<template>\n` + `<template>\n` +
`<div class="markdown">${html}</div>\n` + `<div class="markdown content">${html}</div>\n` +
`</template>\n` + `</template>\n` +
hoistedTags.join('\n') hoistedTags.join('\n')
) )
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册