sproutsite 0.5.24 → 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 +11 -6
- package/THIRD_PARTY_NOTICES.md +3 -3
- package/VERSION +1 -1
- package/package.json +1 -1
- package/src/lib/sproutsite/branding.ts +7 -45
- 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 +209 -38
- package/src/lib/sproutsite/sitemap.ts +2 -2
- package/src/lib/sproutsite/types.ts +5 -9
- package/src/lib/sproutsite/urls.ts +3 -3
- package/src/lib/sproutsite/validation.ts +4 -1
- package/src/package/config.ts +17 -9
- package/src/package/content.ts +25 -1
- package/src/package/manifest.ts +1 -1
- package/src/package/page.astro +6 -3
- package/src/package/starter-assets/README.md +6 -3
- 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 +1 -1
- package/src/themes/default/components/organisms/Header/Header.astro +2 -2
- 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 +3 -3
- package/src/themes/default/styles/theme.css +1 -0
- 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
|
|
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,9 @@ tagline: A short supporting claim.
|
|
|
296
299
|
---
|
|
297
300
|
```
|
|
298
301
|
|
|
299
|
-
|
|
302
|
+
`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.
|
|
303
|
+
|
|
304
|
+
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
305
|
|
|
301
306
|
To deliberately remove global hero classes, use:
|
|
302
307
|
|
|
@@ -466,7 +471,7 @@ Use `class="ss-link--icon-only"` on links that display only an icon, together wi
|
|
|
466
471
|
|
|
467
472
|
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
473
|
|
|
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.
|
|
474
|
+
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
475
|
|
|
471
476
|
`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
477
|
|
|
@@ -591,7 +596,7 @@ The dev server deliberately starts with `--force`, so changes to Content Collect
|
|
|
591
596
|
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
597
|
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
598
|
|
|
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.
|
|
599
|
+
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
600
|
|
|
596
601
|
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
602
|
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -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
|
-
| `
|
|
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
|
-
|
|
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
|
|
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.
|
|
1
|
+
0.5.25
|
package/package.json
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import {
|
|
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,
|
|
@@ -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
|
-
) ??
|
|
14
|
-
|
|
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
|
});
|
|
@@ -1,13 +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 {
|
|
7
|
-
|
|
8
|
-
inheritBranding,
|
|
9
|
-
validateBrandingFiles,
|
|
10
|
-
} from './branding.js';
|
|
6
|
+
import { publicHeroImage, validateHeroBackground } from './hero-background.js';
|
|
7
|
+
import { brandingSchema, validateBrandingFiles } from './branding.js';
|
|
11
8
|
|
|
12
9
|
const linkSchema = z.object({
|
|
13
10
|
label: z.string().trim().min(1),
|
|
@@ -75,8 +72,13 @@ const siteSchema = z.object({
|
|
|
75
72
|
}),
|
|
76
73
|
links: z
|
|
77
74
|
.object({
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
external: z
|
|
76
|
+
.object({
|
|
77
|
+
newTab: z.boolean().optional(),
|
|
78
|
+
icon: z.boolean().optional(),
|
|
79
|
+
})
|
|
80
|
+
.strict()
|
|
81
|
+
.optional(),
|
|
80
82
|
})
|
|
81
83
|
.strict()
|
|
82
84
|
.optional(),
|
|
@@ -85,21 +87,52 @@ const siteSchema = z.object({
|
|
|
85
87
|
base: z
|
|
86
88
|
.string()
|
|
87
89
|
.regex(/^\/(?:[^/].*)?\/$|^\/$/, 'must be / or begin and end with /'),
|
|
88
|
-
|
|
89
|
-
.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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: [] }),
|
|
96
124
|
blog: z
|
|
97
125
|
.object({
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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(),
|
|
102
134
|
})
|
|
135
|
+
.strict()
|
|
103
136
|
.optional(),
|
|
104
137
|
header: z.object({
|
|
105
138
|
links: z
|
|
@@ -172,32 +205,170 @@ const siteSchema = z.object({
|
|
|
172
205
|
}),
|
|
173
206
|
});
|
|
174
207
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
+
}
|
|
183
268
|
if (
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
raw !== null &&
|
|
187
|
-
!Array.isArray(raw)
|
|
269
|
+
record(result.links) &&
|
|
270
|
+
('externalNewTab' in result.links || 'externalIcon' in result.links)
|
|
188
271
|
) {
|
|
189
|
-
const
|
|
190
|
-
|
|
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
|
+
};
|
|
191
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 {
|
|
192
313
|
const parsed = siteSchema.safeParse(raw);
|
|
193
|
-
if (!parsed.success)
|
|
314
|
+
if (!parsed.success)
|
|
194
315
|
throw new Error(
|
|
195
316
|
`Invalid src/content/${filename}: ${parsed.error.issues.map((issue) => `${issue.path.join('.')}: ${issue.message}`).join('; ')}`,
|
|
196
317
|
);
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
318
|
+
const config = parsed.data;
|
|
319
|
+
validateHeroBackground(
|
|
320
|
+
config.hero['background-image'],
|
|
321
|
+
`src/content/${filename}`,
|
|
322
|
+
root,
|
|
323
|
+
);
|
|
200
324
|
validateBrandingFiles(config.branding, root, `src/content/${filename}`);
|
|
325
|
+
return config;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export function loadSiteConfig(
|
|
329
|
+
locale?: string,
|
|
330
|
+
root = process.cwd(),
|
|
331
|
+
): SiteConfig {
|
|
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)
|
|
335
|
+
throw new Error(
|
|
336
|
+
'Invalid src/content/site.yaml: i18n.locale must match i18n.defaultLocale in the base configuration',
|
|
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
|
+
);
|
|
371
|
+
}
|
|
201
372
|
const environmentBase = process.env.SPROUTSITE_BASE;
|
|
202
373
|
if (environmentBase === undefined) return config;
|
|
203
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 });
|
|
@@ -34,22 +34,18 @@ export interface SiteConfig {
|
|
|
34
34
|
name: string;
|
|
35
35
|
url: string;
|
|
36
36
|
base: string;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
heroClasses: string[];
|
|
37
|
+
i18n: { locale: string; defaultLocale: string; locales: string[] };
|
|
38
|
+
hero: { classes: string[]; 'background-image'?: string };
|
|
40
39
|
typography: {
|
|
41
40
|
headings: { family: 'serif' | 'sans-serif'; weight: number };
|
|
42
41
|
eyebrow: { family: 'serif' | 'sans-serif'; weight: number };
|
|
43
42
|
};
|
|
44
43
|
links?: {
|
|
45
|
-
|
|
46
|
-
externalIcon?: boolean;
|
|
44
|
+
external?: { newTab?: boolean; icon?: boolean };
|
|
47
45
|
};
|
|
48
46
|
blog?: {
|
|
49
|
-
title: string;
|
|
50
|
-
|
|
51
|
-
eyebrow: string;
|
|
52
|
-
heading: string;
|
|
47
|
+
hero: { title: string; description: string; eyebrow: string };
|
|
48
|
+
articles: { heading: string };
|
|
53
49
|
};
|
|
54
50
|
header: { links: HeaderItem[] };
|
|
55
51
|
footer: {
|