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

fix: allows no rel attribute on external links in the nav #2338

Merged
merged 5 commits into from Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion packages/@vuepress/theme-default/components/NavLink.vue
Expand Up @@ -71,10 +71,13 @@ export default {
if (this.isNonHttpURI) {
return null
}
if (!this.item.rel && this.item.rel !== undefined) {
return null
}
if (this.item.rel) {
return this.item.rel
}
return this.isBlankTarget ? 'noopener noreferrer' : ''
return this.isBlankTarget ? 'noopener noreferrer' : null
}
},

Expand Down
6 changes: 3 additions & 3 deletions packages/docs/docs/theme/default-theme-config.md
Expand Up @@ -69,14 +69,14 @@ module.exports = {
}
```

Outbound links automatically get `target="_blank" rel="noopener noreferrer"`. You can offer `target` and `rel` to customize the attributes:
Outbound links automatically get `target="_blank" rel="noopener noreferrer"`. You can offer `target` and `rel` to customize the attributes. Passing a "falsy" value to the `rel` attribute will disable that attribute for a link:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, maybe I should make this clearer to say that the falsy value can't be undefined.

Copy link
Collaborator

Choose a reason for hiding this comment

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

IMHO, change the rule. Let user set false rather than falsy value to disable the attribute.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense.


``` js
// .vuepress/config.js
module.exports = {
themeConfig: {
nav: [
{ text: 'External', link: 'https://google.com', target:'_self', rel:'' },
{ text: 'External', link: 'https://google.com', target:'_self', rel:false },
{ text: 'Guide', link: '/guide/', target:'_blank' }
]
}
Expand Down Expand Up @@ -353,7 +353,7 @@ You can improve the search result by [setting `tags` in frontmatter](../guide/fr

```yaml
---
tags:
tags:
- configuration
- theme
- indexing
Expand Down