Skip to content

Commit b092e2a

Browse files
committed
Improve documentation layout
1 parent d93a5a1 commit b092e2a

File tree

8 files changed

+71
-13
lines changed

8 files changed

+71
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
build
66
composer.lock
77
docs/_site
8+
docs/.jekyll-metadata
89
vendor
910
/nbproject/private/

docs/_data/manifest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"docs.css": "/styles.0005.css",
3-
"docs.js": "/scripts.0003.js"
2+
"docs.css": "/styles.css",
3+
"docs.js": "/scripts.js"
44
}

docs/_layouts/default.html

Lines changed: 3 additions & 3 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>
@@ -42,7 +42,7 @@
4242
<input type="search" id="doc-search" class="w-64" placeholder="search the docs...">
4343
</div>
4444
</header>
45-
<main class="relative flex justify-center mx-auto max-w-8xl sm:px-2 lg:px-8 xl:px-12">
45+
<main class="relative flex justify-center mx-auto max-w-8xl sm:px-2 lg:px-8 xl:px-12 gap-8">
4646
<label for="navigation" class="fixed top-5 right-5 z-50 flex items-center justify-center w-12 h-12 mb-4 ml-4 bg-white border rounded-full shadow-lg cursor-pointer text-slate-600 border-slate-300 lg:hidden transition duration-200 ease-in-out active:scale-95">
4747
<svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
4848
<path stroke-linecap="round" stroke-linejoin="round" d="M4 8h16M4 16h16" />
@@ -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/input.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ img {
562562

563563
@layer components {
564564
#onthispage {
565-
@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;
565+
@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 shrink-0;
566566
}
567567

568568
#onthispage nav h3 {

docs/scripts.0003.js renamed to docs/scripts.js

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,55 @@
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+
const headers = root.querySelectorAll('h2, h3, h4, h5, h6');
7+
const ids = new Set();
8+
headers.forEach(h => {
9+
let id = h.id || h.textContent.trim().toLowerCase().replace(/\W+/g, '-');
10+
let base = id;
11+
let i = 2;
12+
while (ids.has(id)) id = `${base}-${i++}`;
13+
ids.add(id);
14+
h.id = id;
15+
});
16+
17+
for (const h of Array.from(headers)) {
18+
// Idempotence : si ce titre est déjà le 1er enfant d'un .section-wrapper, on ne fait rien
19+
if (h.parentElement?.classList.contains('section-wrapper') &&
20+
h.parentElement.firstElementChild === h) {
21+
continue;
22+
}
23+
24+
const wrapper = document.createElement('div');
25+
wrapper.className = 'section-wrapper';
26+
// (optionnel) pour debug :
27+
wrapper.dataset.heading = h.tagName.toLowerCase();
28+
if (h.id) wrapper.dataset.anchor = h.id;
29+
30+
// Insérer le wrapper juste avant le titre
31+
h.parentNode.insertBefore(wrapper, h);
32+
33+
// Déplacer le titre dans le wrapper
34+
wrapper.appendChild(h);
35+
36+
// Puis déplacer tout ce qui suit IMMÉDIATEMENT jusqu'au prochain heading (quel que soit le niveau)
37+
// -> ainsi on n'englobe jamais les sous-titres
38+
let node = wrapper.nextSibling; // ancien "nextSibling" du h2, devenu celui du wrapper
39+
while (node) {
40+
const next = node.nextSibling; // mémoriser avant déplacement/arrêt
41+
42+
// Si on tombe sur un titre (h1..h6), on s'arrête (le prochain wrapper le prendra en charge)
43+
if (node.nodeType === 1 && isHeading(node)) break;
44+
45+
// Sinon, c'est du contenu d'intro : on le rapatrie dans ce wrapper
46+
wrapper.appendChild(node);
47+
48+
node = next;
49+
}
50+
}
51+
})();
52+
153
(() => {
254
let contentHeaders= document.querySelectorAll("main h2[id]");
355
if (!document.querySelector('html').classList.contains('homepage') && contentHeaders) {
@@ -71,7 +123,7 @@
71123
const menuLinks = document.querySelectorAll('#onthispage a');
72124
const observer = new IntersectionObserver(entries => {
73125
entries.forEach(entry => {
74-
const id = entry.target.getAttribute("id");
126+
const id = entry.target.getAttribute("data-anchor");
75127
const link = document.querySelector(`#onthispage a[href="#${id}"]`);
76128

77129
if (entry.isIntersecting) {
@@ -80,11 +132,12 @@
80132
}
81133
});
82134
}, {
83-
rootMargin: "-50% 0px -50% 0px", // trigger when the section is centered in viewport
135+
root: null,
136+
rootMargin: "0px 0px -100% 0px",
84137
threshold: 0
85138
});
86139

87-
sections.forEach(section => observer.observe(section));
140+
sections.forEach(section => observer.observe(section.parentElement));
88141
}
89142

90143
// generate code snippet copy/paste
@@ -111,7 +164,6 @@
111164
notification.classList.remove('bg-black');
112165
}, 500);
113166
} catch (err) {
114-
console.error('Failed to copy: ', err);
115167
notification.innerHTML = 'Copy failed!';
116168
notification.classList.add('bg-red-800');
117169
notification.classList.remove('hidden');

docs/styles.0005.css renamed to docs/styles.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ video {
594594
display: none;
595595
height: calc(100vh - 4.5rem);
596596
width: 18rem;
597+
flex-shrink: 0;
597598
align-self: flex-start;
598599
overflow-y: auto;
599600
padding-right: 2rem;
@@ -903,6 +904,10 @@ video {
903904
gap: 1.5rem;
904905
}
905906

907+
.gap-8 {
908+
gap: 2rem;
909+
}
910+
906911
.space-y-2 > :not([hidden]) ~ :not([hidden]) {
907912
--tw-space-y-reverse: 0;
908913
margin-top: calc(0.5rem * calc(1 - var(--tw-space-y-reverse)));

0 commit comments

Comments
 (0)