create-kitcms 0.0.0-stage → 0.1.1

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.
Files changed (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -2
  3. package/bin/create.js +5 -0
  4. package/dist/args.d.ts +15 -0
  5. package/dist/args.js +72 -0
  6. package/dist/index.d.ts +30 -0
  7. package/dist/index.js +161 -0
  8. package/dist/scaffold.d.ts +31 -0
  9. package/dist/scaffold.js +109 -0
  10. package/dist/wrangler.d.ts +2 -0
  11. package/dist/wrangler.js +7 -0
  12. package/package.json +34 -3
  13. package/templates/blank/.dev.vars.example +1 -0
  14. package/templates/blank/README.md +39 -0
  15. package/templates/blank/_gitignore +7 -0
  16. package/templates/blank/package.json +37 -0
  17. package/templates/blank/pnpm-workspace.yaml +3 -0
  18. package/templates/blank/src/app.d.ts +22 -0
  19. package/templates/blank/src/app.html +11 -0
  20. package/templates/blank/src/hooks.server.ts +4 -0
  21. package/templates/blank/src/kitcms.admin.ts +14 -0
  22. package/templates/blank/src/kitcms.config.ts +32 -0
  23. package/templates/blank/src/kitcms.rpc.ts +6 -0
  24. package/templates/blank/src/lib/index.ts +1 -0
  25. package/templates/blank/src/routes/(kitcms)/admin/[...path]/+page.server.ts +2 -0
  26. package/templates/blank/src/routes/(kitcms)/admin/[...path]/+page.svelte +9 -0
  27. package/templates/blank/src/routes/(kitcms)/api/[...path]/+server.ts +2 -0
  28. package/templates/blank/src/routes/+page.server.ts +7 -0
  29. package/templates/blank/src/routes/+page.svelte +19 -0
  30. package/templates/blank/tsconfig.json +11 -0
  31. package/templates/blank/vite.config.ts +8 -0
  32. package/templates/blank/wrangler.jsonc +28 -0
  33. package/templates/website/.dev.vars.example +1 -0
  34. package/templates/website/README.md +105 -0
  35. package/templates/website/_gitignore +7 -0
  36. package/templates/website/package.json +42 -0
  37. package/templates/website/pnpm-workspace.yaml +3 -0
  38. package/templates/website/src/app.css +23 -0
  39. package/templates/website/src/app.d.ts +22 -0
  40. package/templates/website/src/app.html +11 -0
  41. package/templates/website/src/hooks.server.ts +4 -0
  42. package/templates/website/src/kitcms.admin.ts +19 -0
  43. package/templates/website/src/kitcms.config.ts +269 -0
  44. package/templates/website/src/kitcms.rpc.ts +6 -0
  45. package/templates/website/src/kitcms.seed.ts +232 -0
  46. package/templates/website/src/lib/Img.svelte +62 -0
  47. package/templates/website/src/lib/Link.svelte +10 -0
  48. package/templates/website/src/lib/PageView.svelte +30 -0
  49. package/templates/website/src/lib/PostList.svelte +169 -0
  50. package/templates/website/src/lib/RichText.svelte +13 -0
  51. package/templates/website/src/lib/Seo.svelte +31 -0
  52. package/templates/website/src/lib/blocks/AdminPreview.svelte +59 -0
  53. package/templates/website/src/lib/blocks/Cta.svelte +86 -0
  54. package/templates/website/src/lib/blocks/Features.svelte +147 -0
  55. package/templates/website/src/lib/blocks/Gallery.svelte +122 -0
  56. package/templates/website/src/lib/blocks/Hero.svelte +151 -0
  57. package/templates/website/src/lib/blocks/LatestPosts.svelte +36 -0
  58. package/templates/website/src/lib/blocks/RenderBlocks.svelte +38 -0
  59. package/templates/website/src/lib/blocks/ResolveMedia.svelte +27 -0
  60. package/templates/website/src/lib/blocks/RichTextBlock.svelte +47 -0
  61. package/templates/website/src/lib/blocks/TeamGrid.svelte +159 -0
  62. package/templates/website/src/lib/blocks/types.ts +47 -0
  63. package/templates/website/src/lib/content.ts +31 -0
  64. package/templates/website/src/lib/designs.ts +79 -0
  65. package/templates/website/src/lib/format.ts +3 -0
  66. package/templates/website/src/lib/icons.ts +13 -0
  67. package/templates/website/src/lib/image.ts +29 -0
  68. package/templates/website/src/lib/index.ts +1 -0
  69. package/templates/website/src/lib/media.ts +32 -0
  70. package/templates/website/src/lib/shell/Footer.svelte +146 -0
  71. package/templates/website/src/lib/shell/Header.svelte +121 -0
  72. package/templates/website/src/lib/shell/MobileMenu.svelte +142 -0
  73. package/templates/website/src/lib/shell/shell.ts +52 -0
  74. package/templates/website/src/lib/site.css +329 -0
  75. package/templates/website/src/routes/(kitcms)/admin/[...path]/+page.server.ts +2 -0
  76. package/templates/website/src/routes/(kitcms)/admin/[...path]/+page.svelte +9 -0
  77. package/templates/website/src/routes/(kitcms)/api/[...path]/+server.ts +2 -0
  78. package/templates/website/src/routes/(site)/+error.svelte +23 -0
  79. package/templates/website/src/routes/(site)/+layout.server.ts +12 -0
  80. package/templates/website/src/routes/(site)/+layout.svelte +63 -0
  81. package/templates/website/src/routes/(site)/+page.server.ts +7 -0
  82. package/templates/website/src/routes/(site)/+page.svelte +33 -0
  83. package/templates/website/src/routes/(site)/[slug]/+page.server.ts +11 -0
  84. package/templates/website/src/routes/(site)/[slug]/+page.svelte +9 -0
  85. package/templates/website/src/routes/(site)/blog/+page.server.ts +20 -0
  86. package/templates/website/src/routes/(site)/blog/+page.svelte +66 -0
  87. package/templates/website/src/routes/(site)/blog/[slug]/+page.server.ts +11 -0
  88. package/templates/website/src/routes/(site)/blog/[slug]/+page.svelte +231 -0
  89. package/templates/website/src/routes/(site)/legal/[slug]/+page.server.ts +8 -0
  90. package/templates/website/src/routes/(site)/legal/[slug]/+page.svelte +23 -0
  91. package/templates/website/tsconfig.json +11 -0
  92. package/templates/website/vite.config.ts +8 -0
  93. package/templates/website/wrangler.jsonc +28 -0
@@ -0,0 +1,151 @@
1
+ <script lang="ts">
2
+ import '../site.css';
3
+ import type { DesignId } from '../designs';
4
+ import Img from '../Img.svelte';
5
+ import Link from '../Link.svelte';
6
+ import { asMedia } from '../media';
7
+ import type { BlockOf } from './types';
8
+
9
+ // A "Editorial": text left, a portrait picture right. B "Immersive": a full-bleed photograph
10
+ // with the text on it (a field of the accent colour without a picture). C "Structured": a
11
+ // tinted panel with the text beside a landscape picture.
12
+ let { block, design = 'a' }: { block: BlockOf<'hero'>; design?: DesignId } = $props();
13
+ const image = $derived(asMedia(block.image));
14
+ </script>
15
+
16
+ <section class="hero" data-design={design} class:photo={design === 'b' && image}>
17
+ {#if design === 'b'}
18
+ {#if image}
19
+ <div class="bg"><Img media={image} fill widths={[800, 1400, 2200]} sizes="100vw" eager /></div>
20
+ {/if}
21
+ <div class="container inner">
22
+ <h1>{block.heading ?? ''}</h1>
23
+ {#if block.subheading}<p class="lead sub">{block.subheading}</p>{/if}
24
+ {#if block.ctaLabel && block.ctaHref}
25
+ <Link href={block.ctaHref} class={['btn', image ? 'on-photo' : 'inverse']}>{block.ctaLabel}</Link>
26
+ {/if}
27
+ </div>
28
+ {:else}
29
+ <div class="container grid" class:solo={!image}>
30
+ <div class="copy">
31
+ <h1>{block.heading ?? ''}</h1>
32
+ {#if block.subheading}<p class="lead sub">{block.subheading}</p>{/if}
33
+ {#if block.ctaLabel && block.ctaHref}
34
+ <Link href={block.ctaHref} class="btn">{block.ctaLabel}</Link>
35
+ {/if}
36
+ </div>
37
+ {#if image}
38
+ <div class="pic">
39
+ <Img
40
+ media={image}
41
+ ratio={design === 'a' ? 4 / 5 : 4 / 3}
42
+ widths={[480, 800, 1200]}
43
+ sizes="(min-width: 56rem) 40vw, 100vw"
44
+ eager
45
+ />
46
+ </div>
47
+ {/if}
48
+ </div>
49
+ {/if}
50
+ </section>
51
+
52
+ <style>
53
+ .hero {
54
+ padding-block: var(--s-6) var(--s-6);
55
+ }
56
+ .sub {
57
+ max-width: 36rem;
58
+ margin-bottom: var(--s-4);
59
+ color: var(--muted);
60
+ }
61
+ .grid {
62
+ display: grid;
63
+ gap: var(--s-5);
64
+ }
65
+ .pic :global(img) {
66
+ border-radius: var(--radius);
67
+ }
68
+
69
+ /* A: editorial */
70
+ .hero[data-design='a'] {
71
+ --font-display: var(--font-serif);
72
+ padding-block: var(--s-6) var(--s-7);
73
+ }
74
+ .hero[data-design='a'] h1 {
75
+ font-weight: 600;
76
+ font-size: clamp(2.5rem, 1.4rem + 4.4vw, 5rem);
77
+ max-width: 14ch;
78
+ }
79
+
80
+ /* B: immersive */
81
+ .hero[data-design='b'] {
82
+ display: flex;
83
+ align-items: flex-end;
84
+ position: relative;
85
+ min-height: clamp(22rem, 62svh, 38rem);
86
+ padding-block: var(--s-7) var(--s-6);
87
+ background: var(--accent);
88
+ color: var(--accent-ink);
89
+ --focus: var(--accent-ink);
90
+ overflow: hidden;
91
+ }
92
+ .hero[data-design='b'].photo {
93
+ min-height: clamp(30rem, 86svh, 54rem);
94
+ color: #ffffff;
95
+ --focus: #ffffff;
96
+ background: #2a2c2e;
97
+ }
98
+ .bg {
99
+ position: absolute;
100
+ inset: 0;
101
+ }
102
+ .hero.photo::after {
103
+ content: '';
104
+ position: absolute;
105
+ inset: 0;
106
+ background: linear-gradient(to top, rgb(0 0 0 / 0.78), rgb(0 0 0 / 0.1) 70%);
107
+ }
108
+ .hero[data-design='b'] .inner {
109
+ position: relative;
110
+ z-index: 1;
111
+ }
112
+ .hero[data-design='b'] h1 {
113
+ max-width: 16ch;
114
+ }
115
+ .hero[data-design='b'] .sub {
116
+ color: inherit;
117
+ opacity: 0.92;
118
+ }
119
+
120
+ /* C: structured */
121
+ .hero[data-design='c'] {
122
+ background: var(--surface);
123
+ padding-block: var(--s-6);
124
+ }
125
+ .hero[data-design='c'] h1 {
126
+ font-size: clamp(2.25rem, 1.3rem + 3.6vw, 4rem);
127
+ max-width: 16ch;
128
+ }
129
+ .solo .copy {
130
+ max-width: 46rem;
131
+ }
132
+
133
+ @media (min-width: 56rem) {
134
+ .hero[data-design='a'] .grid:not(.solo) {
135
+ grid-template-columns: 7fr 5fr;
136
+ align-items: end;
137
+ gap: var(--s-7);
138
+ }
139
+ .hero[data-design='a'] .pic {
140
+ margin-bottom: calc(var(--s-6) * -1);
141
+ }
142
+ .hero[data-design='c'] .grid:not(.solo) {
143
+ grid-template-columns: 1fr 1fr;
144
+ align-items: center;
145
+ gap: var(--s-6);
146
+ }
147
+ .hero[data-design='c'] {
148
+ padding-block: var(--s-7);
149
+ }
150
+ }
151
+ </style>
@@ -0,0 +1,36 @@
1
+ <script lang="ts">
2
+ import '../site.css';
3
+ import type { DesignId } from '../designs';
4
+ import PostList from '../PostList.svelte';
5
+ import type { BlockExtras, BlockOf } from './types';
6
+
7
+ // `posts` is loaded by the page route (see `../content.ts`). The admin preview has no data
8
+ // source, so it shows a placeholder. The list follows the page's design (A rows, B cards, C index).
9
+ let {
10
+ block,
11
+ posts,
12
+ design = 'a',
13
+ }: { block: BlockOf<'latestPosts'>; posts?: BlockExtras['posts']; design?: DesignId } = $props();
14
+ const shown = $derived(posts?.slice(0, block.count ?? 3));
15
+ </script>
16
+
17
+ <section class="section" data-design={design}>
18
+ <div class="container">
19
+ {#if block.title}<h2>{block.title}</h2>{/if}
20
+ {#if shown}
21
+ <PostList posts={shown} {design} />
22
+ {:else}
23
+ <p class="placeholder">Latest posts: the newest published posts appear here on the site.</p>
24
+ {/if}
25
+ </div>
26
+ </section>
27
+
28
+ <style>
29
+ .section[data-design='a'] h2 {
30
+ --font-display: var(--font-serif);
31
+ font-weight: 600;
32
+ }
33
+ h2 {
34
+ margin-bottom: var(--s-5);
35
+ }
36
+ </style>
@@ -0,0 +1,38 @@
1
+ <script lang="ts">
2
+ // Maps `blockType` to its component. The same components render the admin live preview
3
+ // (see `AdminPreview.svelte`), so a block looks the same in both places. `design` is the
4
+ // page's resolved design (`a`, `b` or `c`): every block renders all three.
5
+ import type { DesignId } from '../designs';
6
+ import Cta from './Cta.svelte';
7
+ import Features from './Features.svelte';
8
+ import Gallery from './Gallery.svelte';
9
+ import Hero from './Hero.svelte';
10
+ import LatestPosts from './LatestPosts.svelte';
11
+ import RichTextBlock from './RichTextBlock.svelte';
12
+ import TeamGrid from './TeamGrid.svelte';
13
+ import type { BlockExtras, PageBlock } from './types';
14
+
15
+ let {
16
+ blocks,
17
+ extras = {},
18
+ design = 'a',
19
+ }: { blocks: PageBlock[]; extras?: BlockExtras; design?: DesignId } = $props();
20
+ </script>
21
+
22
+ {#each blocks as block (block.id)}
23
+ {#if block.blockType === 'hero'}
24
+ <Hero {block} {design} />
25
+ {:else if block.blockType === 'richText'}
26
+ <RichTextBlock {block} {design} />
27
+ {:else if block.blockType === 'features'}
28
+ <Features {block} {design} />
29
+ {:else if block.blockType === 'gallery'}
30
+ <Gallery {block} {design} />
31
+ {:else if block.blockType === 'cta'}
32
+ <Cta {block} {design} />
33
+ {:else if block.blockType === 'teamGrid'}
34
+ <TeamGrid {block} team={extras.team} {design} />
35
+ {:else if block.blockType === 'latestPosts'}
36
+ <LatestPosts {block} posts={extras.posts} {design} />
37
+ {/if}
38
+ {/each}
@@ -0,0 +1,27 @@
1
+ <script lang="ts">
2
+ // Admin preview only: resolves one upload id to a media doc (via `useRelation`) and reports it.
3
+ // Renders nothing. The public site never imports this file, so no admin code reaches it.
4
+ import { useRelation } from '@kitcms/ui';
5
+ import type { Media } from '../media';
6
+
7
+ let { id, onresolve }: { id: string; onresolve: (id: string, media: Media | null) => void } =
8
+ $props();
9
+
10
+ const rel = useRelation('media', () => id);
11
+ $effect(() => {
12
+ const doc = rel.current;
13
+ onresolve(
14
+ id,
15
+ doc?.url
16
+ ? {
17
+ id: doc.id,
18
+ url: doc.url,
19
+ alt: doc.title,
20
+ width: doc.width,
21
+ height: doc.height,
22
+ mimeType: doc.mimeType,
23
+ }
24
+ : null,
25
+ );
26
+ });
27
+ </script>
@@ -0,0 +1,47 @@
1
+ <script lang="ts">
2
+ import '../site.css';
3
+ import type { DesignId } from '../designs';
4
+ import RichText from '../RichText.svelte';
5
+ import type { BlockOf } from './types';
6
+
7
+ // A "Editorial": a serif reading column on the left. B "Immersive": the column centred.
8
+ // C "Structured": the text in a tinted panel.
9
+ let { block, design = 'a' }: { block: BlockOf<'richText'>; design?: DesignId } = $props();
10
+ </script>
11
+
12
+ <section class="section" data-design={design}>
13
+ <div class="container"><div class="body"><RichText doc={block.body} /></div></div>
14
+ </section>
15
+
16
+ <style>
17
+ .section {
18
+ padding-block: var(--s-6);
19
+ }
20
+ .section[data-design='a'] {
21
+ --font-display: var(--font-serif);
22
+ }
23
+ .section[data-design='a'] .body :global(.prose) {
24
+ font-family: var(--font-serif);
25
+ font-size: 1.1875rem;
26
+ line-height: 1.7;
27
+ }
28
+ .section[data-design='a'] .body :global(.prose :is(h1, h2, h3)) {
29
+ font-weight: 600;
30
+ }
31
+ .section[data-design='b'] .body :global(.prose) {
32
+ margin-inline: auto;
33
+ }
34
+ .section[data-design='b'] .body :global(.prose > p:first-child) {
35
+ font-size: var(--step-lead);
36
+ }
37
+ .section[data-design='c'] .body {
38
+ padding: var(--s-4);
39
+ background: var(--surface);
40
+ border-radius: var(--radius);
41
+ }
42
+ @media (min-width: 48rem) {
43
+ .section[data-design='c'] .body {
44
+ padding: var(--s-6);
45
+ }
46
+ }
47
+ </style>
@@ -0,0 +1,159 @@
1
+ <script lang="ts">
2
+ import '../site.css';
3
+ import type { DesignId } from '../designs';
4
+ import Img from '../Img.svelte';
5
+ import { asMedia } from '../media';
6
+ import type { BlockExtras, BlockOf } from './types';
7
+
8
+ // `team` is loaded by the page route (see `../content.ts`). The admin preview has no data
9
+ // source, so it shows a placeholder.
10
+ // A "Editorial": rows with a small round portrait. B "Immersive": large portrait cards.
11
+ // C "Structured": square tiles on a tinted ground.
12
+ let {
13
+ block,
14
+ team,
15
+ design = 'a',
16
+ }: { block: BlockOf<'teamGrid'>; team?: BlockExtras['team']; design?: DesignId } = $props();
17
+ </script>
18
+
19
+ <section class="section" data-design={design}>
20
+ <div class="container">
21
+ {#if block.title}<h2>{block.title}</h2>{/if}
22
+ {#if team}
23
+ <ul class="grid">
24
+ {#each team as member (member.id)}
25
+ {@const photo = asMedia(member.photo)}
26
+ <li>
27
+ <div class="pic">
28
+ {#if photo}
29
+ <Img
30
+ media={photo}
31
+ ratio={design === 'b' ? 4 / 5 : 1}
32
+ widths={[200, 400, 700]}
33
+ sizes={design === 'a' ? '6rem' : '(min-width: 48rem) 30vw, 100vw'}
34
+ />
35
+ {:else}
36
+ <div class="avatar" aria-hidden="true">{member.name.slice(0, 1)}</div>
37
+ {/if}
38
+ </div>
39
+ <div class="info">
40
+ <h3>{member.name}</h3>
41
+ {#if member.role}<p class="role">{member.role}</p>{/if}
42
+ {#if member.bio}<p class="muted bio">{member.bio}</p>{/if}
43
+ </div>
44
+ </li>
45
+ {/each}
46
+ </ul>
47
+ {:else}
48
+ <p class="placeholder">Team grid: the members of the Team collection appear here on the site.</p>
49
+ {/if}
50
+ </div>
51
+ </section>
52
+
53
+ <style>
54
+ .section[data-design='a'] {
55
+ --font-display: var(--font-serif);
56
+ }
57
+ .section[data-design='a'] h2 {
58
+ font-weight: 600;
59
+ }
60
+ h2 {
61
+ margin-bottom: var(--s-5);
62
+ }
63
+ .grid {
64
+ list-style: none;
65
+ margin: 0;
66
+ padding: 0;
67
+ display: grid;
68
+ gap: var(--s-4);
69
+ }
70
+ li :global(img),
71
+ .avatar {
72
+ width: 100%;
73
+ aspect-ratio: 1;
74
+ object-fit: cover;
75
+ border-radius: var(--radius);
76
+ }
77
+ .avatar {
78
+ display: grid;
79
+ place-items: center;
80
+ font: 700 3rem/1 var(--font-display);
81
+ background: var(--surface-2);
82
+ color: var(--accent);
83
+ }
84
+ h3 {
85
+ margin: 0;
86
+ font-size: 1.2rem;
87
+ }
88
+ p {
89
+ margin: 0.2rem 0 0;
90
+ }
91
+ .role {
92
+ color: var(--accent);
93
+ font-weight: 650;
94
+ font-size: var(--step-small);
95
+ }
96
+ .bio {
97
+ font-size: var(--step-small);
98
+ }
99
+
100
+ /* A: rows */
101
+ .section[data-design='a'] li {
102
+ display: flex;
103
+ gap: var(--s-3);
104
+ align-items: flex-start;
105
+ }
106
+ .section[data-design='a'] .pic {
107
+ flex: none;
108
+ width: 5.5rem;
109
+ }
110
+ .section[data-design='a'] li :global(img),
111
+ .section[data-design='a'] .avatar {
112
+ border-radius: 50%;
113
+ }
114
+
115
+ /* B: portrait cards */
116
+ .section[data-design='b'] .grid {
117
+ gap: var(--s-5) var(--s-3);
118
+ grid-template-columns: repeat(2, 1fr);
119
+ }
120
+ .section[data-design='b'] .avatar {
121
+ aspect-ratio: 4 / 5;
122
+ }
123
+ .section[data-design='b'] .info {
124
+ margin-top: var(--s-2);
125
+ }
126
+
127
+ /* C: tiles */
128
+ .section[data-design='c'] .grid {
129
+ grid-template-columns: repeat(2, 1fr);
130
+ gap: 0.5rem;
131
+ }
132
+ .section[data-design='c'] li {
133
+ display: flex;
134
+ flex-direction: column;
135
+ gap: var(--s-3);
136
+ padding: var(--s-2);
137
+ background: var(--surface);
138
+ border-radius: 0.25rem;
139
+ }
140
+ .section[data-design='c'] li :global(img),
141
+ .section[data-design='c'] .avatar {
142
+ border-radius: 0.125rem;
143
+ }
144
+
145
+ @media (min-width: 48rem) {
146
+ .section[data-design='a'] .grid {
147
+ grid-template-columns: repeat(2, 1fr);
148
+ gap: var(--s-5) var(--s-6);
149
+ }
150
+ .section[data-design='b'] .grid {
151
+ grid-template-columns: repeat(3, 1fr);
152
+ gap: var(--s-5) var(--s-4);
153
+ }
154
+ .section[data-design='c'] .grid {
155
+ grid-template-columns: repeat(3, 1fr);
156
+ gap: 0.5rem;
157
+ }
158
+ }
159
+ </style>
@@ -0,0 +1,47 @@
1
+ import type { DocOf, Rel } from '@kitcms/core';
2
+ import type config from '../../kitcms.config';
3
+
4
+ /**
5
+ * Relationship/upload values are ids (`Rel`) or, after a `depth: 1` read, documents. The block
6
+ * components accept both, so they are typed as `unknown` and narrowed with `../media.ts`.
7
+ */
8
+ type Loose<T> =
9
+ T extends Rel<string>
10
+ ? unknown
11
+ : T extends readonly (infer E)[]
12
+ ? Loose<E>[]
13
+ : T extends object
14
+ ? { [K in keyof T]: Loose<T[K]> }
15
+ : T;
16
+
17
+ /** One block of a page's `sections`, by `blockType`. */
18
+ export type PageBlock = Loose<DocOf<typeof config, 'pages'>['sections'][number]>;
19
+
20
+ /**
21
+ * The block's values. Partial because the same components render the admin live preview, where
22
+ * values are incomplete while editing (and upload fields hold ids, see `../media.ts`).
23
+ */
24
+ export type BlockOf<S extends PageBlock['blockType']> = Partial<
25
+ Extract<PageBlock, { blockType: S }>
26
+ >;
27
+
28
+ /** Collection data some blocks render (loaded by `../content.ts`). Absent in the admin preview. */
29
+ export interface TeamMember {
30
+ id: string;
31
+ name: string;
32
+ role?: string | null;
33
+ bio?: string | null;
34
+ photo?: unknown;
35
+ }
36
+ export interface PostSummary {
37
+ id: string;
38
+ title: string;
39
+ slug: string;
40
+ excerpt?: string | null;
41
+ publishedAt?: string | null;
42
+ cover?: unknown;
43
+ }
44
+ export interface BlockExtras {
45
+ team?: TeamMember[];
46
+ posts?: PostSummary[];
47
+ }
@@ -0,0 +1,31 @@
1
+ // Content loading for the public routes (server only). Everything goes through `locals.cms`, acting
2
+ // as the visitor: anonymous requests only ever see published documents.
3
+ import type { BlockExtras, PageBlock } from './blocks/types';
4
+
5
+ type Cms = App.Locals['cms'];
6
+
7
+ /** The published page with this slug (uploads populated), plus the data its blocks render. */
8
+ export async function loadPage(cms: Cms, slug: string) {
9
+ const page = await cms.findOne('pages', { where: { slug: { equals: slug } }, depth: 1 });
10
+ if (!page) return null;
11
+
12
+ const blocks = (page.sections ?? []) as unknown as PageBlock[];
13
+ const postCount = Math.max(
14
+ 0,
15
+ ...blocks.flatMap((b) => (b.blockType === 'latestPosts' ? [b.count ?? 3] : [])),
16
+ );
17
+ const [team, posts] = await Promise.all([
18
+ blocks.some((b) => b.blockType === 'teamGrid')
19
+ ? cms.find('team', { depth: 1, limit: 100, pagination: false })
20
+ : null,
21
+ postCount > 0
22
+ ? cms.find('posts', { depth: 1, limit: postCount, sort: '-publishedAt', pagination: false })
23
+ : null,
24
+ ]);
25
+ const extras: BlockExtras = {
26
+ team: team?.docs,
27
+ // `slug` is filled from the title on save; the check only narrows its type.
28
+ posts: posts?.docs.flatMap((d) => (d.slug ? [{ ...d, slug: d.slug }] : [])),
29
+ };
30
+ return { page, blocks, extras };
31
+ }
@@ -0,0 +1,79 @@
1
+ // The design registry: the one place that lists page types and their designs.
2
+ // - `kitcms.config.ts` builds the `site` Design tab and the per-page `design` selects from it.
3
+ // - The site picks a design with `resolveDesign(type, site.design, page.design)`.
4
+ // To add a design to a page type, add `d: 'Name'` to its `designs` below and handle `'d'` in the
5
+ // components that switch on it. Client-safe: no config imports, no server code.
6
+
7
+ export interface PageTypeDef {
8
+ label: string;
9
+ /** `id -> human name`. The first entry is the default. */
10
+ designs: Record<string, string>;
11
+ }
12
+
13
+ export const PAGE_TYPES = {
14
+ header: { label: 'Header', designs: { a: 'Bar', b: 'Centred', c: 'Band' } },
15
+ footer: { label: 'Footer', designs: { a: 'Simple', b: 'Columns', c: 'Statement' } },
16
+ home: { label: 'Home', designs: { a: 'Editorial', b: 'Immersive', c: 'Structured' } },
17
+ page: { label: 'Page', designs: { a: 'Editorial', b: 'Immersive', c: 'Structured' } },
18
+ blog: { label: 'Blog list', designs: { a: 'Journal', b: 'Cards', c: 'Index' } },
19
+ post: { label: 'Blog post', designs: { a: 'Essay', b: 'Feature', c: 'Article' } },
20
+ } as const satisfies Record<string, PageTypeDef>;
21
+
22
+ export type PageType = keyof typeof PAGE_TYPES;
23
+ export type DesignId = 'a' | 'b' | 'c';
24
+
25
+ const defs = (type: PageType) => PAGE_TYPES[type].designs as Record<string, string>;
26
+
27
+ /** `{ label, value }` options for a select field. Select values can't be empty, so an unset page override means "use the site setting". */
28
+ export function designOptions(type: PageType) {
29
+ return Object.entries(defs(type)).map(([value, name]) => ({
30
+ label: `${value.toUpperCase()} · ${name}`,
31
+ value,
32
+ }));
33
+ }
34
+
35
+ /**
36
+ * The design to render: the page's own override, else the `site` Design tab, else the type's first
37
+ * design. Unknown ids (a design removed from the registry) fall back too.
38
+ */
39
+ export function resolveDesign(
40
+ type: PageType,
41
+ siteDesign?: Partial<Record<string, string | null>> | null,
42
+ override?: string | null,
43
+ ): DesignId {
44
+ const known = defs(type);
45
+ for (const id of [override, siteDesign?.[type]]) if (id && id in known) return id as DesignId;
46
+ return Object.keys(known)[0] as DesignId;
47
+ }
48
+
49
+ // ---- Theme overrides ------------------------------------------------------------------------
50
+
51
+ const HEX = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
52
+ export const isHex = (v: unknown): v is string => typeof v === 'string' && HEX.test(v);
53
+
54
+ function luminance(hex: string): number {
55
+ const h = hex.length === 4 ? [...hex.slice(1)].map((c) => c + c).join('') : hex.slice(1);
56
+ const [r, g, b] = [0, 2, 4].map((i) => {
57
+ const c = parseInt(h.slice(i, i + 2), 16) / 255;
58
+ return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
59
+ });
60
+ return 0.2126 * r! + 0.7152 * g! + 0.0722 * b!;
61
+ }
62
+
63
+ /**
64
+ * The `site.theme` colours as an inline `style` for the `.site` element. Validated here again
65
+ * (not only in the config), because the value ends up in CSS: anything that is not a hex colour
66
+ * is dropped. Text on the accent (`--accent-ink`) is picked for contrast.
67
+ */
68
+ export function themeStyle(
69
+ theme?: { accent?: string | null; background?: string | null; text?: string | null } | null,
70
+ ): string {
71
+ const out: string[] = [];
72
+ if (isHex(theme?.accent)) {
73
+ out.push(`--accent:${theme.accent}`);
74
+ out.push(`--accent-ink:${luminance(theme.accent) > 0.179 ? '#111111' : '#ffffff'}`);
75
+ }
76
+ if (isHex(theme?.background)) out.push(`--bg:${theme.background}`);
77
+ if (isHex(theme?.text)) out.push(`--ink:${theme.text}`);
78
+ return out.join(';');
79
+ }
@@ -0,0 +1,3 @@
1
+ /** A date for display. UTC, so the server and the browser agree (no hydration mismatch). */
2
+ export const formatDate = (iso?: string | null, dateStyle: 'medium' | 'long' = 'medium') =>
3
+ iso ? new Date(iso).toLocaleDateString('en', { dateStyle, timeZone: 'UTC' }) : '';
@@ -0,0 +1,13 @@
1
+ // Client-safe (no config import): used by the config's `icon` select and the Features block.
2
+ export const ICONS = ['star', 'heart', 'shield', 'clock', 'pin', 'chat'] as const;
3
+ export type IconName = (typeof ICONS)[number];
4
+
5
+ /** 24x24 stroke paths (outline icons). */
6
+ export const ICON_PATHS: Record<IconName, string> = {
7
+ star: 'M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1L3.2 9.5l6.1-.9L12 3z',
8
+ heart: 'M12 20s-7-4.4-7-10a4 4 0 0 1 7-2.6A4 4 0 0 1 19 10c0 5.6-7 10-7 10z',
9
+ shield: 'M12 3l7 3v5c0 4.5-3 8-7 10-4-2-7-5.5-7-10V6l7-3z',
10
+ clock: 'M12 7v5l3 2M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z',
11
+ pin: 'M12 21s-6-5.5-6-11a6 6 0 0 1 12 0c0 5.5-6 11-6 11zM12 12a2 2 0 1 0 0-4 2 2 0 0 0 0 4z',
12
+ chat: 'M4 5h16v11H9l-5 4V5z',
13
+ };
@@ -0,0 +1,29 @@
1
+ // Cloudflare Image Transformations URLs (https://developers.cloudflare.com/images/transform-images/).
2
+ // `/cdn-cgi/image/<options>/<source>` resizes and re-encodes on the fly (avif/webp via `format=auto`).
3
+ // It needs a zone with Image Transformations enabled, so it does nothing in dev, on *.workers.dev
4
+ // or for URLs it can't transform.
5
+
6
+ export interface ImageOptions {
7
+ width?: number;
8
+ height?: number;
9
+ fit?: 'scale-down' | 'contain' | 'cover' | 'crop' | 'pad';
10
+ quality?: number;
11
+ }
12
+
13
+ /**
14
+ * @param enabled Pass false in dev and on *.workers.dev (see `Img.svelte`): the URL is returned unchanged.
15
+ */
16
+ export function imageUrl(url: string, options: ImageOptions = {}, enabled = true): string {
17
+ if (!enabled) return url;
18
+ const absolute = /^https:\/\//i.test(url);
19
+ const rootRelative = url.startsWith('/') && !url.startsWith('//');
20
+ if (!absolute && !rootRelative) return url;
21
+ // SVG is vector already, and the transformer would only rasterize it.
22
+ if (/\.svg(\?|$)/i.test(url)) return url;
23
+ const parts = ['format=auto'];
24
+ if (options.width) parts.push(`width=${Math.round(options.width)}`);
25
+ if (options.height) parts.push(`height=${Math.round(options.height)}`);
26
+ if (options.fit) parts.push(`fit=${options.fit}`);
27
+ if (options.quality) parts.push(`quality=${Math.round(options.quality)}`);
28
+ return `/cdn-cgi/image/${parts.join(',')}${rootRelative ? '' : '/'}${url}`;
29
+ }
@@ -0,0 +1 @@
1
+ export { imageUrl } from './image';