Skip to content

Commit b6a4797

Browse files
Replace sidebar hiding with French nav on French pages
Instead of hiding the sidebar entirely on French pages, use Liquid to generate a French navigation list at build time and JavaScript to swap the sidebar content on DOMContentLoaded. The site title also links to the French homepage when on French pages. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f2b2e62 commit b6a4797

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

_includes/head_custom.html

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,42 @@
2525

2626
{% if page.lang == 'fr' %}
2727
<style>
28-
/* Hide English sidebar on French pages */
29-
.side-bar { display: none !important; }
30-
.main { margin-left: 0 !important; }
31-
@media (min-width: 50rem) {
32-
.main { max-width: none; padding-left: 2rem; }
33-
}
28+
/* Hide English nav items immediately to prevent flash */
29+
.site-nav .nav-list { visibility: hidden; }
3430
</style>
31+
<script>
32+
document.addEventListener('DOMContentLoaded', function() {
33+
// Point site title to French homepage
34+
var siteTitle = document.querySelector('.site-title');
35+
if (siteTitle) {
36+
siteTitle.href = '{{ site.baseurl }}/fr/';
37+
}
38+
39+
// Replace English nav with French nav
40+
var nav = document.querySelector('.site-nav .nav-list');
41+
if (nav) {
42+
var frPages = [
43+
{% assign fr_pages = site.pages | where: "lang", "fr" | sort: "permalink" %}{% for p in fr_pages %}{ title: {{ p.title | jsonify }}, url: "{{ p.permalink | prepend: site.baseurl }}" },
44+
{% endfor %}
45+
];
46+
47+
nav.innerHTML = '';
48+
var currentPath = window.location.pathname.replace(/\/$/,'');
49+
frPages.forEach(function(p) {
50+
var li = document.createElement('li');
51+
li.className = 'nav-list-item';
52+
var a = document.createElement('a');
53+
a.href = p.url;
54+
a.className = 'nav-list-link';
55+
if (currentPath === p.url.replace(/\/$/,'')) {
56+
a.classList.add('active');
57+
}
58+
a.textContent = p.title;
59+
li.appendChild(a);
60+
nav.appendChild(li);
61+
});
62+
nav.style.visibility = 'visible';
63+
}
64+
});
65+
</script>
3566
{% endif %}

0 commit comments

Comments
 (0)