handzon-core 0.13.3 → 0.13.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "handzon-core",
3
- "version": "0.13.3",
3
+ "version": "0.13.4",
4
4
  "description": "Core framework for Handzon — layouts, components, content + AI libs, and server runtime (handlers, DB, auth, migration runner) consumed by Handzon scaffolds.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -20,6 +20,7 @@ import { join, relative, resolve } from "node:path";
20
20
  import type { Loader } from "astro/loaders";
21
21
  import { glob } from "astro/loaders";
22
22
  import { createHeroMediaSchema } from "./lib/heroMedia";
23
+ import { createTutorialIconSchema } from "./lib/tutorialIcon";
23
24
 
24
25
  const TUTORIALS_REL = "src/content/tutorials";
25
26
  const INDEX_FILE = "_index.json";
@@ -486,7 +487,7 @@ export function tutorialsSchema({ image }: { image: () => import("astro/zod").Zo
486
487
  prerequisites: z.array(z.string()).default([]),
487
488
  nextTutorial: z.string().optional(),
488
489
  cover: image().optional(),
489
- icon: z.union([z.string(), image()]).optional(),
490
+ icon: createTutorialIconSchema(z, image).optional(),
490
491
  steps: z.array(z.string()).optional(),
491
492
  gated: z.boolean().default(false),
492
493
  showProgress: z.boolean().default(true),
@@ -2,6 +2,7 @@
2
2
  import { withBase } from "../lib/base";
3
3
  import type { TutorialEntry, StepEntry } from "../lib/content";
4
4
  import { parseStepId } from "../lib/content";
5
+ import { fallbackTextForTrack, iconForTrack } from "../lib/track-icons";
5
6
  import Progress from "./Progress.tsx";
6
7
  import TrackSelector from "./TrackSelector.tsx";
7
8
 
@@ -35,18 +36,29 @@ const slug = tutorial.id;
35
36
  <div class="track-selector-shell">
36
37
  <section class="track-selector" aria-label="Tutorial track" data-track-fallback>
37
38
  <div class="track-selector-list">
38
- {tutorial.data.tracks.map((track: (typeof tutorial.data.tracks)[number]) => (
39
- <button
40
- type="button"
41
- class="track-selector-option"
42
- data-track-id={track.id}
43
- data-active={track.id === (tutorial.data.defaultTrack ?? tutorial.data.tracks[0]?.id) ? "true" : "false"}
44
- disabled
45
- >
46
- <span class="track-selector-icon-slot" aria-hidden="true"></span>
47
- <span>{track.label}</span>
48
- </button>
49
- ))}
39
+ {tutorial.data.tracks.map((track: (typeof tutorial.data.tracks)[number]) => {
40
+ const icon = iconForTrack(track);
41
+ return (
42
+ <button
43
+ type="button"
44
+ class="track-selector-option"
45
+ data-track-id={track.id}
46
+ data-active={track.id === (tutorial.data.defaultTrack ?? tutorial.data.tracks[0]?.id) ? "true" : "false"}
47
+ disabled
48
+ >
49
+ {icon ? (
50
+ <svg class="track-selector-icon" viewBox="0 0 24 24" aria-hidden="true">
51
+ <path d={icon.path} />
52
+ </svg>
53
+ ) : (
54
+ <span class="track-selector-fallback" aria-hidden="true">
55
+ {fallbackTextForTrack(track)}
56
+ </span>
57
+ )}
58
+ <span>{track.label}</span>
59
+ </button>
60
+ );
61
+ })}
50
62
  </div>
51
63
  </section>
52
64
  <TrackSelector
@@ -1,21 +1,6 @@
1
1
  import { useEffect, useMemo } from "react";
2
- import {
3
- type SimpleIcon,
4
- siC,
5
- siCplusplus,
6
- siGnubash,
7
- siGo,
8
- siJavascript,
9
- siMysql,
10
- siPhp,
11
- siPostgresql,
12
- siPython,
13
- siRuby,
14
- siRust,
15
- siSqlite,
16
- siTypescript,
17
- } from "simple-icons";
18
2
  import { useProgress } from "../lib/progress/useProgress";
3
+ import { fallbackTextForTrack, iconForTrack } from "../lib/track-icons";
19
4
  import { resolveActiveTrack, type TrackOption, trackStyleText } from "../lib/tracks";
20
5
 
21
6
  interface Props {
@@ -35,38 +20,6 @@ function applyTrackStyle(trackId: string | undefined) {
35
20
  style.textContent = trackStyleText(trackId);
36
21
  }
37
22
 
38
- const TRACK_ICONS: Record<string, SimpleIcon> = {
39
- bash: siGnubash,
40
- c: siC,
41
- "c++": siCplusplus,
42
- cpp: siCplusplus,
43
- go: siGo,
44
- js: siJavascript,
45
- javascript: siJavascript,
46
- mysql: siMysql,
47
- php: siPhp,
48
- postgres: siPostgresql,
49
- postgresql: siPostgresql,
50
- py: siPython,
51
- python: siPython,
52
- rb: siRuby,
53
- ruby: siRuby,
54
- rust: siRust,
55
- sqlite: siSqlite,
56
- ts: siTypescript,
57
- typescript: siTypescript,
58
- };
59
-
60
- function iconForTrack(track: TrackOption): SimpleIcon | undefined {
61
- const id = track.id.toLowerCase();
62
- const label = track.label.toLowerCase();
63
- return TRACK_ICONS[id] ?? TRACK_ICONS[label];
64
- }
65
-
66
- function fallbackText(track: TrackOption): string {
67
- return (track.id || track.label).slice(0, 2).toUpperCase();
68
- }
69
-
70
23
  export default function TrackSelector({ tracks, defaultTrack }: Props) {
71
24
  const { state, setPref } = useProgress();
72
25
  const activeTrack = useMemo(
@@ -112,7 +65,7 @@ export default function TrackSelector({ tracks, defaultTrack }: Props) {
112
65
  </svg>
113
66
  ) : (
114
67
  <span className="track-selector-fallback" aria-hidden="true">
115
- {fallbackText(track)}
68
+ {fallbackTextForTrack(track)}
116
69
  </span>
117
70
  )}
118
71
  <span>{track.label}</span>
@@ -0,0 +1,49 @@
1
+ import {
2
+ type SimpleIcon,
3
+ siC,
4
+ siCplusplus,
5
+ siGnubash,
6
+ siGo,
7
+ siJavascript,
8
+ siMysql,
9
+ siPhp,
10
+ siPostgresql,
11
+ siPython,
12
+ siRuby,
13
+ siRust,
14
+ siSqlite,
15
+ siTypescript,
16
+ } from "simple-icons";
17
+ import type { TrackOption } from "./tracks";
18
+
19
+ const TRACK_ICONS: Record<string, SimpleIcon> = {
20
+ bash: siGnubash,
21
+ c: siC,
22
+ "c++": siCplusplus,
23
+ cpp: siCplusplus,
24
+ go: siGo,
25
+ js: siJavascript,
26
+ javascript: siJavascript,
27
+ mysql: siMysql,
28
+ php: siPhp,
29
+ postgres: siPostgresql,
30
+ postgresql: siPostgresql,
31
+ py: siPython,
32
+ python: siPython,
33
+ rb: siRuby,
34
+ ruby: siRuby,
35
+ rust: siRust,
36
+ sqlite: siSqlite,
37
+ ts: siTypescript,
38
+ typescript: siTypescript,
39
+ };
40
+
41
+ export function iconForTrack(track: TrackOption): SimpleIcon | undefined {
42
+ const id = track.id.toLowerCase();
43
+ const label = track.label.toLowerCase();
44
+ return TRACK_ICONS[id] ?? TRACK_ICONS[label];
45
+ }
46
+
47
+ export function fallbackTextForTrack(track: TrackOption): string {
48
+ return (track.id || track.label).slice(0, 2).toUpperCase();
49
+ }
@@ -0,0 +1,10 @@
1
+ import type { ZodString, ZodTypeAny } from "zod";
2
+
3
+ type ZodLike = {
4
+ string: () => ZodString;
5
+ union: <T extends readonly [ZodTypeAny, ZodTypeAny, ...ZodTypeAny[]]>(schemas: T) => ZodTypeAny;
6
+ };
7
+
8
+ export function createTutorialIconSchema(z: ZodLike, image: () => ZodTypeAny) {
9
+ return z.union([image(), z.string()]);
10
+ }
@@ -212,9 +212,9 @@ const coverUrl = tutorial.data.cover?.src;
212
212
  }
213
213
  .hero-with-cover {
214
214
  display: grid;
215
- grid-template-columns: minmax(0, 1.1fr) minmax(18rem, 0.9fr);
216
- gap: clamp(1.5rem, 4vw, 3rem);
217
- align-items: stretch;
215
+ grid-template-columns: 1fr;
216
+ gap: clamp(1.5rem, 4vw, 2rem);
217
+ align-items: start;
218
218
  }
219
219
  .hero-copy {
220
220
  min-width: 0;
@@ -243,7 +243,8 @@ const coverUrl = tutorial.data.cover?.src;
243
243
  line-height: 1;
244
244
  }
245
245
  .hero-media {
246
- min-height: 100%;
246
+ order: -1;
247
+ aspect-ratio: 16 / 9;
247
248
  border: var(--border-default, 2px) solid var(--color-border);
248
249
  background: var(--color-surface);
249
250
  overflow: hidden;
@@ -252,7 +253,6 @@ const coverUrl = tutorial.data.cover?.src;
252
253
  .hero-cover {
253
254
  width: 100%;
254
255
  height: 100%;
255
- min-height: 18rem;
256
256
  object-fit: cover;
257
257
  display: block;
258
258
  filter: saturate(0.95) contrast(1.06);
@@ -447,9 +447,6 @@ const coverUrl = tutorial.data.cover?.src;
447
447
  }
448
448
  @media (max-width: 640px) {
449
449
  .hero { padding: 1.5rem 1.25rem 1.75rem; }
450
- .hero-with-cover { grid-template-columns: 1fr; }
451
- .hero-media { order: -1; }
452
- .hero-cover { min-height: 12rem; }
453
450
  .step-list a { grid-template-columns: auto 1fr auto; padding: 0.75rem; }
454
451
  .step-chevron { display: none; }
455
452
  }
@@ -53,12 +53,6 @@
53
53
  fill: currentColor;
54
54
  }
55
55
 
56
- .track-selector-icon-slot {
57
- width: 0.95rem;
58
- height: 0.95rem;
59
- flex-shrink: 0;
60
- }
61
-
62
56
  .track-selector-fallback {
63
57
  display: inline-grid;
64
58
  place-items: center;