Skip to content

Commit 4dd939b

Browse files
Use server-side Liquid sidebar override for French nav
Replace the JavaScript-based nav swap with a pure Liquid override of _includes/components/sidebar.html. French pages now get a server-rendered French sidebar at build time, eliminating JS timing issues. English pages use the original theme sidebar unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b6a4797 commit 4dd939b

File tree

2 files changed

+59
-42
lines changed

2 files changed

+59
-42
lines changed

_includes/components/sidebar.html

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{%- comment -%}
2+
Override of just-the-docs sidebar component.
3+
French pages (lang: fr) get a French navigation sidebar.
4+
English pages get the original theme sidebar.
5+
{%- endcomment -%}
6+
7+
{%- if page.lang == 'fr' -%}
8+
<header class="side-bar">
9+
<div class="site-header">
10+
<a href="{{ '/fr/' | relative_url }}" class="site-title lh-tight">
11+
{{ site.title }}
12+
</a>
13+
<button id="menu-button" class="site-button btn-reset" aria-label="Menu" aria-expanded="false">
14+
<svg viewBox="0 0 24 24" class="icon" aria-hidden="true"><use xlink:href="#svg-menu"></use></svg>
15+
</button>
16+
</div>
17+
<nav aria-label="Main" id="site-nav" class="site-nav">
18+
<ul class="nav-list">
19+
{%- assign fr_pages = site.pages | where: "lang", "fr" | sort: "permalink" -%}
20+
{%- for p in fr_pages -%}
21+
<li class="nav-list-item">
22+
<a href="{{ p.permalink | prepend: site.baseurl }}" class="nav-list-link{% if page.permalink == p.permalink %} active{% endif %}">
23+
{{ p.title }}
24+
</a>
25+
</li>
26+
{%- endfor -%}
27+
</ul>
28+
</nav>
29+
<div class="d-md-block d-none site-footer">
30+
{%- capture nav_footer_custom -%}{%- include nav_footer_custom.html -%}{%- endcapture -%}
31+
{%- if nav_footer_custom != "" -%}
32+
{{ nav_footer_custom }}
33+
{%- else -%}
34+
This site uses <a href="https://github.com/just-the-docs/just-the-docs">Just the Docs</a>, a documentation theme for Jekyll.
35+
{%- endif -%}
36+
</div>
37+
</header>
38+
39+
{%- else -%}
40+
41+
<header class="side-bar">
42+
<div class="site-header">
43+
<a href="{{ '/' | relative_url }}" class="site-title lh-tight">{% include title.html %}</a>
44+
<button id="menu-button" class="site-button btn-reset" aria-label="Menu" aria-expanded="false">
45+
<svg viewBox="0 0 24 24" class="icon" aria-hidden="true"><use xlink:href="#svg-menu"></use></svg>
46+
</button>
47+
</div>
48+
{% include_cached components/site_nav.html %}
49+
<div class="d-md-block d-none site-footer">
50+
{%- capture nav_footer_custom -%}{%- include nav_footer_custom.html -%}{%- endcapture -%}
51+
{%- if nav_footer_custom != "" -%}
52+
{{ nav_footer_custom }}
53+
{%- else -%}
54+
This site uses <a href="https://github.com/just-the-docs/just-the-docs">Just the Docs</a>, a documentation theme for Jekyll.
55+
{%- endif -%}
56+
</div>
57+
</header>
58+
59+
{%- endif -%}

_includes/head_custom.html

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,45 +22,3 @@
2222
}
2323
}
2424
</style>
25-
26-
{% if page.lang == 'fr' %}
27-
<style>
28-
/* Hide English nav items immediately to prevent flash */
29-
.site-nav .nav-list { visibility: hidden; }
30-
</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>
66-
{% endif %}

0 commit comments

Comments
 (0)