Skip to content

Commit 25cbd4f

Browse files
committed
fix: show collapsed code previews on landing
1 parent 361556d commit 25cbd4f

3 files changed

Lines changed: 45 additions & 26 deletions

File tree

app.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ function setupCopyButtons() {
2626
}
2727
}
2828

29+
function setupExpandableCodeExamples() {
30+
const buttons = document.querySelectorAll("[data-expandable-code] .code-example-summary");
31+
32+
for (const button of buttons) {
33+
button.addEventListener("click", () => {
34+
const container = button.closest("[data-expandable-code]");
35+
36+
if (!container) {
37+
return;
38+
}
39+
40+
const isOpen = container.classList.toggle("is-open");
41+
button.setAttribute("aria-expanded", isOpen ? "true" : "false");
42+
});
43+
}
44+
}
45+
2946
document.addEventListener("DOMContentLoaded", () => {
3047
setupCopyButtons();
48+
setupExpandableCodeExamples();
3149
});

index.html

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,12 @@ <h3>Add the site map file</h3>
543543
</div>
544544
</article>
545545

546-
<details class="code-example">
547-
<summary class="code-example-summary">
546+
<article class="code-example" data-expandable-code>
547+
<button class="code-example-summary" type="button" aria-expanded="false">
548548
<span class="code-example-label">File</span>
549549
<code>.github/preview-sites.json</code>
550550
<span class="code-example-hint">Click to expand</span>
551-
</summary>
551+
</button>
552552
<div class="code-block">
553553
<button class="copy-button" type="button" data-copy-target="github-preview-sites">
554554
Copy
@@ -574,7 +574,7 @@ <h3>Add the site map file</h3>
574574
]
575575
}</code></pre>
576576
</div>
577-
</details>
577+
</article>
578578

579579
<article class="timeline-step">
580580
<div class="timeline-index">2</div>
@@ -588,12 +588,12 @@ <h3>Add the preview workflow</h3>
588588
</div>
589589
</article>
590590

591-
<details class="code-example">
592-
<summary class="code-example-summary">
591+
<article class="code-example" data-expandable-code>
592+
<button class="code-example-summary" type="button" aria-expanded="false">
593593
<span class="code-example-label">File</span>
594594
<code>.github/workflows/preview.yml</code>
595595
<span class="code-example-hint">Click to expand</span>
596-
</summary>
596+
</button>
597597
<div class="code-block">
598598
<button class="copy-button" type="button" data-copy-target="github-preview-workflow">
599599
Copy
@@ -686,7 +686,7 @@ <h3>Add the preview workflow</h3>
686686
preview-base-domain: ${{ secrets.PREVIEW_BASE_DOMAIN }}
687687
metadata-dir: preview-metadata</code></pre>
688688
</div>
689-
</details>
689+
</article>
690690

691691
<article class="timeline-step">
692692
<div class="timeline-index">3</div>
@@ -700,12 +700,12 @@ <h3>Feed the preview URL into e2e</h3>
700700
</div>
701701
</article>
702702

703-
<details class="code-example">
704-
<summary class="code-example-summary">
703+
<article class="code-example" data-expandable-code>
704+
<button class="code-example-summary" type="button" aria-expanded="false">
705705
<span class="code-example-label">Append to</span>
706706
<code>.github/workflows/preview.yml</code>
707707
<span class="code-example-hint">Click to expand</span>
708-
</summary>
708+
</button>
709709
<div class="code-block">
710710
<button class="copy-button" type="button" data-copy-target="github-preview-e2e">
711711
Copy
@@ -733,7 +733,7 @@ <h3>Feed the preview URL into e2e</h3>
733733
PLAYWRIGHT_BASE_URL: ${{ steps.preview.outputs.link }}
734734
run: yarn playwright test</code></pre>
735735
</div>
736-
</details>
736+
</article>
737737

738738
<article class="timeline-step">
739739
<div class="timeline-index">4</div>
@@ -748,12 +748,12 @@ <h3>Use plain CLI + rsync instead of actions</h3>
748748
</div>
749749
</article>
750750

751-
<details class="code-example">
752-
<summary class="code-example-summary">
751+
<article class="code-example" data-expandable-code>
752+
<button class="code-example-summary" type="button" aria-expanded="false">
753753
<span class="code-example-label">Shell snippet</span>
754754
<code>rsync preview upload</code>
755755
<span class="code-example-hint">Click to expand</span>
756-
</summary>
756+
</button>
757757
<div class="code-block">
758758
<button class="copy-button" type="button" data-copy-target="github-preview-rsync">
759759
Copy
@@ -774,7 +774,7 @@ <h3>Use plain CLI + rsync instead of actions</h3>
774774

775775
echo "Preview URL: https://${DEPLOY_NAME}.${SITE}.${PREVIEW_BASE_DOMAIN}"</code></pre>
776776
</div>
777-
</details>
777+
</article>
778778
</div>
779779
</section>
780780
</main>

styles.css

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,14 @@ img {
498498
align-items: center;
499499
justify-content: space-between;
500500
gap: 1rem;
501+
width: 100%;
502+
border: 0;
503+
background: transparent;
501504
padding: 1rem 1.2rem 0;
502505
cursor: pointer;
503506
list-style: none;
504-
}
505-
506-
.code-example-summary::-webkit-details-marker {
507-
display: none;
507+
color: inherit;
508+
text-align: left;
508509
}
509510

510511
.code-example-label,
@@ -530,11 +531,11 @@ img {
530531
backdrop-filter: none;
531532
}
532533

533-
.code-example:not([open]) .code-block {
534+
.code-example:not(.is-open) .code-block {
534535
max-height: 15rem;
535536
}
536537

537-
.code-example:not([open]) .code-block::after {
538+
.code-example:not(.is-open) .code-block::after {
538539
content: "";
539540
position: absolute;
540541
inset: auto 0 0;
@@ -549,19 +550,19 @@ img {
549550
pointer-events: none;
550551
}
551552

552-
.code-example[open] .code-example-hint::before {
553+
.code-example.is-open .code-example-hint::before {
553554
content: "Expanded";
554555
}
555556

556-
.code-example[open] .code-example-hint {
557+
.code-example.is-open .code-example-hint {
557558
font-size: 0;
558559
}
559560

560-
.code-example:not([open]) .code-example-hint::before {
561+
.code-example:not(.is-open) .code-example-hint::before {
561562
content: "Click to expand";
562563
}
563564

564-
.code-example:not([open]) .code-example-hint {
565+
.code-example:not(.is-open) .code-example-hint {
565566
font-size: 0;
566567
}
567568

0 commit comments

Comments
 (0)