Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Disable next and prev links from global config #1761

Merged
merged 5 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 33 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 @@ -161,6 +150,11 @@ export default {
}
}

const LINK_TYPES = {
NEXT: 'next',
PREV: 'prev'
}

function resolvePrev (page, items) {
return find(page, items, -1)
}
Expand All @@ -169,6 +163,29 @@ function resolveNext (page, items) {
return find(page, items, 1)
}

function resolvePageLink (linkType, { $themeConfig, $page, $route, $site, sidebarItems }) {
const resolveLink = linkType === LINK_TYPES.NEXT ? resolveNext : resolvePrev
sarahdayan marked this conversation as resolved.
Show resolved Hide resolved

// Get link config from theme
const { nextLinks, prevLinks } = $themeConfig
const themeLinkConfig = linkType === LINK_TYPES.NEXT ? nextLinks : prevLinks

// Get link config from current page
const { next, prev } = $page.frontmatter
const pageLinkConfig = linkType === LINK_TYPES.NEXT ? next : prev

// Page link config will overwrite global theme link config if defined
const link = isNil(pageLinkConfig) ? themeLinkConfig : pageLinkConfig

if (link === false) {
sarahdayan marked this conversation as resolved.
Show resolved Hide resolved
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",
sarahdayan marked this conversation as resolved.
Show resolved Hide resolved
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2",
"vuepress-plugin-container": "^2.0.0"
Expand Down
10 changes: 8 additions & 2 deletions packages/docs/docs/theme/default-theme-config.md
Original file line number Diff line number Diff line change
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
---
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has already been mentioned in the previous section.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but I think it's a good thing to also mention it here as users won't necessarily have read this part before.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean maybe you can update Prev / Next Links to tell folks that they can disable next and prev links from global config ( Instead of updating Git repository and Edit Links). Just my opinion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I can update both parts indeed 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 003f4e8

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