Skip to content

Commit 01384f9

Browse files
committed
feat: collapse the skill code
1 parent de6463f commit 01384f9

4 files changed

Lines changed: 83 additions & 12 deletions

File tree

assets/css/custom.scss

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,14 +2407,14 @@ footer {
24072407
}
24082408
}
24092409

2410-
.codeblock-copy-wrap {
2410+
.codeblock-wrap {
24112411
position: relative;
24122412

24132413
.codeblock-copy-btn {
24142414
position: absolute;
24152415
top: 10px;
24162416
right: 10px;
2417-
z-index: 2;
2417+
z-index: 3;
24182418
display: inline-flex;
24192419
align-items: center;
24202420
gap: 6px;
@@ -2446,6 +2446,50 @@ footer {
24462446
font-size: 0.85em;
24472447
}
24482448
}
2449+
2450+
.codeblock-expand-btn {
2451+
display: block;
2452+
width: 100%;
2453+
margin-top: -1px;
2454+
padding: 8px 10px;
2455+
font-size: 0.8rem;
2456+
font-weight: 700;
2457+
text-transform: uppercase;
2458+
letter-spacing: 0.03em;
2459+
color: #fff;
2460+
background: #34352b; // slightly lighter than the monokai code bg
2461+
border: none;
2462+
border-radius: 0 0 4px 4px;
2463+
cursor: pointer;
2464+
transition: background 0.15s ease;
2465+
2466+
&:hover {
2467+
background: #414234;
2468+
}
2469+
}
2470+
2471+
// Collapsed state: cap the code block to ~25 lines with a fade.
2472+
&.codeblock-collapsible.is-collapsed {
2473+
.highlight {
2474+
max-height: 34em;
2475+
overflow: hidden;
2476+
}
2477+
2478+
&::after {
2479+
content: "";
2480+
position: absolute;
2481+
left: 0;
2482+
right: 0;
2483+
bottom: 2.4em; // sit above the expand button
2484+
height: 5em;
2485+
pointer-events: none;
2486+
background: linear-gradient(
2487+
to bottom,
2488+
rgba(39, 40, 34, 0),
2489+
rgba(39, 40, 34, 0.95)
2490+
);
2491+
}
2492+
}
24492493
}
24502494
}
24512495
.postMeta {

assets/js/codeblock-copy.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
}
1414

1515
function init() {
16-
var buttons = document.querySelectorAll(".codeblock-copy-btn");
17-
if (!buttons.length) return;
18-
19-
Array.prototype.forEach.call(buttons, function (btn) {
16+
var copyButtons = document.querySelectorAll(".codeblock-copy-btn");
17+
Array.prototype.forEach.call(copyButtons, function (btn) {
2018
btn.addEventListener("click", function () {
21-
var wrap = btn.closest(".codeblock-copy-wrap");
19+
var wrap = btn.closest(".codeblock-wrap");
2220
var pre = wrap && wrap.querySelector("pre");
2321
if (!pre) return;
2422

@@ -27,6 +25,26 @@
2725
});
2826
});
2927
});
28+
29+
var expandButtons = document.querySelectorAll(".codeblock-expand-btn");
30+
Array.prototype.forEach.call(expandButtons, function (btn) {
31+
btn.addEventListener("click", function () {
32+
var wrap = btn.closest(".codeblock-wrap");
33+
if (!wrap) return;
34+
35+
var collapsed = wrap.classList.toggle("is-collapsed");
36+
btn.setAttribute("aria-expanded", collapsed ? "false" : "true");
37+
btn.textContent = collapsed ? "Show more" : "Show less";
38+
39+
// When re-collapsing, keep the top of the block in view.
40+
if (collapsed) {
41+
var top = wrap.getBoundingClientRect().top;
42+
if (top < 0) {
43+
wrap.scrollIntoView({ block: "start" });
44+
}
45+
}
46+
});
47+
});
3048
}
3149

3250
function copyToClipboard(text) {

content/blog/2026-08-31-dont-let-ai-break-your-infra.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ We suggest packaging the workflow as a reusable skill so the agent follows the s
154154

155155
Keep your organization's repository and module conventions in companion rules or skills (depending on your AI framework), rather than in the migration skill itself. If you don't have any, our guides on [Terraform root module structure](https://masterpoint.io/blog/standard-tf-files/) and [root module sizing](https://newsletter.masterpoint.io/p/how-big-should-a-terraform-root-module-be) are a good starting point.
156156

157-
````markdown {copy=true}
157+
````markdown {copy=true collapse=true}
158158
---
159159
name: codify-clickops-iac
160160
description: Safely codify existing manually-managed AWS infrastructure into Terraform/OpenTofu. Use when importing click-ops resources, migrating existing AWS resources into IaC, or generating TF from live infrastructure.
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
{{- $result := transform.HighlightCodeBlock . -}} {{- $copy := or (index
2-
.Attributes "copy") (index .Options "copy") -}} {{- if and $copy (eq (lower
3-
(printf "%v" $copy)) "true") -}}
4-
<div class="codeblock-copy-wrap">
2+
.Attributes "copy") (index .Options "copy") -}} {{- $copy = and $copy (eq (lower
3+
(printf "%v" $copy)) "true") -}} {{- $collapse := or (index .Attributes
4+
"collapse") (index .Options "collapse") -}} {{- $collapse = and $collapse (eq
5+
(lower (printf "%v" $collapse)) "true") -}} {{- if or $copy $collapse -}}
6+
<div
7+
class="codeblock-wrap{{ if $collapse }} codeblock-collapsible is-collapsed{{ end }}"
8+
>
9+
{{ if $copy }}
510
<button
611
type="button"
712
class="codeblock-copy-btn"
813
aria-label="Copy code to clipboard"
914
>
1015
<i class="fa fa-copy"></i> Copy
1116
</button>
12-
{{ $result.Wrapped }}
17+
{{ end }} {{ $result.Wrapped }} {{ if $collapse }}
18+
<button type="button" class="codeblock-expand-btn" aria-expanded="false">
19+
Show more
20+
</button>
21+
{{ end }}
1322
</div>
1423
{{- else -}} {{ $result.Wrapped }} {{- end -}}

0 commit comments

Comments
 (0)