handzon-core 0.13.2 → 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 +1 -1
- package/src/collections.ts +2 -1
- package/src/components/Sidebar.astro +24 -12
- package/src/components/TrackSelector.tsx +4 -56
- package/src/components/auth/UserMenu.astro +38 -1
- package/src/components/auth/UserMenu.tsx +7 -0
- package/src/lib/track-icons.ts +49 -0
- package/src/lib/tutorialIcon.ts +10 -0
- package/src/pages/TutorialLanding.astro +5 -8
- package/styles/components/track-selector.css +1 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "handzon-core",
|
|
3
|
-
"version": "0.13.
|
|
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"
|
package/src/collections.ts
CHANGED
|
@@ -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:
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
import {
|
|
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";
|
|
1
|
+
import { useEffect, useMemo } from "react";
|
|
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(
|
|
@@ -107,17 +60,12 @@ export default function TrackSelector({ tracks, defaultTrack }: Props) {
|
|
|
107
60
|
onClick={() => setPref("track", track.id)}
|
|
108
61
|
>
|
|
109
62
|
{icon ? (
|
|
110
|
-
<svg
|
|
111
|
-
className="track-selector-icon"
|
|
112
|
-
viewBox="0 0 24 24"
|
|
113
|
-
aria-hidden="true"
|
|
114
|
-
style={{ "--track-icon-color": `#${icon.hex}` } as CSSProperties}
|
|
115
|
-
>
|
|
63
|
+
<svg className="track-selector-icon" viewBox="0 0 24 24" aria-hidden="true">
|
|
116
64
|
<path d={icon.path} />
|
|
117
65
|
</svg>
|
|
118
66
|
) : (
|
|
119
67
|
<span className="track-selector-fallback" aria-hidden="true">
|
|
120
|
-
{
|
|
68
|
+
{fallbackTextForTrack(track)}
|
|
121
69
|
</span>
|
|
122
70
|
)}
|
|
123
71
|
<span>{track.label}</span>
|
|
@@ -7,10 +7,37 @@
|
|
|
7
7
|
* prerendered route happens to include BaseLayout.
|
|
8
8
|
*/
|
|
9
9
|
import UserMenuIsland from "./UserMenu.tsx";
|
|
10
|
+
|
|
11
|
+
const GITHUB_ICON_PATH =
|
|
12
|
+
"M12 .5C5.65.5.5 5.65 5.65.5 12c0 5.08 3.29 9.39 7.86 10.91.58.11.79-.25.79-.55v-2.02c-3.2.7-3.88-1.36-3.88-1.36-.52-1.33-1.28-1.68-1.28-1.68-1.04-.71.08-.7.08-.7 1.15.08 1.76 1.18 1.76 1.18 1.03 1.76 2.7 1.25 3.36.96.1-.74.4-1.25.72-1.54-2.55-.29-5.24-1.27-5.24-5.66 0-1.25.45-2.27 1.18-3.07-.12-.29-.51-1.45.11-3.03 0 0 .96-.31 3.15 1.17a10.94 10.94 0 0 1 5.76 0c2.19-1.48 3.15-1.17 3.15-1.17.62 1.58.23 2.74.11 3.03.74.8 1.18 1.82 1.18 3.07 0 4.4-2.69 5.37-5.25 5.65.41.35.78 1.04.78 2.11v3.13c0 .3.21.66.79.55C20.71 21.39 24 17.08 24 12 24 5.65 18.85.5 12 .5z";
|
|
10
13
|
---
|
|
11
|
-
<
|
|
14
|
+
<div class="user-menu-shell">
|
|
15
|
+
<div class="user-menu um-fallback" data-user-menu-fallback aria-hidden="true">
|
|
16
|
+
<button type="button" class="um-btn" disabled tabindex="-1">
|
|
17
|
+
<svg
|
|
18
|
+
class="um-gh"
|
|
19
|
+
viewBox="0 0 24 24"
|
|
20
|
+
width="14"
|
|
21
|
+
height="14"
|
|
22
|
+
fill="currentColor"
|
|
23
|
+
aria-hidden="true"
|
|
24
|
+
>
|
|
25
|
+
<path d={GITHUB_ICON_PATH} />
|
|
26
|
+
</svg>
|
|
27
|
+
<span>Sign in with GitHub</span>
|
|
28
|
+
</button>
|
|
29
|
+
</div>
|
|
30
|
+
<UserMenuIsland client:only="react" />
|
|
31
|
+
</div>
|
|
12
32
|
|
|
13
33
|
<style is:global>
|
|
34
|
+
.user-menu-shell {
|
|
35
|
+
display: grid;
|
|
36
|
+
}
|
|
37
|
+
.user-menu-shell > .user-menu,
|
|
38
|
+
.user-menu-shell > astro-island {
|
|
39
|
+
grid-area: 1 / 1;
|
|
40
|
+
}
|
|
14
41
|
.user-menu {
|
|
15
42
|
display: inline-flex;
|
|
16
43
|
align-items: center;
|
|
@@ -43,6 +70,12 @@ import UserMenuIsland from "./UserMenu.tsx";
|
|
|
43
70
|
white-space: nowrap;
|
|
44
71
|
}
|
|
45
72
|
.user-menu form { display: inline-flex; }
|
|
73
|
+
.um-fallback {
|
|
74
|
+
pointer-events: none;
|
|
75
|
+
}
|
|
76
|
+
.um-fallback[hidden] {
|
|
77
|
+
display: none;
|
|
78
|
+
}
|
|
46
79
|
.um-btn {
|
|
47
80
|
display: inline-flex;
|
|
48
81
|
align-items: center;
|
|
@@ -59,6 +92,10 @@ import UserMenuIsland from "./UserMenu.tsx";
|
|
|
59
92
|
border-color: var(--color-accent);
|
|
60
93
|
color: var(--color-accent);
|
|
61
94
|
}
|
|
95
|
+
.um-btn:disabled {
|
|
96
|
+
opacity: 1;
|
|
97
|
+
cursor: default;
|
|
98
|
+
}
|
|
62
99
|
.um-btn-icon {
|
|
63
100
|
padding: 0.3rem 0.45rem;
|
|
64
101
|
}
|
|
@@ -68,6 +68,13 @@ export default function UserMenu() {
|
|
|
68
68
|
};
|
|
69
69
|
}, []);
|
|
70
70
|
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (session === undefined) return;
|
|
73
|
+
document.querySelectorAll<HTMLElement>("[data-user-menu-fallback]").forEach((el) => {
|
|
74
|
+
el.hidden = true;
|
|
75
|
+
});
|
|
76
|
+
}, [session]);
|
|
77
|
+
|
|
71
78
|
// Loading or auth not wired → render nothing.
|
|
72
79
|
if (session === undefined || !csrfToken) return null;
|
|
73
80
|
|
|
@@ -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:
|
|
216
|
-
gap: clamp(1.5rem, 4vw,
|
|
217
|
-
align-items:
|
|
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
|
-
|
|
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
|
}
|
|
@@ -50,13 +50,7 @@
|
|
|
50
50
|
width: 0.95rem;
|
|
51
51
|
height: 0.95rem;
|
|
52
52
|
flex-shrink: 0;
|
|
53
|
-
fill:
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.track-selector-icon-slot {
|
|
57
|
-
width: 0.95rem;
|
|
58
|
-
height: 0.95rem;
|
|
59
|
-
flex-shrink: 0;
|
|
53
|
+
fill: currentColor;
|
|
60
54
|
}
|
|
61
55
|
|
|
62
56
|
.track-selector-fallback {
|