Skip to content

Fix #891 - Adding site-wide and locale-specific support for changing the logo link #1015

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 31 additions & 1 deletion packages/@vuepress/theme-default/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<SidebarButton @toggle-sidebar="$emit('toggle-sidebar')"/>

<router-link
:to="$localePath"
:to="logoLink"
v-if="!isExternal(logoLink)"
class="home-link"
>
<img
Expand All @@ -19,6 +20,26 @@
:class="{ 'can-hide': $site.themeConfig.logo }"
>{{ $siteTitle }}</span>
</router-link>
<a
v-else
:href="logoLink"
class="home-link"
:target="'_blank'"
:rel="'noopener noreferrer'"
>
<img
class="logo"
v-if="$site.themeConfig.logo"
:src="$withBase($site.themeConfig.logo)"
:alt="$siteTitle"
>
<span
ref="siteName"
class="site-name"
v-if="$siteTitle"
:class="{ 'can-hide': $site.themeConfig.logo }"
>{{ $siteTitle }}</span>
</a>

<div
class="links"
Expand All @@ -37,6 +58,7 @@
</template>

<script>
import { isExternal } from '../util'
import SidebarButton from './SidebarButton.vue'
import AlgoliaSearchBox from '@AlgoliaSearchBox'
import SearchBox from '@SearchBox'
Expand Down Expand Up @@ -66,13 +88,21 @@ export default {
window.addEventListener('resize', handleLinksWrapWidth, false)
},

methods: {
isExternal
},

computed: {
algolia () {
return this.$themeLocaleConfig.algolia || this.$site.themeConfig.algolia || {}
},

isAlgoliaSearch () {
return this.algolia && this.algolia.apiKey && this.algolia.indexName
},

logoLink () {
return this.$themeLocaleConfig.logoLink || this.$site.themeConfig.logoLink || this.$localePath
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions packages/docs/docs/theme/default-theme-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,40 @@ If you want to use a completely custom homepage layout, you can also use a [Cust

The Navbar may contain your page title, [Search Box](#search-box), [Navbar Links](#navbar-links), [Languages](../guide/i18n.md) and [Repository Link](#git-repo-and-edit-links), all of them depends on your configuration.

### Logo Link

By default, clicking on the logo redirects you to the [`localePath`](/config/#locales) - the root of the path defined in your current locale. You can change this link on a locale or site-wide level:

```js
// .vuepress/config.js
// Site-wide
module.exports = {
themeConfig: {
logoLink: 'https://yourdomain.com'
}
}
```

```js
// .vuepress/config.js
// Locale-specific
module.exports = {
themeConfig: {
locales: {
'/': {
label: 'English',
logoLink: 'https://yourdomain.com'
},
'/zh': {
label: '简体中文',
logoLink: 'https://yourdomain.cn'
}
}
}
}
```


### Navbar Links

You can add links to the navbar via `themeConfig.nav`:
Expand Down