sproutsite 0.5.24 → 0.5.26

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 (41) hide show
  1. package/README.md +13 -6
  2. package/THIRD_PARTY_NOTICES.md +3 -3
  3. package/VERSION +1 -1
  4. package/package.json +1 -1
  5. package/src/lib/sproutsite/branding.ts +7 -45
  6. package/src/lib/sproutsite/colors.ts +24 -0
  7. package/src/lib/sproutsite/hero-background.ts +61 -0
  8. package/src/lib/sproutsite/public-assets.ts +33 -0
  9. package/src/lib/sproutsite/remark-links.ts +4 -3
  10. package/src/lib/sproutsite/site-colors.ts +47 -0
  11. package/src/lib/sproutsite/site-config.ts +211 -38
  12. package/src/lib/sproutsite/sitemap.ts +2 -2
  13. package/src/lib/sproutsite/types.ts +7 -9
  14. package/src/lib/sproutsite/urls.ts +3 -3
  15. package/src/lib/sproutsite/validation.ts +4 -1
  16. package/src/package/config.ts +24 -9
  17. package/src/package/content.ts +25 -1
  18. package/src/package/manifest.ts +1 -1
  19. package/src/package/page.astro +6 -3
  20. package/src/package/starter-assets/README.md +6 -3
  21. package/src/themes/default/colors.ts +190 -0
  22. package/src/themes/default/components/atoms/HeroBackground/HeroBackground.astro +52 -0
  23. package/src/themes/default/components/atoms/HeroBackground/HeroBackground.css +23 -0
  24. package/src/themes/default/components/layout/Columns/Columns.css +1 -1
  25. package/src/themes/default/components/molecules/LanguageSwitcher/LanguageSwitcher.astro +8 -5
  26. package/src/themes/default/components/molecules/LanguageSwitcher/LanguageSwitcher.css +1 -1
  27. package/src/themes/default/components/organisms/BlogIndex/BlogIndex.astro +16 -13
  28. package/src/themes/default/components/organisms/BlogPost/BlogPost.astro +1 -1
  29. package/src/themes/default/components/organisms/Footer/Footer.astro +1 -1
  30. package/src/themes/default/components/organisms/Footer/Footer.css +1 -1
  31. package/src/themes/default/components/organisms/Header/Header.astro +2 -2
  32. package/src/themes/default/components/organisms/Header/Header.css +10 -7
  33. package/src/themes/default/components/organisms/Hero/Hero.astro +12 -13
  34. package/src/themes/default/components/organisms/Hero/Hero.css +56 -30
  35. package/src/themes/default/components/organisms/PageTitle/PageTitle.astro +19 -0
  36. package/src/themes/default/layouts/ErrorPage/ErrorPage.astro +7 -6
  37. package/src/themes/default/layouts/PageLayout/PageLayout.astro +8 -3
  38. package/src/themes/default/styles/foundation/tokens.css +1 -0
  39. package/src/themes/default/styles/theme.css +1 -0
  40. package/src/themes/default/styles/themes/section-tones.css +7 -3
  41. package/src/themes/default/assets/hero-waves.svg +0 -41
package/README.md CHANGED
@@ -131,8 +131,6 @@ export async function getStaticPaths() {
131
131
  name: My website
132
132
  url: https://example.com
133
133
  base: /
134
- language: en
135
- locales: [en]
136
134
  header:
137
135
  links:
138
136
  - label: Home
@@ -142,6 +140,11 @@ footer:
142
140
  links:
143
141
  - label: Home
144
142
  href: /
143
+ i18n:
144
+ locale: en
145
+ defaultLocale: en
146
+ locales:
147
+ - en
145
148
  ```
146
149
 
147
150
  Replace `name`, `url`, and the footer copy with your own details. `url` is your production origin, even during local development. A visible Sproutsite attribution is optional. Set `base` if the website will be hosted under a subpath, for example `/demo/`.
@@ -266,7 +269,7 @@ pages/
266
269
 
267
270
  `page.yaml` requires a non-empty `title` and `description`. Both values are used for HTML metadata: `title` becomes the `<title>` tag and `description` becomes the meta description. Without `url`, its directory becomes the URL directly: `faq/page.yaml` becomes `/faq/`; a deeper `services/monitoring/page.yaml` becomes `/services/monitoring/`. The optional single URL segment `url` lets an English source path retain a localized public URL: `documentation/page.yaml` with `url: dokumentation` produces `/dokumentation/`. URL segments of parent pages are also considered for child pages.
268
271
 
269
- A `hero.md` activates the shared hero and requires a frontmatter `title`, rendered as the visible `h1`. `titleHighlight` may select one text fragment from that title for the theme highlight. `hero-classes` in `site.yaml` may optionally set up to eight theme classes for each hero and for the H1 fallback view without `hero.md`. A `classes` list in an individual `hero.md` completely overrides that global list; `classes: null` removes global classes for that hero. Classes must begin with `ss-`, for example `ss-hero--visual`, so a theme can add gradients, overlays, or textures. `background-image` optionally references a local image relative to `hero.md`; Astro validates it and emits an optimized decorative hero image. `claim` adds a prominent line below the title. `actions` optionally defines one or two Button-based calls to action with `label`, `href`, and `variant: primary|secondary`; `tagline` adds a short line below them. If these settings are omitted, the hero receives no additional image or actions. Delete the file to render `page.yaml.title` as a compact visible H1 fallback above the sections; it still receives global `hero-classes`. Sections must be named `NN-name.md`, begin with an `h2`, and may set `tone: default`, `muted`, or `brand` in frontmatter. By default, `ss-section__content` constrains content to a readable width. `fullWidth: true` in section frontmatter removes this inner constraint; the shared outer `site-shell` and Markdown typography remain active. For numbered page and blog sections, `tone` also accepts an object with both `odd` and `even`. Each value is `default`, `muted`, or `brand`. The numeric filename prefix selects the tone, including translated files; it does not depend on the section's position in the page. Scalar tones remain fixed, and omitting `tone` still means `default`. Heroes only accept scalar tones. Use a YAML mapping, not a list:
272
+ A `hero.md` activates the shared hero and requires a frontmatter `title`, rendered as the visible `h1`. `titleHighlight` may select one text fragment from that title for the theme highlight. `hero.classes` in `site.yaml` may optionally set up to eight theme classes for each hero and for the H1 fallback view without `hero.md`. A `classes` list in an individual `hero.md` completely overrides that global list; `classes: null` removes global classes for that hero. Classes must begin with `ss-`, for example `ss-hero--visual`, so a theme can add gradients, overlays, or textures. Global `hero.background-image` in `site.yaml` optionally names a public-root SVG or raster path such as `/backgrounds/hero-waves.svg`. Local `background-image` in `hero.md` overrides it with a public-root path or a relative local image; omission inherits the global setting and `null` disables it. Public paths receive `base` once. Imported raster images are optimized, SVGs and public files are preserved. Without either image setting, no background image is rendered and CSS gradients remain. Classes and images are independent: `classes: null` does not disable a global image. `claim` adds a prominent line below the title. `actions` optionally defines one or two Button-based calls to action with `label`, `href`, and `variant: primary|secondary`; `tagline` adds a short line below them. If these settings are omitted, the hero receives no additional image or actions. Delete the file to render `page.yaml.title` as a compact visible H1 fallback above the sections; it still receives global `hero.classes` and `hero.background-image`. Sections must be named `NN-name.md`, begin with an `h2`, and may set `tone: default`, `muted`, or `brand` in frontmatter. By default, `ss-section__content` constrains content to a readable width. `fullWidth: true` in section frontmatter removes this inner constraint; the shared outer `site-shell` and Markdown typography remain active. For numbered page and blog sections, `tone` also accepts an object with both `odd` and `even`. Each value is `default`, `muted`, or `brand`. The numeric filename prefix selects the tone, including translated files; it does not depend on the section's position in the page. Scalar tones remain fixed, and omitting `tone` still means `default`. Heroes only accept scalar tones. Use a YAML mapping, not a list:
270
273
 
271
274
  ```yaml
272
275
  tone:
@@ -296,7 +299,11 @@ tagline: A short supporting claim.
296
299
  ---
297
300
  ```
298
301
 
299
- English and German content can be maintained in the same project. Configure `locales: [en, de]` in `site.yaml`, add `site.de.yaml` with German navigation and the same production URL/base, and add translated `page.de.yaml`, `hero.de.md`, and numbered `.de.md`/`.de.mdx` sections. Add `src/pages/de/[...slug].astro` using the same page component and an async `getStaticPaths()` wrapper that calls `getSproutsiteStaticPaths('de')`. Each locale uses its own copy and optional URL segments; translations are not generated automatically. Keep section numbers aligned between languages.
302
+ The default theme accepts an optional `colors` block: `surfaces` (`default`, `muted`, `border`, `text`), semantic roles (`primary`, `secondary`, `accent`, `neutral`, `info`, `success`, `warning`, `error`, each with `color`/`content`), and `brand` (`background`, `backgroundEnd`, `gradient`, `content`, `highlight`, `accent`). Values are opaque hex colours (`#RGB` or `#RRGGBB`); omitted fields retain the theme defaults. For example, `colors: { primary: { color: "#527b37", content: "#ffffff" } }` changes the primary role. Standard solid text/background pairs are checked for contrast against the resolved defaults; invalid fields or insufficient checked contrast stop Astro configuration/rendering. These checks do not establish conformance for image overlays or every component state. SVG waves, logos and images keep their embedded colours and must be edited separately. See the [website colour guide](https://sproutsite.dev/documentation/getting-started/your-website/colors/).
303
+
304
+ `site.yaml` is the shared base. Optional `site.<locale>.yaml` files override individual object fields; arrays replace the entire inherited list. Omitted fields inherit the base values. Production URL, base path, default locale and enabled locale list remain shared. The base `i18n.locale` matches `i18n.defaultLocale`; locale files may set their own `i18n.locale`. The default locale is explicit and does not depend on list order. Legacy `language`/`locales`, `links.externalNewTab`/`externalIcon` and flat blog settings remain readable, but do not mix old and new spellings within a configuration layer.
305
+
306
+ English and German content can be maintained in the same project. Configure `i18n: { locale: en, defaultLocale: en, locales: [en, de] }` in `site.yaml`, add `site.de.yaml` with `i18n.locale: de` and German navigation, and add translated `page.de.yaml`, `hero.de.md`, and numbered `.de.md`/`.de.mdx` sections. Add `src/pages/de/[...slug].astro` using the same page component and an async `getStaticPaths()` wrapper that calls `getSproutsiteStaticPaths('de')`. Each locale uses its own copy and optional URL segments; translations are not generated automatically. Keep section numbers aligned between languages.
300
307
 
301
308
  To deliberately remove global hero classes, use:
302
309
 
@@ -466,7 +473,7 @@ Use `class="ss-link--icon-only"` on links that display only an icon, together wi
466
473
 
467
474
  Any link with `target="_blank"` must include both `noopener` and `noreferrer` in `rel`, even for same-origin destinations. Button and Markdown rendering preserve other relationship tokens while adding these protections. The repository's `npm run build` verifies all generated HTML pages and reports unsafe native anchors with their file and destination. This requirement also applies when automatic external new tabs are disabled and a new tab is explicitly requested.
468
475
 
469
- Theme components use native `<a>` elements. External HTTP(S) links receive `target="_blank"` and `rel="noopener noreferrer"` by default, including Markdown reference/autolinks and header/footer links. Set `links.externalNewTab: false` in `site.yaml` to retain native same-tab behavior for automatically handled links. Explicit Button `target`/`rel` props remain available. External means a different origin from the validated production URL, including in preview builds. Internal/same-origin links, fragments, `mailto:` and `tel:` retain their normal behavior. Links are underlined only on hover. Set `links.externalIcon: true` to add a compact CSS-only Lucide arrow to external, email and telephone links; omission means no arrows. The two settings are independent and both are enabled in this demo's English and German site files. No Link component or browser-side anchor rewriting is needed.
476
+ Theme components use native `<a>` elements. External HTTP(S) links receive `target="_blank"` and `rel="noopener noreferrer"` by default, including Markdown reference/autolinks and header/footer links. Set `links.external.newTab: false` in `site.yaml` to retain native same-tab behavior for automatically handled links. Explicit Button `target`/`rel` props remain available. External means a different origin from the validated production URL, including in preview builds. Internal/same-origin links, fragments, `mailto:` and `tel:` retain their normal behavior. Links are underlined only on hover. Set `links.external.icon: true` to add a compact CSS-only Lucide arrow to external, email and telephone links; omission means no arrows. The two settings are independent and both are enabled in this demo's base configuration and inherited by German. No Link component or browser-side anchor rewriting is needed.
470
477
 
471
478
  `ContentTable` wraps exactly one Markdown table in an MDX section. Its required `caption` becomes a native table caption. Optional props are `variant="plain|striped"`, `density="comfortable|compact"`, a boolean `wide` flag, and a one-based `highlight={2}` body-row index. Keep blank lines between the component tags and Markdown table. Column alignment uses standard Markdown colons. `wide` preserves a minimum table width of 60rem inside a keyboard-focusable horizontal scroll region.
472
479
 
@@ -591,7 +598,7 @@ The dev server deliberately starts with `--force`, so changes to Content Collect
591
598
  The running demo documents itself at `/documentation/` (German: `/de/dokumentation/`): it contains setup, the content contract, layout components, theme, checks, and local package use. The visible [showcase](https://sproutsite.dev/showcase/) instead collects component examples.
592
599
  The [blog](https://sproutsite.dev/blog/) is a small, file-based project journal. Each article lives in a `YYYY-MM-DD.article-slug/` directory in `src/content/blog/` and uses the same `page.yaml`, `hero.md`, and numbered sections as a normal page. `page.yaml` validates the title, description, date, local card image, and alternative text; the date prefix orders source directories while the URL only uses `article-slug`. Astro generates the overview and article routes from the collection, and every section supports the usual tones and documented MDX components.
593
600
 
594
- The optional `blog` setting in `site.yaml` accepts `title`, `eyebrow`, `description`, and `heading` (all non-empty strings) to customize the blog overview. The demo configures English overview copy in `site.yaml` and German copy in `site.de.yaml`. Without this setting, the theme supplies neutral, localized fallback text. Article links use “Learn more” or “Mehr erfahren” and include the article title in their accessible name.
601
+ The optional `blog` setting in `site.yaml` accepts `hero.title`, `hero.eyebrow`, `hero.description`, and `articles.heading` (all non-empty strings) to customize the blog overview. The demo configures English overview copy in `site.yaml` and German copy in `site.de.yaml`. Without this setting, the theme supplies neutral, localized fallback text. Article links use “Learn more” or “Mehr erfahren” and include the article title in their accessible name.
595
602
 
596
603
  English articles use `page.yaml`, `hero.md`, and numbered sections; their German counterparts use `page.de.yaml`, `hero.de.md`, and `.de.mdx` sections in the same article directory. Each pair keeps its publication date, image, and slug; titles, descriptions, alternative text, heroes, and body copy are maintained separately. `/blog/` and `/de/blog/` list their respective language versions. Dates use the site's language and UTC so a date-only publication value does not shift on hosts in another time zone.
597
604
 
@@ -65,9 +65,9 @@ On 2026-11-16, project maintainer Björn Hempel confirmed that the supplied logo
65
65
  | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------- |
66
66
  | `src/themes/default/assets/branding/icon.svg` and the other branding SVGs | Reconstructed and subsequently refined as vector artwork for Sproutsite from the maintainer's AI-created logo reference. `scripts/generate-branding.ts` contains the vector geometry and generation process. | Apache-2.0 under the maintainer's authorization stated above. |
67
67
  | Favicons, app icons, and `social-card.png` in the same branding directory | Generated from the project's vector artwork by `npm run branding:generate`. | Apache-2.0 under the same authorization, including these derived files. |
68
- | `src/themes/default/assets/hero-waves.svg` | The maintainer supplied the AI-created `sproutsite-hero-waves.svg` for integration. The project subsequently adjusted its composition, gradients, and positioning. | Apache-2.0 under the maintainer's authorization stated above. |
68
+ | `public/backgrounds/hero-waves.svg` | The maintainer supplied the AI-created `sproutsite-hero-waves.svg` for integration. The project subsequently adjusted its composition, gradients, and positioning. | Apache-2.0 under the maintainer's authorization stated above. |
69
69
 
70
- All three scopes are included in the npm archive and are covered by the root [LICENSE](LICENSE), with the project's attribution information in [NOTICE](NOTICE). Their use, modification, and redistribution follow Apache-2.0, including its applicable notice requirements. This records the maintainer's provenance statement and license grant; it does not assert exclusive copyright in AI output or independently certify third-party rights. Nunito and all other third-party materials retain their own licenses and applicable notices.
70
+ The bundled branding scopes are included in the npm archive; the hero SVG now lives in the demo's public directory and is excluded from that archive. All three scopes remain covered by the root [LICENSE](LICENSE), with the project's attribution information in [NOTICE](NOTICE). Their use, modification, and redistribution follow Apache-2.0, including its applicable notice requirements. This records the maintainer's provenance statement and license grant; it does not assert exclusive copyright in AI output or independently certify third-party rights. Nunito and all other third-party materials retain their own licenses and applicable notices.
71
71
 
72
72
  Copyright licensing of artwork and trademark rights are separate. Apache-2.0 Section 6 does not grant general trademark rights; this file adds no trademark restrictions or extra attribution obligations.
73
73
 
@@ -104,6 +104,6 @@ The following existing assets do not have a committed, asset-specific rights/pro
104
104
  | PNGs in `src/content/pages/_assets/`, `src/content/pages/showcase/_assets/`, and `src/content/pages/documentation/_assets/` | Committed demo illustrations without an accompanying asset licensing record. | Record the source or generation provenance, relevant terms, and any third-party reference permissions for each illustration. |
105
105
  | PNGs in `src/content/blog/_assets/` | AI-generated editorial illustrations; current prompts and provenance are recorded in `docs/assets/blog-images.md`. | Review applicable generation terms and artwork licensing; the branding authorization above does not automatically license these separate illustrations. |
106
106
 
107
- The branding and hero SVG are included by the current npm file list and their Apache-2.0 authorization is recorded separately above. This authorization does not automatically license all demo illustrations or separate composite artwork incorporating the branding. Demo content images are excluded from the npm archive but remain relevant when publishing the repository's demo website. Removing the package's private flag or passing a packaging check does not itself establish asset rights.
107
+ The bundled branding assets are included by the current npm file list. The configurable hero SVG now belongs to the demo's public/backgrounds/ directory and is excluded from the npm archive. Their Apache-2.0 authorization remains recorded above. This authorization does not automatically license all demo illustrations or separate composite artwork incorporating the branding. Demo content images are excluded from the npm archive but remain relevant when publishing the repository's demo website. Removing the package's private flag or passing a packaging check does not itself establish asset rights.
108
108
 
109
109
  No additional trademark policy, registration claim, or attribution obligation is introduced here. Apache-2.0 Section 6 governs its trademark-license scope; any later artwork licensing decision should be documented explicitly rather than inferred from the software license.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.24
1
+ 0.5.26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sproutsite",
3
- "version": "0.5.24",
3
+ "version": "0.5.26",
4
4
  "license": "Apache-2.0",
5
5
  "author": "Björn Hempel",
6
6
  "description": "Agent-ready, Markdown-first Static CMS powered by Astro and TypeScript.",
@@ -1,18 +1,13 @@
1
- import { readFileSync, realpathSync, statSync } from 'node:fs';
2
- import { extname, relative, resolve, sep } from 'node:path';
3
- import { imageMetadata } from 'astro/assets/utils';
1
+ import { extname } from 'node:path';
4
2
  import { z } from 'zod';
3
+ import {
4
+ publicAssetPath as assetPath,
5
+ publicAssetFile as publicBrandingFile,
6
+ publicImageMetadata as brandingImageMetadata,
7
+ } from './public-assets.js';
8
+ export { brandingImageMetadata };
5
9
 
6
10
  // Paths refer to Astro's standard public directory, without a deployment base.
7
- const assetPath = z.string().refine(
8
- (value) =>
9
- /^\/(?!\/)[A-Za-z0-9_./-]+$/.test(value) &&
10
- value
11
- .slice(1)
12
- .split('/')
13
- .every((part) => part && part !== '.' && part !== '..'),
14
- 'must be a root-relative public file path without a base, query, fragment or traversal',
15
- );
16
11
  const logoSchema = z
17
12
  .object({
18
13
  src: assetPath,
@@ -50,35 +45,6 @@ export const brandingSchema = z
50
45
  export type Branding = z.infer<typeof brandingSchema>;
51
46
  export type BrandLogoConfig = z.infer<typeof logoSchema>;
52
47
 
53
- /** Merge only branding: other locale settings retain their existing contract. */
54
- export function inheritBranding(primary: unknown, localized: unknown): unknown {
55
- if (localized === undefined) return primary;
56
- const record = (value: unknown): value is Record<string, unknown> =>
57
- typeof value === 'object' && value !== null && !Array.isArray(value);
58
- if (!record(primary) || !record(localized)) return localized;
59
- const merged = { ...primary, ...localized };
60
- for (const key of ['logo', 'footerLogo', 'icons', 'sharingImage']) {
61
- if (record(primary[key]) && record(localized[key]))
62
- merged[key] = { ...primary[key], ...localized[key] };
63
- }
64
- return merged;
65
- }
66
-
67
- export function publicBrandingFile(src: string, root = process.cwd()): string {
68
- if (!assetPath.safeParse(src).success)
69
- throw new Error(`Unsafe branding path: ${src}`);
70
- const directory = realpathSync(resolve(root, 'public'));
71
- const file = realpathSync(resolve(directory, `.${src}`));
72
- const within = relative(directory, file);
73
- if (
74
- within.startsWith(`..${sep}`) ||
75
- within === '..' ||
76
- !statSync(file).isFile()
77
- )
78
- throw new Error(`Branding asset must be a file inside public/: ${src}`);
79
- return file;
80
- }
81
-
82
48
  function assets(branding: Branding) {
83
49
  return [
84
50
  ...(['logo', 'footerLogo'] as const).flatMap((key) => {
@@ -147,10 +113,6 @@ export function validateBrandingFiles(
147
113
  }
148
114
  }
149
115
 
150
- export async function brandingImageMetadata(src: string, root = process.cwd()) {
151
- return imageMetadata(readFileSync(publicBrandingFile(src, root)), src);
152
- }
153
-
154
116
  /** Astro's image reader verifies file contents and required app-icon dimensions. */
155
117
  export async function validateBrandingImages(
156
118
  branding: Branding | undefined,
@@ -5,3 +5,27 @@ export function isHexColor(value: unknown): value is `#${string}` {
5
5
  /^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i.test(value)
6
6
  );
7
7
  }
8
+
9
+ /** Relative luminance for opaque, validated sRGB hex colours (WCAG). */
10
+ function luminance(hex: string): number {
11
+ const value =
12
+ hex.length === 4
13
+ ? [...hex.slice(1)].map((digit) => digit + digit).join('')
14
+ : hex.slice(1);
15
+ const channels = [0, 2, 4].map((offset) => {
16
+ const channel =
17
+ Number.parseInt(value.slice(offset, offset + 2), 16) / 255;
18
+ return channel <= 0.04045
19
+ ? channel / 12.92
20
+ : ((channel + 0.055) / 1.055) ** 2.4;
21
+ });
22
+ return (
23
+ channels[0]! * 0.2126 + channels[1]! * 0.7152 + channels[2]! * 0.0722
24
+ );
25
+ }
26
+
27
+ export function contrastRatio(first: string, second: string): number {
28
+ const a = luminance(first);
29
+ const b = luminance(second);
30
+ return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
31
+ }
@@ -0,0 +1,61 @@
1
+ import { extname } from 'node:path';
2
+ import type { ImageMetadata } from 'astro';
3
+ import {
4
+ publicAssetFile,
5
+ publicAssetPath,
6
+ publicImageMetadata,
7
+ } from './public-assets.js';
8
+
9
+ const formats = ['svg', 'png', 'jpg', 'jpeg', 'webp', 'avif'];
10
+ export const publicHeroImage = publicAssetPath.refine(
11
+ (src) => formats.includes(extname(src).slice(1).toLowerCase()),
12
+ 'must be a public SVG, PNG, JPEG, WebP or AVIF image',
13
+ );
14
+
15
+ export type HeroBackground = ImageMetadata | string | null | undefined;
16
+
17
+ export function isSvgHeroImage(image: HeroBackground): boolean {
18
+ return typeof image === 'string'
19
+ ? image.toLowerCase().endsWith('.svg')
20
+ : image?.format === 'svg';
21
+ }
22
+
23
+ /** Undefined inherits; null explicitly disables a global default. */
24
+ export function selectHeroBackground(
25
+ local: HeroBackground,
26
+ global: string | undefined,
27
+ ): HeroBackground {
28
+ return local === undefined ? global : local;
29
+ }
30
+
31
+ export function validateHeroBackground(
32
+ src: string | null | undefined,
33
+ source: string,
34
+ root = process.cwd(),
35
+ ): void {
36
+ if (src == null) return;
37
+ try {
38
+ publicHeroImage.parse(src);
39
+ publicAssetFile(src, root);
40
+ } catch (error) {
41
+ throw new Error(
42
+ `Invalid ${source}: hero.background-image (${src}): ${error instanceof Error ? error.message : String(error)}`,
43
+ );
44
+ }
45
+ }
46
+
47
+ export async function validateHeroBackgroundImage(
48
+ src: string | null | undefined,
49
+ root = process.cwd(),
50
+ ): Promise<void> {
51
+ if (src == null) return;
52
+ const metadata = await publicImageMetadata(src, root);
53
+ const extension = extname(src)
54
+ .slice(1)
55
+ .toLowerCase()
56
+ .replace('jpeg', 'jpg');
57
+ if (metadata.format !== extension)
58
+ throw new Error(
59
+ `Invalid hero.background-image (${src}): image content must match its SVG or raster extension`,
60
+ );
61
+ }
@@ -0,0 +1,33 @@
1
+ import { readFileSync, realpathSync, statSync } from 'node:fs';
2
+ import { relative, resolve, sep } from 'node:path';
3
+ import { imageMetadata } from 'astro/assets/utils';
4
+ import { z } from 'zod';
5
+
6
+ export const publicAssetPath = z.string().refine(
7
+ (value) =>
8
+ /^\/(?!\/)[A-Za-z0-9_./-]+$/.test(value) &&
9
+ value
10
+ .slice(1)
11
+ .split('/')
12
+ .every((part) => part && part !== '.' && part !== '..'),
13
+ 'must be a root-relative public file path without a base, query, fragment or traversal',
14
+ );
15
+
16
+ export function publicAssetFile(src: string, root = process.cwd()): string {
17
+ if (!publicAssetPath.safeParse(src).success)
18
+ throw new Error(`Unsafe public asset path: ${src}`);
19
+ const directory = realpathSync(resolve(root, 'public'));
20
+ const file = realpathSync(resolve(directory, `.${src}`));
21
+ const within = relative(directory, file);
22
+ if (
23
+ within.startsWith(`..${sep}`) ||
24
+ within === '..' ||
25
+ !statSync(file).isFile()
26
+ )
27
+ throw new Error(`Asset must be a file inside public/: ${src}`);
28
+ return file;
29
+ }
30
+
31
+ export async function publicImageMetadata(src: string, root = process.cwd()) {
32
+ return imageMetadata(readFileSync(publicAssetFile(src, root)), src);
33
+ }
@@ -6,12 +6,13 @@ import type { SiteConfig } from './types.js';
6
6
  export function remarkContentLinks(site: SiteConfig) {
7
7
  return (tree: Root, file: { path?: string }) => {
8
8
  const locale =
9
- site.locales.find((language) =>
9
+ site.i18n.locales.find((language) =>
10
10
  ['md', 'mdx'].some((extension) =>
11
11
  file.path?.endsWith(`.${language}.${extension}`),
12
12
  ),
13
- ) ?? site.language;
14
- const documentSite = { ...site, language: locale };
13
+ ) ??
14
+ (site.i18n.locales.includes('en') ? 'en' : site.i18n.defaultLocale);
15
+ const documentSite = { ...site, i18n: { ...site.i18n, locale } };
15
16
  visit(tree, 'link', (node) => {
16
17
  node.url = contentHref(node.url, documentSite);
17
18
  });
@@ -0,0 +1,47 @@
1
+ import { z } from 'zod';
2
+
3
+ /** Opaque colours keep palette contrast predictable; components retain their own API. */
4
+ const hex = z
5
+ .string()
6
+ .regex(
7
+ /^#(?:[\da-f]{3}|[\da-f]{6})$/i,
8
+ 'must be an opaque hex colour (#RGB or #RRGGBB)',
9
+ );
10
+ const pair = z
11
+ .object({ color: hex.optional(), content: hex.optional() })
12
+ .strict();
13
+
14
+ export const siteColorsSchema = z
15
+ .object({
16
+ surfaces: z
17
+ .object({
18
+ default: hex.optional(),
19
+ muted: hex.optional(),
20
+ border: hex.optional(),
21
+ text: hex.optional(),
22
+ })
23
+ .strict()
24
+ .optional(),
25
+ primary: pair.optional(),
26
+ secondary: pair.optional(),
27
+ accent: pair.optional(),
28
+ neutral: pair.optional(),
29
+ info: pair.optional(),
30
+ success: pair.optional(),
31
+ warning: pair.optional(),
32
+ error: pair.optional(),
33
+ brand: z
34
+ .object({
35
+ background: hex.optional(),
36
+ backgroundEnd: hex.optional(),
37
+ gradient: hex.optional(),
38
+ content: hex.optional(),
39
+ highlight: hex.optional(),
40
+ accent: hex.optional(),
41
+ })
42
+ .strict()
43
+ .optional(),
44
+ })
45
+ .strict();
46
+
47
+ export type SiteColors = z.infer<typeof siteColorsSchema>;