Skip to content

Commit cd3cce0

Browse files
committed
Improve documentation layout
1 parent f209e48 commit cd3cce0

5 files changed

Lines changed: 77 additions & 35 deletions

File tree

docs/_layouts/default.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<link rel="preconnect" href="https://fonts.googleapis.com">
2020
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
2121
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;500&family=Onest:wght@300;400;500;600;700;900&display=swap" rel="stylesheet">
22-
<link href="{{ site.data.manifest['docs.css'] }}" rel="stylesheet">
22+
<link href="{{ site.data.manifest['docs.css'] }}?v={{ site.time | date:'%s' }}" rel="stylesheet">
2323
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css">
2424
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.data.project.google_analytics_tracking_id }}"></script>
2525
<script>
@@ -183,7 +183,7 @@ <h3 class="font-semibold tracking-tight text-slate-900">Older versions</h3>
183183
</div>
184184
</footer>
185185
</div>
186-
<script src="{{ site.data.manifest['docs.js'] }}"></script>
186+
<script src="{{ site.data.manifest['docs.js'] }}?v={{ site.time | date:'%s' }}"></script>
187187
<script src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>
188188
<script> docsearch({
189189
apiKey: '0b444a337a024ecded8e2da9367775fa',

docs/_layouts/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<link rel="preconnect" href="https://fonts.googleapis.com">
1212
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
1313
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;500&family=Onest:wght@300;400;500;600;700;900&display=swap" rel="stylesheet">
14-
<link href="{{ site.data.manifest['docs.css'] }}" rel="stylesheet">
14+
<link href="{{ site.data.manifest['docs.css'] }}?v={{ site.time | date:'%s' }}" rel="stylesheet">
1515
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-46050814-6"></script>
1616
<script>
1717
window.dataLayer = window.dataLayer || [];

docs/_layouts/redirect.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<link rel="preconnect" href="https://fonts.googleapis.com">
2020
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
2121
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;500&family=Onest:wght@300;400;500;600;700;900&display=swap" rel="stylesheet">
22-
<link href="{{ site.data.manifest['docs.css'] }}" rel="stylesheet">
22+
<link href="{{ site.data.manifest['docs.css'] }}?v={{ site.time | date:'%s' }}" rel="stylesheet">
2323
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css">
2424
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.data.project.google_analytics_tracking_id }}"></script>
2525
<script>
@@ -174,7 +174,7 @@ <h1>Redirecting…</h1>
174174
</div>
175175
</footer>
176176
</div>
177-
<script src="{{ site.data.manifest['docs.js'] }}"></script>
177+
<script src="{{ site.data.manifest['docs.js'] }}?v={{ site.time | date:'%s' }}"></script>
178178
<script src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>
179179
<script> docsearch({
180180
apiKey: '0b444a337a024ecded8e2da9367775fa',

docs/input.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ img {
542542
}
543543
}
544544

545-
546545
#onthispage {
547546
@apply sticky top-[4.5rem] h-[calc(100vh-4.5rem)] w-72 overflow-y-auto pr-8 text-sm xl:pr-16 self-start hidden lg:block;
548547
}

docs/scripts.0004.js

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,48 @@
1+
(() => {
2+
const root = document.querySelector('article.content');
3+
if (!root) return;
4+
5+
const isHeading = el => el && el.nodeType === 1 && /^H[1-6]$/.test(el.tagName);
6+
7+
// Récupère tous les titres h2..h6 dans l'ordre du document (live snapshot figé)
8+
const headings = Array.from(root.querySelectorAll('h2, h3, h4, h5, h6'));
9+
10+
for (const h of headings) {
11+
// Idempotence : si ce titre est déjà le 1er enfant d'un .section-wrapper, on ne fait rien
12+
if (h.parentElement?.classList.contains('section-wrapper') &&
13+
h.parentElement.firstElementChild === h) {
14+
continue;
15+
}
16+
17+
const wrapper = document.createElement('div');
18+
wrapper.className = 'section-wrapper';
19+
// (optionnel) pour debug :
20+
wrapper.dataset.heading = h.tagName.toLowerCase();
21+
if (h.id) wrapper.dataset.anchor = h.id;
22+
23+
// Insérer le wrapper juste avant le titre
24+
h.parentNode.insertBefore(wrapper, h);
25+
26+
// Déplacer le titre dans le wrapper
27+
wrapper.appendChild(h);
28+
29+
// Puis déplacer tout ce qui suit IMMÉDIATEMENT jusqu'au prochain heading (quel que soit le niveau)
30+
// -> ainsi on n'englobe jamais les sous-titres
31+
let node = wrapper.nextSibling; // ancien "nextSibling" du h2, devenu celui du wrapper
32+
while (node) {
33+
const next = node.nextSibling; // mémoriser avant déplacement/arrêt
34+
35+
// Si on tombe sur un titre (h1..h6), on s'arrête (le prochain wrapper le prendra en charge)
36+
if (node.nodeType === 1 && isHeading(node)) break;
37+
38+
// Sinon, c'est du contenu d'intro : on le rapatrie dans ce wrapper
39+
wrapper.appendChild(node);
40+
41+
node = next;
42+
}
43+
}
44+
})();
45+
146
(() => {
247
let contentHeaders= document.querySelectorAll("main h2[id]");
348
if (!document.querySelector('html').classList.contains('homepage') && contentHeaders) {
@@ -71,7 +116,7 @@
71116
const menuLinks = document.querySelectorAll('#onthispage a');
72117
const observer = new IntersectionObserver(entries => {
73118
entries.forEach(entry => {
74-
const id = entry.target.getAttribute("id");
119+
const id = entry.target.getAttribute("data-anchor");
75120
const link = document.querySelector(`#onthispage a[href="#${id}"]`);
76121

77122
if (entry.isIntersecting) {
@@ -80,11 +125,12 @@
80125
}
81126
});
82127
}, {
83-
rootMargin: "-50% 0px -50% 0px", // trigger when the section is centered in viewport
128+
root: null,
129+
rootMargin: "0px 0px -100% 0px",
84130
threshold: 0
85131
});
86132

87-
sections.forEach(section => observer.observe(section));
133+
sections.forEach(section => observer.observe(section.parentElement));
88134
}
89135

90136
// generate code snippet copy/paste
@@ -98,29 +144,28 @@
98144
link.classList.add("copy-snippet");
99145
link.innerHTML = "copy 📋";
100146
link.addEventListener('click', function (e) {
101-
let snippetParent = e.target.parentNode;
102-
let notification = snippetParent.querySelector('.copy-snippet-notification');
103-
let content = snippetParent.querySelector('pre').textContent;
104-
try {
105-
navigator.clipboard.writeText(content);
106-
notification.innerHTML = 'Copied!';
107-
notification.classList.add('bg-black');
108-
notification.classList.remove('hidden');
109-
setTimeout(() => {
110-
notification.classList.add('hidden');
111-
notification.classList.remove('bg-black');
112-
}, 500);
113-
} catch (err) {
114-
console.error('Failed to copy: ', err);
115-
notification.innerHTML = 'Copy failed!';
116-
notification.classList.add('bg-red-800');
117-
notification.classList.remove('hidden');
118-
setTimeout(() => {
119-
notification.classList.add('hidden');
120-
notification.classList.remove('bg-red-800');
121-
}, 500);
122-
}
123-
}, false);
147+
let snippetParent = e.target.parentNode;
148+
let notification = snippetParent.querySelector('.copy-snippet-notification');
149+
let content = snippetParent.querySelector('pre').textContent;
150+
try {
151+
navigator.clipboard.writeText(content);
152+
notification.innerHTML = 'Copied!';
153+
notification.classList.add('bg-black');
154+
notification.classList.remove('hidden');
155+
setTimeout(() => {
156+
notification.classList.add('hidden');
157+
notification.classList.remove('bg-black');
158+
}, 500);
159+
} catch (err) {
160+
notification.innerHTML = 'Copy failed!';
161+
notification.classList.add('bg-red-800');
162+
notification.classList.remove('hidden');
163+
setTimeout(() => {
164+
notification.classList.add('hidden');
165+
notification.classList.remove('bg-red-800');
166+
}, 500);
167+
}
168+
}, false);
124169
snippet.appendChild(link);
125170
});
126171

@@ -134,9 +179,7 @@
134179

135180
document.addEventListener('click', (event) => {
136181
if (!dropDownButton.contains(event.target) && !dropDownList.contains(event.target)) {
137-
dropDownList.classList.add('hidden');
182+
dropDownList.classList.add('hidden');
138183
}
139184
});
140185
})();
141-
142-

0 commit comments

Comments
 (0)