Skip to content

Commit 8699de4

Browse files
author
Benibur
committed
docs: add language switcher, sidebar filter, switch root redirect to /en/
- _includes/head_custom.html: JS that hides side-nav entries belonging to the other language and injects a FR↔EN link into the auxiliary nav using each page's lang_alt_url front matter. - index.html: root now redirects to /en/ (was /fr/) since EN is now available.
1 parent 79a58e3 commit 8699de4

2 files changed

Lines changed: 54 additions & 6 deletions

File tree

docs/_includes/head_custom.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<script>
2+
(function () {
3+
function init() {
4+
var path = window.location.pathname;
5+
var currentLang = null;
6+
if (path.indexOf('/fr/') !== -1) currentLang = 'fr';
7+
else if (path.indexOf('/en/') !== -1) currentLang = 'en';
8+
if (!currentLang) return; // root redirect page — nothing to do
9+
10+
// 1. Filter the side nav: hide items that link to the other language
11+
var navItems = document.querySelectorAll('.site-nav .nav-list-item');
12+
navItems.forEach(function (item) {
13+
var link = item.querySelector('.nav-list-link');
14+
if (!link) return;
15+
var href = link.getAttribute('href') || '';
16+
var linkLang = null;
17+
if (href.indexOf('/fr/') !== -1) linkLang = 'fr';
18+
else if (href.indexOf('/en/') !== -1) linkLang = 'en';
19+
if (linkLang && linkLang !== currentLang) {
20+
item.style.display = 'none';
21+
}
22+
});
23+
24+
// 2. Inject the language switcher into the auxiliary nav (top-right)
25+
{% if page.lang_alt_url %}
26+
var altUrl = '{{ page.lang_alt_url | relative_url }}';
27+
var label = currentLang === 'fr' ? 'EN' : 'FR';
28+
var auxNav = document.querySelector('.aux-nav-list');
29+
if (auxNav && altUrl) {
30+
var li = document.createElement('li');
31+
li.className = 'aux-nav-list-item';
32+
var a = document.createElement('a');
33+
a.href = altUrl;
34+
a.className = 'site-button';
35+
a.textContent = label;
36+
li.appendChild(a);
37+
auxNav.insertBefore(li, auxNav.firstChild);
38+
}
39+
{% endif %}
40+
}
41+
42+
if (document.readyState === 'loading') {
43+
document.addEventListener('DOMContentLoaded', init);
44+
} else {
45+
init();
46+
}
47+
})();
48+
</script>

docs/index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
sitemap: false
44
---
55
<!DOCTYPE html>
6-
<html lang="fr">
6+
<html lang="en">
77
<head>
88
<meta charset="utf-8">
9-
<meta http-equiv="refresh" content="0; url={{ '/fr/' | relative_url }}">
10-
<link rel="canonical" href="{{ '/fr/' | relative_url }}">
11-
<title>Open Buro — Tech Sprint 1</title>
12-
<script>window.location.replace("{{ '/fr/' | relative_url }}");</script>
9+
<meta http-equiv="refresh" content="0; url={{ '/en/' | relative_url }}">
10+
<link rel="canonical" href="{{ '/en/' | relative_url }}">
11+
<title>Open Buro — Tech Sprint #1</title>
12+
<script>window.location.replace("{{ '/en/' | relative_url }}");</script>
1313
</head>
1414
<body>
15-
<p><a href="{{ '/fr/' | relative_url }}">Redirection vers la documentation…</a></p>
15+
<p><a href="{{ '/en/' | relative_url }}">Redirecting to the documentation…</a></p>
1616
</body>
1717
</html>

0 commit comments

Comments
 (0)