sproutsite 0.5.23 → 0.5.25
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/README.md +46 -8
- package/THIRD_PARTY_NOTICES.md +5 -3
- package/VERSION +1 -1
- package/package.json +4 -2
- package/src/lib/sproutsite/branding.ts +150 -0
- package/src/lib/sproutsite/hero-background.ts +61 -0
- package/src/lib/sproutsite/public-assets.ts +33 -0
- package/src/lib/sproutsite/remark-links.ts +4 -3
- package/src/lib/sproutsite/site-config.ts +211 -24
- package/src/lib/sproutsite/sitemap.ts +2 -2
- package/src/lib/sproutsite/types.ts +8 -9
- package/src/lib/sproutsite/urls.ts +3 -3
- package/src/lib/sproutsite/validation.ts +4 -1
- package/src/package/config.ts +25 -8
- package/src/package/content.ts +25 -1
- package/src/package/manifest.ts +5 -10
- package/src/package/page.astro +6 -3
- package/src/package/starter-assets/README.md +85 -0
- package/src/package/starter-assets/manifest.json +95 -0
- package/src/package/starter-assets/public/LICENSE.txt +202 -0
- package/src/package/starter-assets/public/NOTICE.txt +10 -0
- package/src/package/starter-assets/public/branding/apple-touch-icon.png +0 -0
- package/src/package/starter-assets/public/branding/favicon-16.png +0 -0
- package/src/package/starter-assets/public/branding/favicon-32.png +0 -0
- package/src/package/starter-assets/public/branding/favicon-48.png +0 -0
- package/src/package/starter-assets/public/branding/favicon.ico +0 -0
- package/src/package/starter-assets/public/branding/favicon.svg +1 -0
- package/src/package/starter-assets/public/branding/icon-192.png +0 -0
- package/src/package/starter-assets/public/branding/icon-512.png +0 -0
- package/src/package/starter-assets/public/branding/logo-light.svg +1 -0
- package/src/package/starter-assets/public/branding/logo.svg +1 -0
- package/src/package/starter-assets/public/branding/sharing-image.png +0 -0
- package/src/package/starter-assets/public/images/hero.jpg +0 -0
- package/src/package/starter-assets/sources/hero.svg +12 -0
- package/src/package/starter-assets/sources/sharing-image.svg +18 -0
- package/src/themes/default/branding.ts +53 -0
- package/src/themes/default/components/atoms/BrandLogo/BrandLogo.astro +49 -12
- package/src/themes/default/components/atoms/BrandLogo/BrandLogo.css +28 -0
- package/src/themes/default/components/atoms/HeroBackground/HeroBackground.astro +52 -0
- package/src/themes/default/components/atoms/HeroBackground/HeroBackground.css +23 -0
- package/src/themes/default/components/molecules/LanguageSwitcher/LanguageSwitcher.astro +8 -5
- package/src/themes/default/components/organisms/BlogIndex/BlogIndex.astro +16 -13
- package/src/themes/default/components/organisms/BlogPost/BlogPost.astro +1 -1
- package/src/themes/default/components/organisms/Footer/Footer.astro +2 -2
- package/src/themes/default/components/organisms/Footer/Footer.css +3 -1
- package/src/themes/default/components/organisms/Header/Header.astro +4 -4
- package/src/themes/default/components/organisms/Header/Header.css +7 -1
- package/src/themes/default/components/organisms/Hero/Hero.astro +12 -13
- package/src/themes/default/components/organisms/Hero/Hero.css +7 -18
- package/src/themes/default/components/organisms/PageTitle/PageTitle.astro +19 -0
- package/src/themes/default/layouts/ErrorPage/ErrorPage.astro +7 -6
- package/src/themes/default/layouts/PageLayout/PageLayout.astro +26 -35
- package/src/themes/default/styles/theme.css +1 -0
- package/src/themes/default/assets/hero-waves.svg +0 -41
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { parse } from 'yaml';
|
|
5
5
|
import type { SiteConfig } from './types.js';
|
|
6
|
+
import { publicHeroImage, validateHeroBackground } from './hero-background.js';
|
|
7
|
+
import { brandingSchema, validateBrandingFiles } from './branding.js';
|
|
6
8
|
|
|
7
9
|
const linkSchema = z.object({
|
|
8
10
|
label: z.string().trim().min(1),
|
|
@@ -57,6 +59,7 @@ const fontSelectionSchema = z
|
|
|
57
59
|
.default({ family: 'serif', weight: 500 });
|
|
58
60
|
|
|
59
61
|
const siteSchema = z.object({
|
|
62
|
+
branding: brandingSchema.optional(),
|
|
60
63
|
typography: z
|
|
61
64
|
.object({
|
|
62
65
|
headings: fontSelectionSchema,
|
|
@@ -69,8 +72,13 @@ const siteSchema = z.object({
|
|
|
69
72
|
}),
|
|
70
73
|
links: z
|
|
71
74
|
.object({
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
external: z
|
|
76
|
+
.object({
|
|
77
|
+
newTab: z.boolean().optional(),
|
|
78
|
+
icon: z.boolean().optional(),
|
|
79
|
+
})
|
|
80
|
+
.strict()
|
|
81
|
+
.optional(),
|
|
74
82
|
})
|
|
75
83
|
.strict()
|
|
76
84
|
.optional(),
|
|
@@ -79,21 +87,52 @@ const siteSchema = z.object({
|
|
|
79
87
|
base: z
|
|
80
88
|
.string()
|
|
81
89
|
.regex(/^\/(?:[^/].*)?\/$|^\/$/, 'must be / or begin and end with /'),
|
|
82
|
-
|
|
83
|
-
.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
i18n: z
|
|
91
|
+
.object({
|
|
92
|
+
locale: z
|
|
93
|
+
.string()
|
|
94
|
+
.regex(
|
|
95
|
+
/^[a-z]{2}(?:-[A-Z]{2})?$/,
|
|
96
|
+
'must be a BCP 47 language tag',
|
|
97
|
+
),
|
|
98
|
+
defaultLocale: z.string().regex(/^[a-z]{2}(?:-[A-Z]{2})?$/),
|
|
99
|
+
locales: z
|
|
100
|
+
.array(z.string().regex(/^[a-z]{2}(?:-[A-Z]{2})?$/))
|
|
101
|
+
.min(1)
|
|
102
|
+
.refine(
|
|
103
|
+
(locales) => new Set(locales).size === locales.length,
|
|
104
|
+
'must contain unique locales',
|
|
105
|
+
),
|
|
106
|
+
})
|
|
107
|
+
.strict()
|
|
108
|
+
.superRefine((value, context) => {
|
|
109
|
+
for (const field of ['locale', 'defaultLocale'] as const)
|
|
110
|
+
if (!value.locales.includes(value[field]))
|
|
111
|
+
context.addIssue({
|
|
112
|
+
code: 'custom',
|
|
113
|
+
path: [field],
|
|
114
|
+
message: 'must be included in i18n.locales',
|
|
115
|
+
});
|
|
116
|
+
}),
|
|
117
|
+
hero: z
|
|
118
|
+
.object({
|
|
119
|
+
classes: z.array(heroClass).max(8).default([]),
|
|
120
|
+
'background-image': publicHeroImage.optional(),
|
|
121
|
+
})
|
|
122
|
+
.strict()
|
|
123
|
+
.default({ classes: [] }),
|
|
90
124
|
blog: z
|
|
91
125
|
.object({
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
126
|
+
hero: z
|
|
127
|
+
.object({
|
|
128
|
+
title: z.string().trim().min(1),
|
|
129
|
+
description: z.string().trim().min(1),
|
|
130
|
+
eyebrow: z.string().trim().min(1),
|
|
131
|
+
})
|
|
132
|
+
.strict(),
|
|
133
|
+
articles: z.object({ heading: z.string().trim().min(1) }).strict(),
|
|
96
134
|
})
|
|
135
|
+
.strict()
|
|
97
136
|
.optional(),
|
|
98
137
|
header: z.object({
|
|
99
138
|
links: z
|
|
@@ -166,22 +205,170 @@ const siteSchema = z.object({
|
|
|
166
205
|
}),
|
|
167
206
|
});
|
|
168
207
|
|
|
208
|
+
function record(value: unknown): value is Record<string, unknown> {
|
|
209
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Config objects inherit fields; arrays, primitives and explicit null replace. */
|
|
213
|
+
function mergeConfig(
|
|
214
|
+
base: Record<string, unknown>,
|
|
215
|
+
override: Record<string, unknown>,
|
|
216
|
+
): Record<string, unknown> {
|
|
217
|
+
const merged = { ...base };
|
|
218
|
+
for (const [key, value] of Object.entries(override)) {
|
|
219
|
+
if (['__proto__', 'prototype', 'constructor'].includes(key))
|
|
220
|
+
throw new Error(`Unsafe site configuration key: ${key}`);
|
|
221
|
+
merged[key] =
|
|
222
|
+
record(merged[key]) && record(value)
|
|
223
|
+
? mergeConfig(merged[key], value)
|
|
224
|
+
: value;
|
|
225
|
+
}
|
|
226
|
+
return merged;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Read old generated projects as well; never combine competing spellings. */
|
|
230
|
+
function readConfig(
|
|
231
|
+
source: string,
|
|
232
|
+
primary: boolean,
|
|
233
|
+
defaultLocale?: string,
|
|
234
|
+
): Record<string, unknown> {
|
|
235
|
+
const raw: unknown = parse(readFileSync(source, 'utf8'));
|
|
236
|
+
if (!record(raw))
|
|
237
|
+
throw new Error(`Invalid ${source}: expected a configuration object`);
|
|
238
|
+
const result = { ...raw };
|
|
239
|
+
if ('hero-classes' in result)
|
|
240
|
+
throw new Error(
|
|
241
|
+
`Invalid ${source}: hero-classes has moved to hero.classes. Use hero: { classes: [...] }.`,
|
|
242
|
+
);
|
|
243
|
+
if ('language' in result || 'locales' in result) {
|
|
244
|
+
if ('i18n' in result)
|
|
245
|
+
throw new Error(
|
|
246
|
+
`Invalid ${source}: use i18n instead of mixing language/locales with i18n`,
|
|
247
|
+
);
|
|
248
|
+
result.i18n = {
|
|
249
|
+
...(primary
|
|
250
|
+
? {
|
|
251
|
+
defaultLocale: result.language,
|
|
252
|
+
locales: result.locales ?? [result.language],
|
|
253
|
+
}
|
|
254
|
+
: {}),
|
|
255
|
+
...(result.language !== undefined
|
|
256
|
+
? { locale: result.language }
|
|
257
|
+
: {}),
|
|
258
|
+
...(!primary && result.locales !== undefined
|
|
259
|
+
? { locales: result.locales }
|
|
260
|
+
: {}),
|
|
261
|
+
...(!primary && defaultLocale !== undefined
|
|
262
|
+
? { defaultLocale }
|
|
263
|
+
: {}),
|
|
264
|
+
};
|
|
265
|
+
delete result.language;
|
|
266
|
+
delete result.locales;
|
|
267
|
+
}
|
|
268
|
+
if (
|
|
269
|
+
record(result.links) &&
|
|
270
|
+
('externalNewTab' in result.links || 'externalIcon' in result.links)
|
|
271
|
+
) {
|
|
272
|
+
const { externalNewTab, externalIcon, ...links } = result.links;
|
|
273
|
+
if ('external' in links)
|
|
274
|
+
throw new Error(
|
|
275
|
+
`Invalid ${source}: do not mix legacy link options with links.external`,
|
|
276
|
+
);
|
|
277
|
+
result.links = {
|
|
278
|
+
...links,
|
|
279
|
+
external: {
|
|
280
|
+
...(externalNewTab !== undefined
|
|
281
|
+
? { newTab: externalNewTab }
|
|
282
|
+
: {}),
|
|
283
|
+
...(externalIcon !== undefined ? { icon: externalIcon } : {}),
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
const blogInput = result.blog;
|
|
288
|
+
if (
|
|
289
|
+
record(blogInput) &&
|
|
290
|
+
['title', 'eyebrow', 'description', 'heading'].some(
|
|
291
|
+
(key) => key in blogInput,
|
|
292
|
+
)
|
|
293
|
+
) {
|
|
294
|
+
const { title, eyebrow, description, heading, ...blog } = blogInput;
|
|
295
|
+
if ('hero' in blog || 'articles' in blog)
|
|
296
|
+
throw new Error(
|
|
297
|
+
`Invalid ${source}: do not mix flat blog options with blog.hero/blog.articles`,
|
|
298
|
+
);
|
|
299
|
+
result.blog = {
|
|
300
|
+
...blog,
|
|
301
|
+
hero: { title, eyebrow, description },
|
|
302
|
+
articles: { heading },
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function parseConfig(
|
|
309
|
+
raw: Record<string, unknown>,
|
|
310
|
+
filename: string,
|
|
311
|
+
root: string,
|
|
312
|
+
): SiteConfig {
|
|
313
|
+
const parsed = siteSchema.safeParse(raw);
|
|
314
|
+
if (!parsed.success)
|
|
315
|
+
throw new Error(
|
|
316
|
+
`Invalid src/content/${filename}: ${parsed.error.issues.map((issue) => `${issue.path.join('.')}: ${issue.message}`).join('; ')}`,
|
|
317
|
+
);
|
|
318
|
+
const config = parsed.data;
|
|
319
|
+
validateHeroBackground(
|
|
320
|
+
config.hero['background-image'],
|
|
321
|
+
`src/content/${filename}`,
|
|
322
|
+
root,
|
|
323
|
+
);
|
|
324
|
+
validateBrandingFiles(config.branding, root, `src/content/${filename}`);
|
|
325
|
+
return config;
|
|
326
|
+
}
|
|
327
|
+
|
|
169
328
|
export function loadSiteConfig(
|
|
170
329
|
locale?: string,
|
|
171
330
|
root = process.cwd(),
|
|
172
331
|
): SiteConfig {
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const raw = parse(readFileSync(source, 'utf8'));
|
|
177
|
-
const parsed = siteSchema.safeParse(raw);
|
|
178
|
-
if (!parsed.success) {
|
|
332
|
+
const primaryRaw = readConfig(resolve(root, 'src/content/site.yaml'), true);
|
|
333
|
+
const primary = parseConfig(primaryRaw, 'site.yaml', root);
|
|
334
|
+
if (primary.i18n.locale !== primary.i18n.defaultLocale)
|
|
179
335
|
throw new Error(
|
|
180
|
-
|
|
336
|
+
'Invalid src/content/site.yaml: i18n.locale must match i18n.defaultLocale in the base configuration',
|
|
181
337
|
);
|
|
338
|
+
const target = locale ?? primary.i18n.defaultLocale;
|
|
339
|
+
if (!primary.i18n.locales.includes(target))
|
|
340
|
+
throw new Error(
|
|
341
|
+
`Invalid site locale ${target}: must be included in i18n.locales`,
|
|
342
|
+
);
|
|
343
|
+
const filename = `site.${target}.yaml`;
|
|
344
|
+
const localized = resolve(root, 'src/content', filename);
|
|
345
|
+
let config = primary;
|
|
346
|
+
if (
|
|
347
|
+
locale !== undefined &&
|
|
348
|
+
(existsSync(localized) || target !== primary.i18n.defaultLocale)
|
|
349
|
+
) {
|
|
350
|
+
const layer = existsSync(localized)
|
|
351
|
+
? readConfig(localized, false, primary.i18n.defaultLocale)
|
|
352
|
+
: {};
|
|
353
|
+
const override = mergeConfig({ i18n: { locale: target } }, layer);
|
|
354
|
+
config = parseConfig(mergeConfig(primaryRaw, override), filename, root);
|
|
355
|
+
if (config.i18n.locale !== target)
|
|
356
|
+
throw new Error(
|
|
357
|
+
`Invalid src/content/${filename}: i18n.locale must be ${target}`,
|
|
358
|
+
);
|
|
359
|
+
for (const field of ['defaultLocale', 'locales'] as const)
|
|
360
|
+
if (
|
|
361
|
+
JSON.stringify(config.i18n[field]) !==
|
|
362
|
+
JSON.stringify(primary.i18n[field])
|
|
363
|
+
)
|
|
364
|
+
throw new Error(
|
|
365
|
+
`Invalid src/content/${filename}: i18n.${field} must match site.yaml`,
|
|
366
|
+
);
|
|
367
|
+
if (config.url !== primary.url || config.base !== primary.base)
|
|
368
|
+
throw new Error(
|
|
369
|
+
`Invalid src/content/${filename}: url and base must match site.yaml`,
|
|
370
|
+
);
|
|
182
371
|
}
|
|
183
|
-
const { 'hero-classes': heroClasses, ...site } = parsed.data;
|
|
184
|
-
const config: SiteConfig = { ...site, heroClasses };
|
|
185
372
|
const environmentBase = process.env.SPROUTSITE_BASE;
|
|
186
373
|
if (environmentBase === undefined) return config;
|
|
187
374
|
const base = siteSchema.shape.base.safeParse(environmentBase);
|
|
@@ -43,7 +43,7 @@ export function createSitemapMetadata(root = process.cwd()) {
|
|
|
43
43
|
files: string[];
|
|
44
44
|
directory?: string;
|
|
45
45
|
}[] = [];
|
|
46
|
-
for (const locale of site.locales) {
|
|
46
|
+
for (const locale of site.i18n.locales) {
|
|
47
47
|
const localizedSite = loadSiteConfig(locale, root);
|
|
48
48
|
const siteFiles = [
|
|
49
49
|
join(root, 'src/content/site.yaml'),
|
|
@@ -147,7 +147,7 @@ export function createSitemapMetadata(root = process.cwd()) {
|
|
|
147
147
|
url: candidate.url,
|
|
148
148
|
}));
|
|
149
149
|
const defaultEntry = equivalents.find(
|
|
150
|
-
(candidate) => candidate.locale === site.
|
|
150
|
+
(candidate) => candidate.locale === site.i18n.defaultLocale,
|
|
151
151
|
);
|
|
152
152
|
if (defaultEntry)
|
|
153
153
|
links.push({ lang: 'x-default', url: defaultEntry.url });
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Branding } from './branding.js';
|
|
2
|
+
|
|
1
3
|
export const tones = ['default', 'muted', 'brand'] as const;
|
|
2
4
|
export type Tone = (typeof tones)[number];
|
|
3
5
|
export type SectionTone = Tone | { odd: Tone; even: Tone };
|
|
@@ -28,25 +30,22 @@ export type HeaderItem =
|
|
|
28
30
|
| { type: 'language-switcher' };
|
|
29
31
|
|
|
30
32
|
export interface SiteConfig {
|
|
33
|
+
branding?: Branding;
|
|
31
34
|
name: string;
|
|
32
35
|
url: string;
|
|
33
36
|
base: string;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
heroClasses: string[];
|
|
37
|
+
i18n: { locale: string; defaultLocale: string; locales: string[] };
|
|
38
|
+
hero: { classes: string[]; 'background-image'?: string };
|
|
37
39
|
typography: {
|
|
38
40
|
headings: { family: 'serif' | 'sans-serif'; weight: number };
|
|
39
41
|
eyebrow: { family: 'serif' | 'sans-serif'; weight: number };
|
|
40
42
|
};
|
|
41
43
|
links?: {
|
|
42
|
-
|
|
43
|
-
externalIcon?: boolean;
|
|
44
|
+
external?: { newTab?: boolean; icon?: boolean };
|
|
44
45
|
};
|
|
45
46
|
blog?: {
|
|
46
|
-
title: string;
|
|
47
|
-
|
|
48
|
-
eyebrow: string;
|
|
49
|
-
heading: string;
|
|
47
|
+
hero: { title: string; description: string; eyebrow: string };
|
|
48
|
+
articles: { heading: string };
|
|
50
49
|
};
|
|
51
50
|
header: { links: HeaderItem[] };
|
|
52
51
|
footer: {
|
|
@@ -40,9 +40,9 @@ export function withBase(pathname: string, base: string): string {
|
|
|
40
40
|
|
|
41
41
|
export function contentHref(href: string, site: SiteConfig): string {
|
|
42
42
|
if (!href.startsWith('/') || href.startsWith('//')) return href;
|
|
43
|
-
const defaultLocale = site.
|
|
43
|
+
const defaultLocale = site.i18n.defaultLocale;
|
|
44
44
|
const localePrefix =
|
|
45
|
-
site.
|
|
45
|
+
site.i18n.locale === defaultLocale ? '' : `/${site.i18n.locale}`;
|
|
46
46
|
const localizedHref =
|
|
47
47
|
localePrefix === '' ||
|
|
48
48
|
href === localePrefix ||
|
|
@@ -89,7 +89,7 @@ export function externalLinkAttributes(
|
|
|
89
89
|
if (!isExternalWebLink(href, site.url)) return {};
|
|
90
90
|
return {
|
|
91
91
|
'data-external-link': '',
|
|
92
|
-
...(site.links?.
|
|
92
|
+
...(site.links?.external?.newTab !== false
|
|
93
93
|
? { target: '_blank' as const, rel: 'noopener noreferrer' }
|
|
94
94
|
: {}),
|
|
95
95
|
};
|
|
@@ -13,6 +13,7 @@ import { visit } from 'unist-util-visit';
|
|
|
13
13
|
import { loadSiteConfig } from './site-config.js';
|
|
14
14
|
import { heroTypes, sectionSpacings, tones } from './types.js';
|
|
15
15
|
import { isHexColor } from './colors.js';
|
|
16
|
+
import { validateHeroBackground } from './hero-background.js';
|
|
16
17
|
import {
|
|
17
18
|
badgeVariants,
|
|
18
19
|
badgeStyles,
|
|
@@ -78,7 +79,7 @@ const heroSchema = markdownSchema
|
|
|
78
79
|
})
|
|
79
80
|
.optional(),
|
|
80
81
|
classes: z.array(heroClass).max(8).nullable().optional(),
|
|
81
|
-
'background-image': z.string().trim().min(1).optional(),
|
|
82
|
+
'background-image': z.string().trim().min(1).nullable().optional(),
|
|
82
83
|
actions: z.array(heroAction).min(1).max(2).optional(),
|
|
83
84
|
claim: z.string().trim().min(1).optional(),
|
|
84
85
|
tagline: z.string().trim().min(1).optional(),
|
|
@@ -1366,6 +1367,8 @@ export function validateSproutsiteContent(
|
|
|
1366
1367
|
);
|
|
1367
1368
|
if (filename === 'hero.md') {
|
|
1368
1369
|
const heroMetadata = heroSchema.parse(frontmatter);
|
|
1370
|
+
if (heroMetadata['background-image']?.startsWith('/'))
|
|
1371
|
+
validateHeroBackground(heroMetadata['background-image'], path);
|
|
1369
1372
|
for (const action of heroMetadata.actions ?? []) {
|
|
1370
1373
|
if (
|
|
1371
1374
|
/^(?:javascript:|data:)/i.test(action.href) ||
|
package/src/package/config.ts
CHANGED
|
@@ -17,6 +17,8 @@ import { remarkContentLinks } from '../lib/sproutsite/remark-links.js';
|
|
|
17
17
|
import { loadSiteConfig } from '../lib/sproutsite/site-config.js';
|
|
18
18
|
import { validateSproutsiteContent } from '../lib/sproutsite/validation.js';
|
|
19
19
|
import { createSitemapMetadata } from '../lib/sproutsite/sitemap.js';
|
|
20
|
+
import { validateBrandingImages } from '../lib/sproutsite/branding.js';
|
|
21
|
+
import { validateHeroBackgroundImage } from '../lib/sproutsite/hero-background.js';
|
|
20
22
|
|
|
21
23
|
/** Returns the Astro configuration required by the default Sproutsite theme. */
|
|
22
24
|
export function createSproutsiteConfig() {
|
|
@@ -28,8 +30,8 @@ export function createSproutsiteConfig() {
|
|
|
28
30
|
site: site.url,
|
|
29
31
|
base: site.base,
|
|
30
32
|
i18n: {
|
|
31
|
-
locales: site.locales,
|
|
32
|
-
defaultLocale: site.
|
|
33
|
+
locales: site.i18n.locales,
|
|
34
|
+
defaultLocale: site.i18n.defaultLocale,
|
|
33
35
|
routing: { prefixDefaultLocale: false },
|
|
34
36
|
},
|
|
35
37
|
integrations: [
|
|
@@ -58,7 +60,21 @@ export function createSproutsiteConfig() {
|
|
|
58
60
|
{
|
|
59
61
|
name: 'sproutsite/default-routes',
|
|
60
62
|
hooks: {
|
|
61
|
-
'astro:config:setup': ({ injectRoute }) => {
|
|
63
|
+
'astro:config:setup': async ({ injectRoute }) => {
|
|
64
|
+
for (const locale of site.i18n.locales) {
|
|
65
|
+
await validateHeroBackgroundImage(
|
|
66
|
+
(locale === site.i18n.defaultLocale
|
|
67
|
+
? site
|
|
68
|
+
: loadSiteConfig(locale)
|
|
69
|
+
).hero['background-image'],
|
|
70
|
+
);
|
|
71
|
+
await validateBrandingImages(
|
|
72
|
+
(locale === site.i18n.defaultLocale
|
|
73
|
+
? site
|
|
74
|
+
: loadSiteConfig(locale)
|
|
75
|
+
).branding,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
62
78
|
injectRoute({
|
|
63
79
|
pattern: '/404',
|
|
64
80
|
entrypoint: new URL('./404.astro', import.meta.url),
|
|
@@ -69,8 +85,8 @@ export function createSproutsiteConfig() {
|
|
|
69
85
|
entrypoint: new URL('./500.astro', import.meta.url),
|
|
70
86
|
prerender: true,
|
|
71
87
|
});
|
|
72
|
-
for (const locale of site.locales.filter(
|
|
73
|
-
(locale) => locale !== site.
|
|
88
|
+
for (const locale of site.i18n.locales.filter(
|
|
89
|
+
(locale) => locale !== site.i18n.defaultLocale,
|
|
74
90
|
)) {
|
|
75
91
|
for (const status of [404, 500]) {
|
|
76
92
|
injectRoute({
|
|
@@ -106,8 +122,8 @@ export function createSproutsiteConfig() {
|
|
|
106
122
|
);
|
|
107
123
|
// Astro owns error-page rendering. Flatten localized output
|
|
108
124
|
// for web servers that select their error documents by locale.
|
|
109
|
-
for (const locale of site.locales.filter(
|
|
110
|
-
(locale) => locale !== site.
|
|
125
|
+
for (const locale of site.i18n.locales.filter(
|
|
126
|
+
(locale) => locale !== site.i18n.defaultLocale,
|
|
111
127
|
)) {
|
|
112
128
|
for (const status of [404, 500]) {
|
|
113
129
|
const flat = new URL(
|
|
@@ -157,7 +173,8 @@ export function createSproutsiteConfig() {
|
|
|
157
173
|
rehypeExternalLinks,
|
|
158
174
|
{
|
|
159
175
|
url: site.url,
|
|
160
|
-
externalNewTab:
|
|
176
|
+
externalNewTab:
|
|
177
|
+
site.links?.external?.newTab ?? true,
|
|
161
178
|
},
|
|
162
179
|
],
|
|
163
180
|
],
|
package/src/package/content.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { defineCollection, type ImageFunction } from 'astro:content';
|
|
|
2
2
|
import { glob } from 'astro/loaders';
|
|
3
3
|
import { z } from 'astro/zod';
|
|
4
4
|
import { heroTypes, sectionSpacings, tones } from '../lib/sproutsite/types.js';
|
|
5
|
+
import { publicHeroImage } from '../lib/sproutsite/hero-background.js';
|
|
5
6
|
import { optionalBlogLoader } from './optional-blog-loader.js';
|
|
6
7
|
import { createBlogReadinessLoader } from './blog-state.js';
|
|
7
8
|
|
|
@@ -80,7 +81,30 @@ export function createSproutsiteCollections(
|
|
|
80
81
|
titleHighlight: z.string().trim().min(1).optional(),
|
|
81
82
|
eyebrow: z.string().trim().min(1).optional(),
|
|
82
83
|
classes: z.array(heroClass).max(8).nullable().optional(),
|
|
83
|
-
'background-image':
|
|
84
|
+
'background-image': z
|
|
85
|
+
.union([
|
|
86
|
+
z
|
|
87
|
+
.string()
|
|
88
|
+
.refine(
|
|
89
|
+
(src) => publicHeroImage.safeParse(src).success,
|
|
90
|
+
'must be a public image path',
|
|
91
|
+
),
|
|
92
|
+
z.preprocess((value, context) => {
|
|
93
|
+
if (
|
|
94
|
+
typeof value !== 'string' ||
|
|
95
|
+
!(value.startsWith('./') || value.startsWith('../'))
|
|
96
|
+
) {
|
|
97
|
+
context.addIssue({
|
|
98
|
+
code: 'custom',
|
|
99
|
+
message: 'must be a relative local image path',
|
|
100
|
+
});
|
|
101
|
+
return z.NEVER;
|
|
102
|
+
}
|
|
103
|
+
return value;
|
|
104
|
+
}, image()),
|
|
105
|
+
])
|
|
106
|
+
.nullable()
|
|
107
|
+
.optional(),
|
|
84
108
|
actions: z.array(heroAction).min(1).max(2).optional(),
|
|
85
109
|
claim: z.string().trim().min(1).optional(),
|
|
86
110
|
tagline: z.string().trim().min(1).optional(),
|
package/src/package/manifest.ts
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
import type { APIRoute } from 'astro';
|
|
2
|
-
import
|
|
3
|
-
import icon512 from '../themes/default/assets/branding/icon-512x512.png';
|
|
2
|
+
import { resolveBranding } from '../themes/default/branding.js';
|
|
4
3
|
import { loadSiteConfig } from '../lib/sproutsite/site-config.js';
|
|
5
4
|
|
|
6
5
|
// A native static Astro endpoint keeps bundled, hashed icon URLs correct for
|
|
7
6
|
// both package consumers and deployments under a base path. No service worker.
|
|
8
|
-
export const GET: APIRoute = () => {
|
|
7
|
+
export const GET: APIRoute = async () => {
|
|
9
8
|
const site = loadSiteConfig();
|
|
9
|
+
const branding = await resolveBranding(site);
|
|
10
10
|
return new Response(
|
|
11
11
|
JSON.stringify({
|
|
12
12
|
name: site.name,
|
|
13
13
|
short_name: site.name,
|
|
14
|
-
lang: site.
|
|
14
|
+
lang: site.i18n.locale,
|
|
15
15
|
start_url: site.base,
|
|
16
16
|
scope: site.base,
|
|
17
17
|
display: 'browser',
|
|
18
|
-
icons:
|
|
19
|
-
src: icon.src,
|
|
20
|
-
sizes: `${icon.width}x${icon.height}`,
|
|
21
|
-
type: 'image/png',
|
|
22
|
-
purpose: 'any',
|
|
23
|
-
})),
|
|
18
|
+
icons: branding.appIcons,
|
|
24
19
|
}),
|
|
25
20
|
{ headers: { 'Content-Type': 'application/manifest+json' } },
|
|
26
21
|
);
|
package/src/package/page.astro
CHANGED
|
@@ -16,8 +16,10 @@ type Locale = 'en' | 'de';
|
|
|
16
16
|
|
|
17
17
|
export { localeOf, logicalId };
|
|
18
18
|
|
|
19
|
-
export async function getSproutsiteStaticPaths(
|
|
20
|
-
|
|
19
|
+
export async function getSproutsiteStaticPaths(
|
|
20
|
+
locale: Locale = loadSiteConfig().i18n.defaultLocale as Locale,
|
|
21
|
+
) {
|
|
22
|
+
if (!loadSiteConfig().i18n.locales.includes(locale)) return [];
|
|
21
23
|
const pages = assemblePages(
|
|
22
24
|
(await getCollection('pages')).filter(
|
|
23
25
|
(entry) => localeOf(entry.id) === locale,
|
|
@@ -105,8 +107,9 @@ const postSections = post
|
|
|
105
107
|
<Hero hero={page.hero!} site={site} Content={hero.Content} />
|
|
106
108
|
) : page.entry.data.layout !== 'landing' ? (
|
|
107
109
|
<PageTitle
|
|
110
|
+
site={site}
|
|
108
111
|
title={page.entry.data.title}
|
|
109
|
-
classes={site.
|
|
112
|
+
classes={site.hero.classes}
|
|
110
113
|
/>
|
|
111
114
|
) : null}
|
|
112
115
|
{sections.map(({ section, rendered }) => (
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Neutral website starter assets
|
|
2
|
+
|
|
3
|
+
Sproutsite maintains this asset set. The separate `create-sproutsite` project
|
|
4
|
+
vendors a reviewed snapshot when preparing its own release. It must not download
|
|
5
|
+
assets or install Sproutsite just to create files for an end user.
|
|
6
|
+
|
|
7
|
+
## Public entry and copy contract
|
|
8
|
+
|
|
9
|
+
Resolve `sproutsite/starter-assets` to locate `manifest.json` in the installed
|
|
10
|
+
package. This is a public export, not a private theme path:
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { createRequire } from 'node:module';
|
|
14
|
+
import { dirname, join } from 'node:path';
|
|
15
|
+
import { readFileSync } from 'node:fs';
|
|
16
|
+
|
|
17
|
+
const require = createRequire(import.meta.url);
|
|
18
|
+
const manifestFile = require.resolve('sproutsite/starter-assets');
|
|
19
|
+
const manifest = JSON.parse(readFileSync(manifestFile, 'utf8'));
|
|
20
|
+
const publicDirectory = join(dirname(manifestFile), manifest.publicDirectory);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Manifest schema version 1 contains:
|
|
24
|
+
|
|
25
|
+
- `publicDirectory`: the directory whose **contents** are copied to the website's
|
|
26
|
+
`public/`, preserving names and binary data. It includes LICENSE.txt and
|
|
27
|
+
NOTICE.txt; preserve both with the assets.
|
|
28
|
+
- `files`: the exact recursive public-file list and SHA-256 hashes. Verify paths
|
|
29
|
+
remain inside the directory and compare the vendored snapshot before release.
|
|
30
|
+
- `branding`: a complete neutral configuration to merge into `site.yaml`.
|
|
31
|
+
`showName: true` displays the generated website's actual name beside a neutral
|
|
32
|
+
document symbol. The icon intentionally works on light and dark backgrounds.
|
|
33
|
+
- `localizedSharingImageAlt`: English and German alternative text. The generator
|
|
34
|
+
may personalize this with the chosen website name; do not replace tokens in
|
|
35
|
+
image files.
|
|
36
|
+
- `heroExample`: an optional existing-API integration. Copy its `source` to
|
|
37
|
+
`contentDestination` and merge `frontmatter` into the homepage hero. Use the
|
|
38
|
+
same local asset for both languages. This recipe uses Astro's
|
|
39
|
+
local image schema for optimization. Alternatively set the global
|
|
40
|
+
`hero.background-image` to `/images/hero.jpg` after copying public files;
|
|
41
|
+
public images are delivered unchanged. Set `classes: null` to remove the
|
|
42
|
+
default theme classes. The local image independently replaces any global
|
|
43
|
+
background image.
|
|
44
|
+
|
|
45
|
+
Do not merge a second duplicate `branding` YAML key. Keep the existing name,
|
|
46
|
+
URL, locale, typography and navigation configuration. Locale files inherit the
|
|
47
|
+
main configuration and can override `sharingImage.alt`.
|
|
48
|
+
|
|
49
|
+
## Files and ownership
|
|
50
|
+
|
|
51
|
+
`public/branding/` contains logo.svg, logo-light.svg, favicon.svg, favicon.ico,
|
|
52
|
+
16/32/48-pixel PNG favicon variants, a 180-pixel Apple touch icon, 192/512-pixel
|
|
53
|
+
app icons and a 1200×630 sharing-image.png. `public/images/hero.jpg` is 1920×1080.
|
|
54
|
+
The optional PNG favicon variants are available for consumers needing them;
|
|
55
|
+
the current branding API uses `favicon` for one preferred SVG, PNG or ICO.
|
|
56
|
+
|
|
57
|
+
The SVG symbol in `public/branding/logo.svg` and the illustrations in `sources/`
|
|
58
|
+
are first-party vector sources without third-party imagery, font dependencies
|
|
59
|
+
or a Sproutsite wordmark. Raster images and ICO frames are derived locally with
|
|
60
|
+
Sharp. There is no AI image-generation input or provider restriction to resolve
|
|
61
|
+
for this set. All these assets follow Apache-2.0; see the unchanged full license
|
|
62
|
+
and the attribution notice inside `public/`. No additional visible attribution
|
|
63
|
+
or branding requirement is imposed.
|
|
64
|
+
|
|
65
|
+
## Maintenance
|
|
66
|
+
|
|
67
|
+
Run `npm run starter-assets:generate` from the Sproutsite repository after
|
|
68
|
+
editing the vector sources. This updates derivatives, copies the official
|
|
69
|
+
project license unchanged and regenerates the file hashes. The command requires
|
|
70
|
+
development dependencies; website builds and generation do not execute it.
|
|
71
|
+
`npm run branding:generate` also calls it after regenerating the demo branding.
|
|
72
|
+
|
|
73
|
+
The default theme imports its neutral fallback icons directly from this set.
|
|
74
|
+
Do not maintain a second fallback asset directory. Sproutsite's own demo uses
|
|
75
|
+
separate, explicitly configured product files under the repository's root
|
|
76
|
+
`public/branding/`; those are not the starter artwork.
|
|
77
|
+
|
|
78
|
+
Check `npm test` and `npm run test:package` before publishing. The archive test
|
|
79
|
+
resolves the exported manifest from a real installation, verifies every asset
|
|
80
|
+
and builds the copied starter configuration. Package files are committed here;
|
|
81
|
+
consumer projects own their copies and package updates do not overwrite them.
|
|
82
|
+
|
|
83
|
+
The initializer needs its own change and release before it includes this set.
|
|
84
|
+
This repository does not claim that an existing npm version of
|
|
85
|
+
`create-sproutsite` already includes it.
|