Skip to content

Commit 533a843

Browse files
committed
Improve documentation layout
1 parent d93a5a1 commit 533a843

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

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: '63ba748e8f5bceb91934667c118972d0',

docs/_layouts/homepage.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<link rel="preconnect" href="https://fonts.googleapis.com">
1111
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
1212
<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">
13-
<link href="{{ site.data.manifest['docs.css'] }}" rel="stylesheet">
13+
<link href="{{ site.data.manifest['docs.css'] }}?v={{ site.time | date:'%s' }}" rel="stylesheet">
1414
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-46050814-6"></script>
1515
<script>
1616
window.dataLayer = window.dataLayer || [];

docs/_layouts/redirect.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<title>{{ site.data.project.tagline }} - {{ site.data.project.title }}</title>
1111
<link rel="icon" type="image/x-icon" href="//theme.thephpleague.com/img/favicon.ico" />
1212
<link rel="apple-touch-icon-precomposed" href="//theme.thephpleague.com/img/apple-touch-icon-precomposed.png">
13-
<link rel="stylesheet" href="//theme.thephpleague.com/css/all.css?12">
14-
<link rel="stylesheet"href="{{ site.data.manifest['docs.css'] }}">
13+
<link rel="stylesheet" href="//theme.thephpleague.com/css/all.css?v={{ site.time | date:'%s' }}">
14+
<link rel="stylesheet"href="{{ site.data.manifest['docs.css'] }}?v={{ site.time | date:'%s' }}">
1515
<link rel="canonical" href="{{ page.redirect.to }}">
1616
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.data.project.google_analytics_tracking_id }}"></script>
1717
<script>

docs/scripts.0003.js

Lines changed: 49 additions & 4 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
@@ -111,7 +157,6 @@
111157
notification.classList.remove('bg-black');
112158
}, 500);
113159
} catch (err) {
114-
console.error('Failed to copy: ', err);
115160
notification.innerHTML = 'Copy failed!';
116161
notification.classList.add('bg-red-800');
117162
notification.classList.remove('hidden');

0 commit comments

Comments
 (0)