Skip to content

Commit 05a417a

Browse files
authored
feat: add 7 utility shortcodes (admonition, button, carousel, gallery, figure, tabs, video) (#47)
* feat: add 7 utility shortcodes (admonition, button, carousel, gallery, figure, tabs, video) Resolves #6 - admonition (note/tip/warning/danger) with Feather SVG icons, markdown content - button (primary/secondary/outline) with icon slot, external URL detection - carousel: CSS scroll-snap with minimal JS prev/next buttons - figure: HTML5 <figure> with caption, lazy loading, local+remote resources - gallery: CSS grid thumbnails with optional :target CSS-only lightbox - tabs/tab: CSS-only radio-button tabs, keyboard-accessible (arrow keys) - video: HTML5 <video> with poster, caption, responsive container Design: - wvc- CSS prefix to avoid theme conflicts - Dark-mode aware via [data-theme] + CSS variables - Single assets/css/shortcodes.css for all styles - Feather-style open-source SVG icons (MIT) - Theme-aware code block backgrounds (slate in light/dark mode) - Copy-to-clipboard button on all code blocks (highlight + plain pre) Tests: 18 Hugo integration tests added (34 total, all passing) Demo page: exampleSite/content/docs/shortcodes.md * fix: address code review findings for utility shortcodes CRITICAL fixes: - carousel: hide prev/next buttons when 0-1 slides (C1) - tabs: errorf when >5 tabs to prevent silent content loss (C2) - video: fix boolean param parsing (string 'false' was truthy) (C3) - video: auto-enforce muted when autoplay (browser requirement) - video: auto-detect MIME type from file extension - button: remove role=button on <a> (ARIA contract violation) (C4) WARNING fixes: - figure: only use target=_blank for external href links (W1) - button, figure: add noreferrer to rel for external links (W2) - CSS: add focus-visible outlines to all button variants (W9) - CSS: merge duplicate figure/video caption styles (W8) - carousel: fix usage comment (no slide shortcode exists) (I4) Tests updated to match new behavior.
1 parent 8538be4 commit 05a417a

133 files changed

Lines changed: 11407 additions & 15 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

assets/css/shortcodes.css

Lines changed: 354 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
/* ── Wavecast Utility Shortcodes ──────────────────────────────────────────
2+
Dark-mode aware, minimal-JS, accessible. Prefix: wvc-
3+
─────────────────────────────────────────────────────────────────────── */
4+
5+
/* ── Design tokens ── */
6+
:root {
7+
--wvc-note: #0ea5e9;
8+
--wvc-note-bg: #f0f9ff;
9+
--wvc-tip: #22c55e;
10+
--wvc-tip-bg: #f0fdf4;
11+
--wvc-warning: #f59e0b;
12+
--wvc-warning-bg: #fffbeb;
13+
--wvc-danger: #ef4444;
14+
--wvc-danger-bg: #fef2f2;
15+
--wvc-primary: #4f46e5;
16+
--wvc-primary-hover: #4338ca;
17+
--wvc-secondary: #6b7280;
18+
--wvc-secondary-hover: #4b5563;
19+
--wvc-outline-border: #d1d5db;
20+
--wvc-outline-hover-bg: #f3f4f6;
21+
--wvc-tab-border: #d1d5db;
22+
--wvc-tab-active-border: #4f46e5;
23+
--wvc-tab-active-text: #4f46e5;
24+
--wvc-radius: 0.5rem;
25+
}
26+
27+
[data-theme="dark"] {
28+
--wvc-note-bg: #0c2d48;
29+
--wvc-tip-bg: #0a2e1a;
30+
--wvc-warning-bg: #2e2200;
31+
--wvc-danger-bg: #3b0a0a;
32+
--wvc-outline-border: #4b5563;
33+
--wvc-outline-hover-bg: #1f2937;
34+
--wvc-tab-border: #4b5563;
35+
--wvc-tab-active-border: #818cf8;
36+
--wvc-tab-active-text: #a5b4fc;
37+
--wvc-primary: #6366f1;
38+
--wvc-primary-hover: #818cf8;
39+
--wvc-secondary: #9ca3af;
40+
--wvc-secondary-hover: #d1d5db;
41+
}
42+
43+
/* ── Admonition ── */
44+
.wvc-admonition {
45+
border-left: 4px solid;
46+
padding: 1rem 1.25rem;
47+
margin: 1.5rem 0;
48+
border-radius: 0 var(--wvc-radius) var(--wvc-radius) 0;
49+
font-size: 0.95rem;
50+
line-height: 1.65;
51+
}
52+
.wvc-admonition--note { border-color: var(--wvc-note); background: var(--wvc-note-bg); }
53+
.wvc-admonition--tip { border-color: var(--wvc-tip); background: var(--wvc-tip-bg); }
54+
.wvc-admonition--warning { border-color: var(--wvc-warning); background: var(--wvc-warning-bg); }
55+
.wvc-admonition--danger { border-color: var(--wvc-danger); background: var(--wvc-danger-bg); }
56+
57+
.wvc-admonition__header {
58+
display: flex;
59+
align-items: center;
60+
gap: 0.5rem;
61+
margin-bottom: 0.25rem;
62+
}
63+
.wvc-admonition__icon {
64+
display: flex;
65+
align-items: center;
66+
flex-shrink: 0;
67+
}
68+
.wvc-admonition--note .wvc-admonition__icon { color: var(--wvc-note); }
69+
.wvc-admonition--tip .wvc-admonition__icon { color: var(--wvc-tip); }
70+
.wvc-admonition--warning .wvc-admonition__icon { color: var(--wvc-warning); }
71+
.wvc-admonition--danger .wvc-admonition__icon { color: var(--wvc-danger); }
72+
73+
.wvc-admonition__title {
74+
font-weight: 700;
75+
font-size: 0.95rem;
76+
}
77+
.wvc-admonition__content > :first-child { margin-top: 0; }
78+
.wvc-admonition__content > :last-child { margin-bottom: 0; }
79+
.wvc-admonition__content p { margin: 0.4rem 0; }
80+
81+
/* ── Button ── */
82+
.wvc-button {
83+
display: inline-flex;
84+
align-items: center;
85+
gap: 0.4rem;
86+
padding: 0.55rem 1.2rem;
87+
font-size: 0.9rem;
88+
font-weight: 600;
89+
border-radius: var(--wvc-radius);
90+
text-decoration: none;
91+
cursor: pointer;
92+
border: 2px solid transparent;
93+
transition: background 0.15s, color 0.15s, border-color 0.15s;
94+
line-height: 1.4;
95+
}
96+
.wvc-button--primary {
97+
background: var(--wvc-primary);
98+
color: #fff;
99+
}
100+
.wvc-button--primary:hover { background: var(--wvc-primary-hover); color: #fff; }
101+
102+
.wvc-button--secondary {
103+
background: var(--wvc-secondary);
104+
color: #fff;
105+
}
106+
.wvc-button--secondary:hover { background: var(--wvc-secondary-hover); color: #fff; }
107+
108+
.wvc-button--outline {
109+
background: transparent;
110+
color: var(--wvc-primary);
111+
border-color: var(--wvc-outline-border);
112+
}
113+
.wvc-button--outline:hover { background: var(--wvc-outline-hover-bg); color: var(--wvc-primary-hover); }
114+
115+
.wvc-button:focus-visible {
116+
outline: 2px solid var(--wvc-primary);
117+
outline-offset: 2px;
118+
}
119+
.wvc-button--primary:focus-visible {
120+
outline-color: var(--wvc-primary-hover);
121+
box-shadow: 0 0 0 2px rgba(79,70,229,0.35);
122+
}
123+
.wvc-button--secondary:focus-visible {
124+
outline-color: var(--wvc-secondary-hover);
125+
}
126+
127+
.wvc-button__icon { font-size: 1.1rem; line-height: 1; }
128+
129+
/* ── Figure ── */
130+
.wvc-figure {
131+
margin: 1.5rem 0;
132+
text-align: center;
133+
}
134+
.wvc-figure img {
135+
max-width: 100%;
136+
height: auto;
137+
border-radius: var(--wvc-radius);
138+
display: block;
139+
margin: 0 auto;
140+
}
141+
.wvc-figure__caption,
142+
.wvc-video__caption {
143+
margin-top: 0.6rem;
144+
font-size: 0.88rem;
145+
color: #6b7280;
146+
font-style: italic;
147+
}
148+
[data-theme="dark"] .wvc-figure__caption,
149+
[data-theme="dark"] .wvc-video__caption { color: #9ca3af; }
150+
151+
/* ── Video ── */
152+
.wvc-video {
153+
margin: 1.5rem 0;
154+
text-align: center;
155+
}
156+
.wvc-video video {
157+
max-width: 100%;
158+
height: auto;
159+
border-radius: var(--wvc-radius);
160+
display: block;
161+
margin: 0 auto;
162+
}
163+
164+
/* ── Gallery ── */
165+
.wvc-gallery {
166+
display: grid;
167+
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
168+
gap: 0.75rem;
169+
margin: 1.5rem 0;
170+
}
171+
.wvc-gallery a { display: block; }
172+
.wvc-gallery img {
173+
width: 100%;
174+
height: 200px;
175+
object-fit: cover;
176+
border-radius: var(--wvc-radius);
177+
display: block;
178+
transition: transform 0.2s, box-shadow 0.2s;
179+
}
180+
.wvc-gallery img:hover {
181+
transform: scale(1.03);
182+
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
183+
}
184+
185+
/* ── Lightbox (CSS-only, triggered by :target) ── */
186+
.wvc-lightbox {
187+
display: none;
188+
position: fixed;
189+
inset: 0;
190+
z-index: 9999;
191+
background: rgba(0,0,0,0.85);
192+
align-items: center;
193+
justify-content: center;
194+
}
195+
.wvc-lightbox:target {
196+
display: flex;
197+
}
198+
.wvc-lightbox img {
199+
max-width: 90vw;
200+
max-height: 90vh;
201+
border-radius: var(--wvc-radius);
202+
box-shadow: 0 8px 32px rgba(0,0,0,0.5);
203+
}
204+
.wvc-lightbox__close {
205+
position: absolute;
206+
top: 1.5rem;
207+
right: 1.5rem;
208+
color: #fff;
209+
font-size: 2rem;
210+
text-decoration: none;
211+
line-height: 1;
212+
opacity: 0.8;
213+
}
214+
.wvc-lightbox__close:hover { opacity: 1; }
215+
216+
/* ── Carousel ── */
217+
.wvc-carousel {
218+
position: relative;
219+
margin: 1.5rem 0;
220+
--wvc-carousel-gap: 0.75rem;
221+
}
222+
.wvc-carousel__slides {
223+
display: flex;
224+
gap: var(--wvc-carousel-gap);
225+
overflow-x: auto;
226+
scroll-snap-type: x mandatory;
227+
scroll-behavior: smooth;
228+
-webkit-overflow-scrolling: touch;
229+
scrollbar-width: thin;
230+
border-radius: var(--wvc-radius);
231+
}
232+
.wvc-carousel__slides > * {
233+
scroll-snap-align: start;
234+
flex: 0 0 calc(100% - var(--wvc-carousel-gap));
235+
min-width: 0;
236+
}
237+
.wvc-carousel__slides img {
238+
width: 100%;
239+
height: auto;
240+
border-radius: var(--wvc-radius);
241+
display: block;
242+
}
243+
.wvc-carousel__prev,
244+
.wvc-carousel__next {
245+
position: absolute;
246+
top: 50%;
247+
transform: translateY(-50%);
248+
z-index: 2;
249+
background: rgba(0,0,0,0.5);
250+
color: #fff;
251+
border: none;
252+
border-radius: 50%;
253+
width: 2.5rem;
254+
height: 2.5rem;
255+
font-size: 1.5rem;
256+
cursor: pointer;
257+
display: flex;
258+
align-items: center;
259+
justify-content: center;
260+
line-height: 1;
261+
transition: background 0.2s;
262+
padding: 0;
263+
}
264+
.wvc-carousel__prev:hover,
265+
.wvc-carousel__next:hover { background: rgba(0,0,0,0.75); }
266+
.wvc-carousel__prev { left: 0.5rem; }
267+
.wvc-carousel__next { right: 0.5rem; }
268+
269+
/* ── Tabs ── */
270+
.wvc-tabs {
271+
margin: 1.5rem 0;
272+
position: relative; /* containing block for clipped radio inputs */
273+
}
274+
.wvc-tabs__labels {
275+
display: flex;
276+
flex-wrap: wrap;
277+
border-bottom: 2px solid var(--wvc-tab-border);
278+
margin-bottom: 1rem;
279+
gap: 0;
280+
}
281+
.wvc-tabs__label {
282+
display: inline-block;
283+
padding: 0.55rem 1.15rem;
284+
font-size: 0.9rem;
285+
font-weight: 600;
286+
color: inherit;
287+
cursor: pointer;
288+
border-bottom: 2px solid transparent;
289+
margin-bottom: -2px;
290+
transition: color 0.15s, border-color 0.15s;
291+
user-select: none;
292+
}
293+
.wvc-tabs__label:hover { color: var(--wvc-tab-active-text); }
294+
295+
/* Visually-hidden radio inputs — still focusable for keyboard navigation */
296+
.wvc-tabs input[type="radio"] {
297+
position: absolute;
298+
width: 1px;
299+
height: 1px;
300+
padding: 0;
301+
margin: -1px;
302+
overflow: hidden;
303+
clip: rect(0, 0, 0, 0);
304+
white-space: nowrap;
305+
border: 0;
306+
}
307+
308+
/* Focus indicator: highlight corresponding label when radio receives keyboard focus */
309+
.wvc-tabs input[type="radio"]:nth-of-type(1):focus-visible ~ .wvc-tabs__labels label:nth-of-type(1),
310+
.wvc-tabs input[type="radio"]:nth-of-type(2):focus-visible ~ .wvc-tabs__labels label:nth-of-type(2),
311+
.wvc-tabs input[type="radio"]:nth-of-type(3):focus-visible ~ .wvc-tabs__labels label:nth-of-type(3),
312+
.wvc-tabs input[type="radio"]:nth-of-type(4):focus-visible ~ .wvc-tabs__labels label:nth-of-type(4),
313+
.wvc-tabs input[type="radio"]:nth-of-type(5):focus-visible ~ .wvc-tabs__labels label:nth-of-type(5) {
314+
outline: 2px solid var(--wvc-tab-active-border);
315+
outline-offset: 2px;
316+
border-radius: 2px;
317+
}
318+
319+
/* Show panel whose radio is checked (overrides [hidden] attribute) */
320+
.wvc-tabs input[type="radio"]:nth-of-type(1):checked ~ .wvc-tabs__panels .wvc-tabs__panel:nth-of-type(1),
321+
.wvc-tabs input[type="radio"]:nth-of-type(2):checked ~ .wvc-tabs__panels .wvc-tabs__panel:nth-of-type(2),
322+
.wvc-tabs input[type="radio"]:nth-of-type(3):checked ~ .wvc-tabs__panels .wvc-tabs__panel:nth-of-type(3),
323+
.wvc-tabs input[type="radio"]:nth-of-type(4):checked ~ .wvc-tabs__panels .wvc-tabs__panel:nth-of-type(4),
324+
.wvc-tabs input[type="radio"]:nth-of-type(5):checked ~ .wvc-tabs__panels .wvc-tabs__panel:nth-of-type(5) {
325+
display: block;
326+
}
327+
328+
/* Active label style */
329+
.wvc-tabs input[type="radio"]:nth-of-type(1):checked ~ .wvc-tabs__labels label:nth-of-type(1),
330+
.wvc-tabs input[type="radio"]:nth-of-type(2):checked ~ .wvc-tabs__labels label:nth-of-type(2),
331+
.wvc-tabs input[type="radio"]:nth-of-type(3):checked ~ .wvc-tabs__labels label:nth-of-type(3),
332+
.wvc-tabs input[type="radio"]:nth-of-type(4):checked ~ .wvc-tabs__labels label:nth-of-type(4),
333+
.wvc-tabs input[type="radio"]:nth-of-type(5):checked ~ .wvc-tabs__labels label:nth-of-type(5) {
334+
border-bottom-color: var(--wvc-tab-active-border);
335+
color: var(--wvc-tab-active-text);
336+
}
337+
338+
.wvc-tabs__panel {
339+
display: none;
340+
padding: 0.5rem 0;
341+
}
342+
.wvc-tabs__panel > :first-child { margin-top: 0; }
343+
.wvc-tabs__panel > :last-child { margin-bottom: 0; }
344+
345+
/* ── Responsive ── */
346+
@media (max-width: 640px) {
347+
.wvc-gallery { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
348+
.wvc-gallery img { height: 140px; }
349+
.wvc-carousel__prev,
350+
.wvc-carousel__next { width: 2rem; height: 2rem; font-size: 1.2rem; }
351+
.wvc-carousel__prev { left: 0.25rem; }
352+
.wvc-carousel__next { right: 0.25rem; }
353+
.wvc-tabs__label { padding: 0.5rem 0.75rem; font-size: 0.82rem; }
354+
}

0 commit comments

Comments
 (0)