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

Changing repo label depending on the host #168

Merged
merged 6 commits into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/default-theme-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ next: false
---
```

## GitHub Repo and Edit Links
## Git Repo and Edit Links

Providing `themeConfig.repo` auto generates a GitHub link in the navbar and "Edit this page" links at the bottom of each page.

Expand All @@ -226,6 +226,9 @@ module.exports = {
themeConfig: {
// Assumes GitHub. Can also be a full GitLab url.
repo: 'vuejs/vuepress',
// Customising the header label
// Defaults to "GitHub"/"GitLab"/"Bitbucket" depending on `themeConfig.repo`
repoLabel: 'Contribute!',
// if your docs are not at the root of the repo
docsDir: 'docs',
// optional, defaults to master
Expand Down
37 changes: 27 additions & 10 deletions lib/default-theme/NavLinks.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<nav class="nav-links" v-if="userLinks.length || githubLink">
<nav class="nav-links" v-if="userLinks.length || repoLink">
<!-- user links -->
<div
class="nav-item"
Expand All @@ -8,13 +8,13 @@
<DropdownLink v-if="item.type === 'links'" :item="item"/>
<NavLink v-else :item="item"/>
</div>
<!-- github link -->
<a v-if="githubLink"
:href="githubLink"
class="github-link"
<!-- repo link -->
<a v-if="repoLink"
:href="repoLink"
class="repo-link"
target="_blank"
rel="noopener noreferrer">
GitHub
{{ repoLabel }}
<OutboundLink/>
</a>
</nav>
Expand Down Expand Up @@ -69,14 +69,31 @@ export default {
})
}))
},
githubLink () {
repoLink () {
const { repo } = this.$site.themeConfig
if (repo) {
return /^https?:/.test(repo)
? repo
: `https://github.com/${repo}`
}
}
},
repoLabel () {
if (!this.repoLink) return
if (this.$site.themeConfig.repoLabel) {
return this.$site.themeConfig.repoLabel
}

const repoHost = this.repoLink.match(/^https?:\/\/[^/]+/)[0]
const platforms = ['GitHub', 'GitLab', 'Bitbucket']
for (let i = 0; i < platforms.length; i++) {
const platform = platforms[i]
if (new RegExp(platform, 'i').test(repoHost)) {
return platform
}
}

return 'Source'
},
},
methods: {
isActive
Expand All @@ -100,12 +117,12 @@ export default {
display inline-block
margin-left 1.5rem
line-height 2rem
.github-link
.repo-link
margin-left 1.5rem

@media (max-width: $MQMobile)
.nav-links
.nav-item, .github-link
.nav-item, .repo-link
margin-left 0

@media (min-width: $MQMobile)
Expand Down