Skip to content

Commit

Permalink
feat: Disable next and prev links from global config (#1761)
Browse files Browse the repository at this point in the history
* core: add lodash deps

* core: disable next and prev links from global config

* doc: add documentation

* core: resolvePageLink function refactoring

* docs: Improve Prev 'Next links' section description
  • Loading branch information
kefranabg committed Sep 5, 2019
1 parent dad9c8c commit 92a1c02
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
55 changes: 39 additions & 16 deletions packages/@vuepress/theme-default/components/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
</template>

<script>
import isString from 'lodash/isString'
import isNil from 'lodash/isNil'
import { resolvePage, outboundRE, endingSlashRE } from '../util'
export default {
Expand All @@ -83,25 +86,11 @@ export default {
},
prev () {
const prev = this.$page.frontmatter.prev
if (prev === false) {
return
} else if (prev) {
return resolvePage(this.$site.pages, prev, this.$route.path)
} else {
return resolvePrev(this.$page, this.sidebarItems)
}
return resolvePageLink(LINK_TYPES.PREV, this)
},
next () {
const next = this.$page.frontmatter.next
if (next === false) {
return
} else if (next) {
return resolvePage(this.$site.pages, next, this.$route.path)
} else {
return resolveNext(this.$page, this.sidebarItems)
}
return resolvePageLink(LINK_TYPES.NEXT, this)
},
editLink () {
Expand Down Expand Up @@ -169,6 +158,40 @@ function resolveNext (page, items) {
return find(page, items, 1)
}
const LINK_TYPES = {
NEXT: {
resolveLink: resolveNext,
getThemeLinkConfig: ({ nextLinks }) => nextLinks,
getPageLinkConfig: ({ frontmatter }) => frontmatter.next
},
PREV: {
resolveLink: resolvePrev,
getThemeLinkConfig: ({ prevLinks }) => prevLinks,
getPageLinkConfig: ({ frontmatter }) => frontmatter.prev
}
}
function resolvePageLink (linkType, { $themeConfig, $page, $route, $site, sidebarItems }) {
const { resolveLink, getThemeLinkConfig, getPageLinkConfig } = linkType
// Get link config from theme
const themeLinkConfig = getThemeLinkConfig($themeConfig)
// Get link config from current page
const pageLinkConfig = getPageLinkConfig($page)
// Page link config will overwrite global theme link config if defined
const link = isNil(pageLinkConfig) ? themeLinkConfig : pageLinkConfig
if (link === false) {
return
} else if (isString(link)) {
return resolvePage($site.pages, link, $route.path)
} else {
return resolveLink($page, sidebarItems)
}
}
function find (page, items, offset) {
const res = []
flatten(items, res)
Expand Down
1 change: 1 addition & 0 deletions packages/@vuepress/theme-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@vuepress/plugin-nprogress": "^1.0.3",
"@vuepress/plugin-search": "^1.0.3",
"docsearch.js": "^2.5.2",
"lodash": "^4.17.15",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2",
"vuepress-plugin-container": "^2.0.0"
Expand Down
12 changes: 9 additions & 3 deletions packages/docs/docs/theme/default-theme-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ Note that it’s `off` by default. If given a `string`, it will be displayed as

## Prev / Next Links

Prev and next links are automatically inferred based on the sidebar order of the active page. You can also explicitly overwrite or disable them using `YAML front matter`:
Prev and next links are automatically inferred based on the sidebar order of the active page. You can also explicitly overwrite or disable them globally with [theme config](/theme/default-theme-config.html#git-repository-and-edit-links) or on specific pages using `YAML front matter`:

``` yaml
---
Expand Down Expand Up @@ -409,17 +409,23 @@ module.exports = {
docsBranch: 'master',
// defaults to false, set to true to enable
editLinks: true,
// default value is true. Allows to hide next page links on all pages
nextLinks: false,
// default value is true. Allows to hide prev page links on all pages
prevLinks: false,
// custom text for edit link. Defaults to "Edit this page"
editLinkText: 'Help us improve this page!'
}
}
```

You can also hide the edit link on a specific page via `YAML front matter`:
You can overwrite the following properties on specific pages via `YAML front matter`:

``` yaml
---
editLink: false
editLink: false # Will overwrite 'editLinks' from themeConfig
prev: true # Will overwrite 'prevLinks' property from themeConfig
next: ./my-next-page # Will overwrite 'nextLinks' property from themeConfig
---
```

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7316,7 +7316,7 @@ lodash.uniq@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"

lodash@^4.0.0, lodash@^4.11.2, lodash@^4.17.12:
lodash@^4.0.0, lodash@^4.11.2, lodash@^4.17.12, lodash@^4.17.15:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"

Expand Down

0 comments on commit 92a1c02

Please sign in to comment.