Skip to content

Commit 7a05c67

Browse files
authored
Fix header links (#2588)
1 parent 0771ecf commit 7a05c67

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

docs/js/custom.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@ $(document).ready(function() {
1818
warningBox.hidden = false;
1919
}
2020

21-
$('.md-content a.md-icon').each(function() {
21+
if (!/^\d+\.\d+$/.test(branchName) && branchName !== 'latest') {
22+
branchName = 'master';
23+
}
24+
25+
// Insert version into header links
26+
$('.md-header a.md-logo, #site-name > a').each(function() {
2227
$(this).attr(
2328
'href',
2429
$(this)
2530
.attr('href')
26-
.replace('master/docs/', branchName + '/docs/'),
31+
.replace(/\/en\/[^\/]+\//, '/en/' + branchName + '/'),
2732
);
2833
});
2934

30-
if (!/^\d+\.\d+$/.test(branchName) && branchName !== 'latest') {
31-
branchName = 'master';
32-
}
33-
3435
// Add version pill to top of navigation
3536
$('#site-name').append('<span class="pill">' + branchName + '</span>');
3637

theme/main.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
<div class="main_nav">
2020
<div class="main_nav_content">
2121
<div class="site-header" id="site-name">
22-
<a href="/">{{ config.site_name }}</a>
22+
{% set site_url = config.site_url | default(nav.homepage.url, true) | url %}
23+
{% if not config.use_directory_urls and site_url[0] == site_url[-1] == "." %}
24+
{% set site_url = site_url ~ "/index.html" %}
25+
{% endif %}
26+
<a href="{{ site_url }}">{{ config.site_name }}</a>
2327
</div>
2428
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
2529
<div class="md-sidebar__scrollwrap">

0 commit comments

Comments
 (0)