Skip to content

Commit

Permalink
fix: Correctly interpret URLs of links in the sidebar
Browse files Browse the repository at this point in the history
- closes #589
  • Loading branch information
LouisBarranqueiro committed Dec 15, 2019
1 parent 540336d commit eeedd4a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "node"
- "6"
- "lts/*"
- "8"

Expand Down
4 changes: 2 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ sidebar:
icon: fa fa-archive
search:
title: global.search
url: /#search
url: "#search"
icon: fa fa-search
# `open-algolia-search` classes are used to open algolia search modal
class: open-algolia-search
about:
title: global.about
url: /#about
url: "#about"
icon: fa fa-question
author_links:
github:
Expand Down
32 changes: 19 additions & 13 deletions layout/_partial/sidebar.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,28 @@
<% } %>
</div>
<% } %>
<% for (var i in theme.sidebar) { %>
<% for (var menuName in theme.sidebar) { %>
<ul class="sidebar-buttons">
<% for (var n in theme.sidebar[i]) { %>
<% for (var linkName in theme.sidebar[menuName]) { %>
<li class="sidebar-button">
<% if (url_for(theme.sidebar[i][n].url).indexOf(config.url) < 0 && url_for(theme.sidebar[i][n].url).indexOf(':') >= 0) { %>
<a class="sidebar-button-link <% if (theme.sidebar[i][n].class) { %><%= theme.sidebar[i][n].class %><% } %>" href="<%- url_for(theme.sidebar[i][n].url) %>" target="_blank" rel="noopener" title="<%= __(theme.sidebar[i][n].title) %>">
<% } else { %>
<a class="sidebar-button-link <% if (theme.sidebar[i][n].class) { %><%= theme.sidebar[i][n].class %><% } %>"
<% if (theme.sidebar[i][n].url.indexOf("/") === 0 && theme.sidebar[i][n].url.length === 1) { %> href="<%- url_for(' ') %>"
<% } else if (theme.sidebar[i][n].url.indexOf("/") === 0) { %> href="<%- url_for(theme.sidebar[i][n].url.substr(1)) %>"
<% } else { %> href="<%- url_for(theme.sidebar[i][n].url) %>"<%%>
title="<%= __(theme.sidebar[i][n].title) %>"
<%
var link = Object.assign({}, theme.sidebar[menuName][linkName])
link.class = link.class || ''
// TODO: do not re-write URLs starting with `/#` in the next major version.
link.url = link.url.startsWith("/#") ? link.url.substr(1) : link.url
link.url = url_for(link.url)
%>
<a
class="sidebar-button-link <%= link.class %>"
href="<%- link.url %>"
<% if (!link.url.startsWith(config.url) && link.url.includes(':')) { %>
target="_blank"
<% } %>
rel="noopener"
title="<%= __(link.title) %>"
>
<% } %>
<i class="sidebar-button-icon <%= theme.sidebar[i][n].icon %>" aria-hidden="true"></i>
<span class="sidebar-button-desc"><%= __(theme.sidebar[i][n].title) %></span>
<i class="sidebar-button-icon <%= link.icon %>" aria-hidden="true"></i>
<span class="sidebar-button-desc"><%= __(link.title) %></span>
</a>
</li>
<% } %>
Expand Down

0 comments on commit eeedd4a

Please sign in to comment.