@eldrajs/theme-core 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,38 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
5
5
|
|
|
6
6
|
## Unreleased
|
|
7
7
|
|
|
8
|
+
- **`buildToken` client option (WS-403).** `createEldraClient({ buildToken })` sends
|
|
9
|
+
`X-Eldra-Build-Token` on every read; pass a read-only build token (`eldra_bld_…`, Studio →
|
|
10
|
+
Settings → Developers → Build tokens), never the deploy token. Server and build only.
|
|
11
|
+
|
|
12
|
+
- **`createAnalytics`, `normalizeAnalyticsProps`, `truncateUtf8`.** Framework-free custom-event layer
|
|
13
|
+
over the Eldra tracker's `window.eldra('event', ...)`: props stringified and cut to the platform's
|
|
14
|
+
limits, events queued (50) until the script loads, a no-op when disabled, `pageview` rejected.
|
|
15
|
+
Behind `useEldraAnalytics` in `@eldrajs/theme-nuxt`.
|
|
16
|
+
|
|
17
|
+
- New framework-free schema.org JSON-LD builders: `buildProductLd` (`Offer`, or `AggregateOffer` for
|
|
18
|
+
variants at different prices; price rounded to the currency's own fraction digits, list price from
|
|
19
|
+
`compareAt`, GTIN only when valid), `buildBreadcrumbLd`, `buildItemListLd`, `buildOrganizationLd`,
|
|
20
|
+
`buildWebSiteLd` (with a `SearchAction` when given a search path) and `serializeLd` (escapes `<`
|
|
21
|
+
and the two line separators so a value cannot close the script tag), plus `validGtin`, `ldPrice`,
|
|
22
|
+
`ldPlainText` and `applyStructuredDataPolicy` (the opt-out and extender `@eldrajs/theme-nuxt`
|
|
23
|
+
applies). Empty values are omitted, never written. Documented in `docs/theme-seo.md`.
|
|
24
|
+
- New framework-free `buildSitemap` (a `urlset`, or a `sitemapindex` with children past the
|
|
25
|
+
sitemaps.org limits; hreflang `xhtml:link` alternates and `x-default`; noindex pages excluded; a
|
|
26
|
+
same-origin canonical as `loc`), `buildRobots` (preview: `Disallow: /`; production: `Allow: /`,
|
|
27
|
+
merchant lines, `Sitemap:`), `buildAlternates` (the head's hreflang set) and their helpers
|
|
28
|
+
(`siteOrigin`, `sitemapLastmod`, `escapeXml`). `@eldrajs/theme-nuxt` feeds them the prerendered
|
|
29
|
+
routes. Documented in `docs/theme-seo.md`.
|
|
30
|
+
|
|
31
|
+
- New framework-free SEO resolver, `resolveSeo` (and `substituteSeoPattern`, `tidySeoTitle`,
|
|
32
|
+
`renderSeoTitle`, `pickSeoLocale`, the `SeoSetting`/`SeoEntryValue`/`ResolvedSeo` types):
|
|
33
|
+
title, description, share image, canonical, `noindex`, `og:type` and Twitter handle for one route
|
|
34
|
+
from the entry's own `seo` value, the route template's pattern, the site's pattern and the page's
|
|
35
|
+
own title, in that order. `{{dot.path}}` substitution is a single pass, an unknown or empty
|
|
36
|
+
variable becomes empty (never literal braces), and a separator left dangling by an empty variable
|
|
37
|
+
is dropped. Studio's previews run the same function; `src/__tests__/fixtures/seo-vectors.json`
|
|
38
|
+
is the vector file shared with Core and Studio. Documented in `docs/theme-seo.md`.
|
|
39
|
+
|
|
8
40
|
- New `themeId` helpers, framework-free: `blockApiIdOf(schemaApiId, themeId)` (the wire spelling
|
|
9
41
|
`<themeId>:<apiId>` to the bare block id, stripping only the given theme's own prefix, so
|
|
10
42
|
`catalog:product` and another theme's `starter:hero` pass through) and
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ColorLiteral, ColorSelection, ContainerOverride, ContainerPreset, CssTo
|
|
|
2
2
|
import { a as buildDynamicRoutePath, c as parseDynamicRoutePattern, d as resolvePagePath, i as RouteTemplateLike, l as resolveRoute, n as MAX_DYNAMIC_ROUTE_PATTERN_BYTES, o as catalogRouteTarget, r as ParsedDynamicRoutePattern, s as matchDynamicRoutePattern, t as DynamicRouteResolution, u as PageLike } from "./dynamicRoute-pRTBoYT6.js";
|
|
3
3
|
import { a as ImageFraming, c as focalBand, d as imageFramingAttrs, f as imageFramingStyle, h as unscaledFrameRect, i as IMAGE_FRAMING_MIN_ZOOM, l as framingDrag, m as parseImageFramingValueAttr, n as FrameRect, o as clampFocal, p as normalizeImageFraming, r as IMAGE_FRAMING_MAX_ZOOM, s as clampImageFraming, t as DEFAULT_IMAGE_FRAMING, u as framingZoom } from "./imageFraming-BUZ-yqho.js";
|
|
4
4
|
import { StegaMeta, decodeStega, encodeStega, stripStega } from "./stega.js";
|
|
5
|
-
import { C as ResolveEntryListBody, S as PageMeta, _ as EldraClientOptions, a as TemplateLayoutDocument, b as EntryList, c as TemplateLayoutRenderNode, d as CatalogDoc, f as CatalogList, g as EldraClientError, h as EldraClient, i as TemplateLayoutContext, l as buildTemplateBlockRenames, m as EldraCatalogReader, n as TemplateBlockFieldDefinition, o as TemplateLayoutNode, p as CatalogQuery, r as TemplateBlockNode, s as TemplateLayoutRenderModel, t as TemplateBlockDefinition, u as createTemplateLayoutRenderModel, v as EldraRetryOptions, x as EntryQuery, y as EntryDoc } from "./templateLayout-
|
|
5
|
+
import { C as ResolveEntryListBody, S as PageMeta, _ as EldraClientOptions, a as TemplateLayoutDocument, b as EntryList, c as TemplateLayoutRenderNode, d as CatalogDoc, f as CatalogList, g as EldraClientError, h as EldraClient, i as TemplateLayoutContext, l as buildTemplateBlockRenames, m as EldraCatalogReader, n as TemplateBlockFieldDefinition, o as TemplateLayoutNode, p as CatalogQuery, r as TemplateBlockNode, s as TemplateLayoutRenderModel, t as TemplateBlockDefinition, u as createTemplateLayoutRenderModel, v as EldraRetryOptions, x as EntryQuery, y as EntryDoc } from "./templateLayout-7rT_TH_E.js";
|
|
6
6
|
import { A as generateLayoutCss, C as Responsive, D as WidthLength, E as Spacing, F as resolveLayoutBreakpoints, I as resolveLayoutDocument, L as validateLayoutDocument, M as layoutNodeClass, N as layoutRenderNodeId, O as activeLayoutBreakpoint, P as normalizeLayoutDocument, S as ResolvedLayoutStyle, T as SlotValidationContext, _ as LayoutValidationError, a as LAYOUT_BREAKPOINTS, b as ResolvedLayoutDocument, c as LayoutBreakpoints, d as LayoutNode, f as LayoutRenderBlockNode, g as LayoutValidationCode, h as LayoutStyle, i as EDIT_MODE_HIDDEN_OPACITY, j as hiddenLayoutBreakpoints, k as createLayoutRenderModel, l as LayoutContainerNode, m as LayoutRenderNode, n as CssLength, o as LayoutBlockNode, p as LayoutRenderModel, r as DEFAULT_LAYOUT_BREAKPOINTS, s as LayoutBreakpoint, t as BlockSlotDefinition, u as LayoutDocument, v as LayoutValidationIssue, w as SizingLength, x as ResolvedLayoutNode, y as NormalizedLayoutResult } from "./layout-CWq_v6ws.js";
|
|
7
7
|
import { a as RichTextRenderStateChange, c as NegotiatedEditorCapabilities, d as PreviewRouterMessageType, f as createPreviewMessageRouter, i as RichTextFieldIdentity, l as PREVIEW_ROUTER_MESSAGE_TYPES, n as OverlayRuntime, o as classifyBeforeInput, r as OverlayRuntimeOptions, s as createOverlayRuntime, t as BeforeInputClassification, u as PreviewMessageRouter } from "./overlay-Bgi0tIbN.js";
|
|
8
8
|
import { a as ReusableComponentRevision, i as ReusableComponentResolver, n as ReusableComponentPlacement, o as ReusableRenderIdentity, r as ReusableComponentProjection, s as createProjectionResolver, t as ReusableComponentBinding } from "./reusableExpansion-CXvs_ckx.js";
|
|
@@ -10,6 +10,58 @@ import { PageLayoutDocument, PageLayoutNode, ReusableComponentSnapshotCache, Reu
|
|
|
10
10
|
//#region src/client.d.ts
|
|
11
11
|
export declare function createEldraClient(opts: EldraClientOptions): EldraClient;
|
|
12
12
|
//#endregion
|
|
13
|
+
//#region src/analytics.d.ts
|
|
14
|
+
/**
|
|
15
|
+
* Framework-free custom-event tracking for the Eldra analytics tracker script
|
|
16
|
+
* (`<gateway>/js/script.js`, see `analyticsTrackerScript` in `@eldrajs/sdk`).
|
|
17
|
+
*
|
|
18
|
+
* The script owns pageviews (including SPA navigations, by patching `history`) and exposes
|
|
19
|
+
* `window.eldra('event', name, { props })` for everything else. This module is the thin, testable
|
|
20
|
+
* layer a theme calls instead of reaching for that global: it coerces props to the string-only
|
|
21
|
+
* shape Core accepts, stays inside Core's limits, holds events until the script has loaded, and is
|
|
22
|
+
* a no-op wherever tracking is off (disabled, a Studio preview frame, the server).
|
|
23
|
+
*
|
|
24
|
+
* Nothing here reads or writes a cookie or storage: the visitor is a salted daily hash computed by
|
|
25
|
+
* the platform, never an identifier kept in the browser.
|
|
26
|
+
*/
|
|
27
|
+
/** A prop value a theme may pass; stringified (and `null`/`undefined` dropped) before sending. */
|
|
28
|
+
export type AnalyticsPropValue = string | number | boolean | null | undefined;
|
|
29
|
+
export type AnalyticsProps = Record<string, AnalyticsPropValue>;
|
|
30
|
+
/** Core's ingest limits (`SanitizeProps`): 30 entries, keys up to 60 bytes, values 300 bytes. */
|
|
31
|
+
export declare const ANALYTICS_MAX_PROPS = 30;
|
|
32
|
+
export declare const ANALYTICS_MAX_KEY_BYTES = 60;
|
|
33
|
+
export declare const ANALYTICS_MAX_VALUE_BYTES = 300;
|
|
34
|
+
/** Core cuts an event name at 120 bytes. */
|
|
35
|
+
export declare const ANALYTICS_MAX_NAME_BYTES = 120;
|
|
36
|
+
/** Events held back before the tracker script has loaded; the oldest are dropped past this. */
|
|
37
|
+
export declare const ANALYTICS_QUEUE_LIMIT = 50;
|
|
38
|
+
/** The tracker script's global, as `script.js` installs it. */
|
|
39
|
+
export type AnalyticsSender = (command: 'event', name: string, options?: {
|
|
40
|
+
props?: Record<string, string>;
|
|
41
|
+
}) => void;
|
|
42
|
+
export interface Analytics {
|
|
43
|
+
/** Whether events are sent at all. `false` makes `track` a no-op. */
|
|
44
|
+
readonly enabled: boolean;
|
|
45
|
+
/** Records a named event. Never throws; a failed send is dropped. */
|
|
46
|
+
track(name: string, props?: AnalyticsProps): void;
|
|
47
|
+
/** Sends everything queued while the script was loading. Call once the script has loaded. */
|
|
48
|
+
flush(): void;
|
|
49
|
+
}
|
|
50
|
+
export interface CreateAnalyticsOptions {
|
|
51
|
+
/** `false` for the server, a preview frame, a dev server or a site that opted out. */
|
|
52
|
+
enabled: boolean;
|
|
53
|
+
/** Resolves the tracker's global; `undefined` until the script has loaded. */
|
|
54
|
+
sender: () => AnalyticsSender | undefined;
|
|
55
|
+
}
|
|
56
|
+
/** Cuts a string to at most `maxBytes` of UTF-8 without splitting a character. */
|
|
57
|
+
export declare function truncateUtf8(value: string, maxBytes: number): string;
|
|
58
|
+
/**
|
|
59
|
+
* Coerces a theme's props to what Core stores: strings only, `null`/`undefined`/non-finite numbers
|
|
60
|
+
* dropped, keys and values cut to the ingest limits, at most 30 entries.
|
|
61
|
+
*/
|
|
62
|
+
export declare function normalizeAnalyticsProps(props: AnalyticsProps | undefined): Record<string, string>;
|
|
63
|
+
export declare function createAnalytics(options: CreateAnalyticsOptions): Analytics;
|
|
64
|
+
//#endregion
|
|
13
65
|
//#region src/stegaWalk.d.ts
|
|
14
66
|
/**
|
|
15
67
|
* Projects a complete localized CMS draft into the active-locale shape used
|
|
@@ -446,4 +498,347 @@ export declare function registerThemeId(themeId: string | undefined): void;
|
|
|
446
498
|
/** The registered theme id, if the app registered one. */
|
|
447
499
|
export declare function getRegisteredThemeId(): string | undefined;
|
|
448
500
|
//#endregion
|
|
501
|
+
//#region src/seo.d.ts
|
|
502
|
+
/**
|
|
503
|
+
* The page-title and SEO-metadata resolver. Framework-free: the theme's `useEldraSeo`
|
|
504
|
+
* (`@eldrajs/theme-nuxt`) feeds it, and Studio's search-result and share-card previews run the
|
|
505
|
+
* very same function, so what the merchant sees is what the build writes.
|
|
506
|
+
*
|
|
507
|
+
* The rules are the platform's contract (`__tests__/fixtures/seo-vectors.json` is shared with
|
|
508
|
+
* Core and Studio):
|
|
509
|
+
*
|
|
510
|
+
* - Precedence, per field: the entry's own `seo` value, then the route template's pattern for this
|
|
511
|
+
* context, then the site's pattern, then the page's own title.
|
|
512
|
+
* - A pattern is `{{dot.path}}` over scalars (`"syntax": 1`). Substitution is **one pass** over the
|
|
513
|
+
* pattern: a substituted value is never scanned again, so a product called `{{site.name}}` shows
|
|
514
|
+
* those characters. An unknown or empty variable becomes `''`, never literal braces (unlike the
|
|
515
|
+
* email renderer, which keeps unknown paths and swallows nearby whitespace and punctuation).
|
|
516
|
+
* - Titles are tidied afterwards: whitespace collapsed, and a separator (`· | – — -`, standing
|
|
517
|
+
* alone between spaces) left leading, trailing or doubled by an empty variable is dropped.
|
|
518
|
+
*/
|
|
519
|
+
/** The contexts a pattern can be written for; they decide which variables exist. */
|
|
520
|
+
export type SeoContext = 'page' | 'home' | 'catalog:product' | 'catalog:collection' | 'catalog:category';
|
|
521
|
+
/** The only pattern syntax version this resolver understands. */
|
|
522
|
+
export declare const SEO_SYNTAX = 1;
|
|
523
|
+
/** A string per locale, keyed by the site's locale tags. */
|
|
524
|
+
export type SeoLocaleMap = Record<string, string>;
|
|
525
|
+
/** `GET /site/v1/seo` exactly as the platform answers it. */
|
|
526
|
+
export interface SeoSetting {
|
|
527
|
+
revision: number;
|
|
528
|
+
syntax: number;
|
|
529
|
+
site: {
|
|
530
|
+
/** `null`: use the site's own name (the theme's). */
|
|
531
|
+
name: string | null;
|
|
532
|
+
titlePattern: SeoLocaleMap;
|
|
533
|
+
description: SeoLocaleMap;
|
|
534
|
+
imageAssetId: string | null;
|
|
535
|
+
/** The media worker's 1200x630 rendering, absolute, or `null`. */
|
|
536
|
+
imageUrl: string | null;
|
|
537
|
+
twitterHandle: string | null;
|
|
538
|
+
};
|
|
539
|
+
/** Per-context patterns (`catalog:product`, ...). A context with none inherits the site's. */
|
|
540
|
+
templates: Record<string, {
|
|
541
|
+
titlePattern?: SeoLocaleMap;
|
|
542
|
+
descriptionPattern?: SeoLocaleMap;
|
|
543
|
+
}>;
|
|
544
|
+
}
|
|
545
|
+
/** A page's or template's own `seo` field value. Each string may also be a per-locale map. */
|
|
546
|
+
export interface SeoEntryValue {
|
|
547
|
+
title?: string | SeoLocaleMap | null;
|
|
548
|
+
description?: string | SeoLocaleMap | null;
|
|
549
|
+
canonicalUrl?: string | SeoLocaleMap | null;
|
|
550
|
+
/** Open Graph title and description overrides; each falls back to the page's title and description. */
|
|
551
|
+
ogTitle?: string | SeoLocaleMap | null;
|
|
552
|
+
ogDescription?: string | SeoLocaleMap | null;
|
|
553
|
+
/** The share image's asset id; Core resolves it to `imageUrl` in the public entry read. */
|
|
554
|
+
imageAssetId?: string | null;
|
|
555
|
+
/**
|
|
556
|
+
* The share image's media URL: the resolved rendering of `imageAssetId` (as Core serves for the
|
|
557
|
+
* site's own image). The resolver reads only the URL.
|
|
558
|
+
*/
|
|
559
|
+
imageUrl?: string | null;
|
|
560
|
+
noindex?: boolean | null;
|
|
561
|
+
}
|
|
562
|
+
/** Variables by path: nested (`{ page: { title } }`) or flat (`{ 'page.title': ... }`). */
|
|
563
|
+
export type SeoData = Record<string, unknown>;
|
|
564
|
+
export interface ResolveSeoInput {
|
|
565
|
+
/** The locale being rendered (`en-US`). */
|
|
566
|
+
locale: string | null;
|
|
567
|
+
/** The locale served at `/`; the last fallback when a map has no entry for `locale`. */
|
|
568
|
+
defaultLocale?: string | null;
|
|
569
|
+
context: SeoContext;
|
|
570
|
+
/** The platform's setting, or `null` (unset, or the read failed). */
|
|
571
|
+
site: SeoSetting | null;
|
|
572
|
+
/** The site's own name, used when the setting names none. */
|
|
573
|
+
siteName?: string | null;
|
|
574
|
+
/** The site's origin (`https://shop.example`); without it no canonical or absolute image exists. */
|
|
575
|
+
siteUrl?: string | null;
|
|
576
|
+
/** The route's path, with its locale prefix, as it is served. */
|
|
577
|
+
path?: string | null;
|
|
578
|
+
/** The page's or template's own `seo` field value. */
|
|
579
|
+
entry?: SeoEntryValue | null;
|
|
580
|
+
/** The route template's `seo` field value, when the route renders through one. */
|
|
581
|
+
template?: SeoEntryValue | null;
|
|
582
|
+
/**
|
|
583
|
+
* The context's variables (`page.title`, `product.name`, ...). `site.*` is filled in here and
|
|
584
|
+
* wins over anything supplied under that name.
|
|
585
|
+
*/
|
|
586
|
+
data?: SeoData;
|
|
587
|
+
/** The image the content itself offers (a product's first image); used after the entry's own. */
|
|
588
|
+
contentImage?: string | null;
|
|
589
|
+
/** A preview build: robots is `noindex` whatever the content says. */
|
|
590
|
+
isPreview?: boolean;
|
|
591
|
+
}
|
|
592
|
+
export interface ResolvedSeo {
|
|
593
|
+
title: string;
|
|
594
|
+
description: string;
|
|
595
|
+
/** The Open Graph title: the entry's or template's `ogTitle`, else `title`. */
|
|
596
|
+
ogTitle: string;
|
|
597
|
+
/** The Open Graph description: the entry's or template's `ogDescription`, else `description`. */
|
|
598
|
+
ogDescription: string;
|
|
599
|
+
/** Absolute image URL, or `null`. */
|
|
600
|
+
image: string | null;
|
|
601
|
+
/** Absolute canonical URL, or `null` when no site origin is known. */
|
|
602
|
+
canonical: string | null;
|
|
603
|
+
noindex: boolean;
|
|
604
|
+
ogType: 'website' | 'product';
|
|
605
|
+
/** `@handle` form, or `null`. */
|
|
606
|
+
twitterSite: string | null;
|
|
607
|
+
}
|
|
608
|
+
/** The title pattern used when neither the context nor the site sets one. */
|
|
609
|
+
export declare const DEFAULT_TITLE_PATTERN = "{{page.title}} · {{site.name}}";
|
|
610
|
+
/** The home page's default: the site's name alone. */
|
|
611
|
+
export declare const DEFAULT_HOME_TITLE_PATTERN = "{{site.name}}";
|
|
612
|
+
/** One pass of `{{path}}` substitution; unknown and empty values become `''`. No tidying. */
|
|
613
|
+
export declare function substituteSeoPattern(pattern: string, data: SeoData): string;
|
|
614
|
+
/** Collapses whitespace and drops leading, trailing and doubled separators. */
|
|
615
|
+
export declare function tidySeoTitle(value: string): string;
|
|
616
|
+
/** Substitutes, then tidies: the title rule the shared vectors pin down. */
|
|
617
|
+
export declare function renderSeoTitle(pattern: string, data: SeoData): string;
|
|
618
|
+
/**
|
|
619
|
+
* One locale's string out of a string or a locale map: the exact tag, the same language, the
|
|
620
|
+
* default locale, then `''`.
|
|
621
|
+
*/
|
|
622
|
+
export declare function pickSeoLocale(value: string | SeoLocaleMap | null | undefined, locale: string | null, defaultLocale?: string | null): string;
|
|
623
|
+
/** Resolves every SEO value one route needs. Pure; never throws on malformed content. */
|
|
624
|
+
export declare function resolveSeo(input: ResolveSeoInput): ResolvedSeo;
|
|
625
|
+
//#endregion
|
|
626
|
+
//#region src/sitemap.d.ts
|
|
627
|
+
/**
|
|
628
|
+
* `sitemap.xml` and `robots.txt` for a static build. Framework-free and pure: the theme-nuxt
|
|
629
|
+
* module feeds it the prerendered route list, a test reads every byte without a Nuxt app.
|
|
630
|
+
*
|
|
631
|
+
* Why the input is already fanned out per locale: which paths exist under which locale prefix is
|
|
632
|
+
* the module's routing (`localePathFor`), not this file's. A page is one entry holding one
|
|
633
|
+
* `variant` per locale it is served in, and every variant lists its siblings as
|
|
634
|
+
* `xhtml:link rel="alternate" hreflang` (plus `x-default`), which is what tells a search engine
|
|
635
|
+
* the URLs are one page in several languages.
|
|
636
|
+
*/
|
|
637
|
+
/** One URL of a page: the page as it is spelled under one locale. */
|
|
638
|
+
export interface SitemapVariant {
|
|
639
|
+
/** The locale tag written as `hreflang`; `null` on a site with no locales. */
|
|
640
|
+
locale: string | null;
|
|
641
|
+
/** The served path, with its locale prefix (`/en-US/about`). */
|
|
642
|
+
path: string;
|
|
643
|
+
/** The page's own canonical URL for this variant, when it has one. */
|
|
644
|
+
canonical?: string | null;
|
|
645
|
+
/** The variant served at `/`: what `x-default` points at. */
|
|
646
|
+
isDefault?: boolean;
|
|
647
|
+
}
|
|
648
|
+
export interface SitemapPage {
|
|
649
|
+
variants: readonly SitemapVariant[];
|
|
650
|
+
/** When the content last changed: an ISO string or a `Date`. Anything unparsable is omitted. */
|
|
651
|
+
lastmod?: string | Date | null;
|
|
652
|
+
/** A `noindex` page is left out of the sitemap altogether. */
|
|
653
|
+
noindex?: boolean;
|
|
654
|
+
}
|
|
655
|
+
export interface SitemapLimits {
|
|
656
|
+
/** sitemaps.org: 50,000 URLs per file. */
|
|
657
|
+
maxUrls?: number;
|
|
658
|
+
/** sitemaps.org: 50 MiB uncompressed per file. */
|
|
659
|
+
maxBytes?: number;
|
|
660
|
+
}
|
|
661
|
+
export interface SitemapFile {
|
|
662
|
+
/** The file name inside the site root: `sitemap.xml`, `sitemap-1.xml`, ... */
|
|
663
|
+
name: string;
|
|
664
|
+
xml: string;
|
|
665
|
+
}
|
|
666
|
+
export declare const SITEMAP_MAX_URLS = 50000;
|
|
667
|
+
export declare const SITEMAP_MAX_BYTES = 52428800;
|
|
668
|
+
/** The absolute origin of `siteUrl` (`https://shop.example`, no trailing slash), or `null`. */
|
|
669
|
+
export declare function siteOrigin(siteUrl: string | null | undefined): string | null;
|
|
670
|
+
export declare function escapeXml(value: string): string;
|
|
671
|
+
/** A W3C datetime (`2026-01-02T03:04:05.000Z`), or `null` for anything that is not a date. */
|
|
672
|
+
export declare function sitemapLastmod(value: string | Date | null | undefined): string | null;
|
|
673
|
+
/**
|
|
674
|
+
* The sitemap files for `pages`: one `sitemap.xml` (a `urlset`), or, when the URLs do not fit the
|
|
675
|
+
* limits, a `sitemap.xml` that is a `sitemapindex` over `sitemap-1.xml`, `sitemap-2.xml`, ...
|
|
676
|
+
*
|
|
677
|
+
* Empty when `siteUrl` is not an absolute http(s) URL (a sitemap of relative URLs is invalid) and
|
|
678
|
+
* when no page is indexable.
|
|
679
|
+
*/
|
|
680
|
+
export declare function buildSitemap(input: {
|
|
681
|
+
pages: readonly SitemapPage[];
|
|
682
|
+
siteUrl: string | null | undefined;
|
|
683
|
+
limits?: SitemapLimits;
|
|
684
|
+
}): SitemapFile[];
|
|
685
|
+
/**
|
|
686
|
+
* The `robots.txt` body.
|
|
687
|
+
*
|
|
688
|
+
* A **preview** build disallows everything and names no sitemap. A production build allows
|
|
689
|
+
* everything, adds the merchant's own lines (`extra`), and names the sitemap when there is one.
|
|
690
|
+
* `extra` is untrusted text: control characters are dropped, every line is trimmed, and a line
|
|
691
|
+
* that opens a second `User-agent` group is kept as the merchant wrote it (that is the point of
|
|
692
|
+
* the field), after the platform's group.
|
|
693
|
+
*/
|
|
694
|
+
export declare function buildRobots(input: {
|
|
695
|
+
target: 'production' | 'preview';
|
|
696
|
+
siteUrl?: string | null;
|
|
697
|
+
extra?: string | null;
|
|
698
|
+
/** Name `<origin>/sitemap.xml`; only honoured in production with an absolute `siteUrl`. */
|
|
699
|
+
sitemap?: boolean;
|
|
700
|
+
}): string;
|
|
701
|
+
/**
|
|
702
|
+
* The `<link rel="alternate" hreflang>` set for one page, for the head: one per locale plus
|
|
703
|
+
* `x-default`. `pathFor(locale)` spells the page under that locale (`undefined`: the one
|
|
704
|
+
* served at `/`, for `x-default`). Absolute when `siteUrl` is known, otherwise the paths as given. Empty for fewer
|
|
705
|
+
* than two locales: a single-locale site has no alternates.
|
|
706
|
+
*/
|
|
707
|
+
export declare function buildAlternates(input: {
|
|
708
|
+
locales: readonly string[];
|
|
709
|
+
pathFor: (locale: string | undefined) => string;
|
|
710
|
+
siteUrl?: string | null;
|
|
711
|
+
}): Array<{
|
|
712
|
+
rel: 'alternate';
|
|
713
|
+
hreflang: string;
|
|
714
|
+
href: string;
|
|
715
|
+
}>;
|
|
716
|
+
//#endregion
|
|
717
|
+
//#region src/structuredData.d.ts
|
|
718
|
+
/**
|
|
719
|
+
* schema.org JSON-LD builders, framework-free. A theme's page feeds them plain data it already
|
|
720
|
+
* renders from (the same price, currency and stock the visible `<Price>` and stock line read), and
|
|
721
|
+
* `@eldrajs/theme-nuxt`'s `useStructuredData` writes the result into the head. Nothing here reads
|
|
722
|
+
* a gateway, a route or the DOM.
|
|
723
|
+
*
|
|
724
|
+
* Rules every builder follows, so a theme never has to:
|
|
725
|
+
*
|
|
726
|
+
* - An `undefined`, `null`, empty string, empty array or empty object is **omitted**, never
|
|
727
|
+
* emitted: a half-empty node is worse than none for a crawler, and Google penalises made-up
|
|
728
|
+
* values (so there is no rating unless the caller has real ones).
|
|
729
|
+
* - Prices are the amount rounded to the **store currency's own fraction digits** (`ISK` has none,
|
|
730
|
+
* `USD` two), the same rounding the rendered price uses.
|
|
731
|
+
* - `availability` is a full schema.org URL.
|
|
732
|
+
* - `serializeLd` escapes `<` (and the two line separators) so a product named `</script>` cannot
|
|
733
|
+
* break out of the tag.
|
|
734
|
+
*/
|
|
735
|
+
/** One JSON-LD node. */
|
|
736
|
+
export type JsonLd = Record<string, unknown>;
|
|
737
|
+
/** The kinds of node a theme writes; the opt-out and the extender are keyed by these. */
|
|
738
|
+
export type StructuredDataType = 'product' | 'breadcrumb' | 'itemList' | 'organization' | 'website';
|
|
739
|
+
export declare const STRUCTURED_DATA_TYPES: readonly StructuredDataType[];
|
|
740
|
+
export type LdAvailability = 'InStock' | 'OutOfStock' | 'PreOrder' | 'LimitedAvailability';
|
|
741
|
+
export interface ProductLdVariant {
|
|
742
|
+
sku?: string | null;
|
|
743
|
+
/** Free text in the catalog; emitted as `gtin` only when it is a valid GTIN-8/12/13/14. */
|
|
744
|
+
gtin?: string | null;
|
|
745
|
+
/** Major units. */
|
|
746
|
+
price: number;
|
|
747
|
+
/** The pre-sale price in major units; written as the offer's list price when above `price`. */
|
|
748
|
+
compareAt?: number | null;
|
|
749
|
+
availability: LdAvailability;
|
|
750
|
+
url?: string | null;
|
|
751
|
+
/** ISO 8601 date; the end of the sale price. */
|
|
752
|
+
priceValidUntil?: string | null;
|
|
753
|
+
}
|
|
754
|
+
export interface ProductLdInput {
|
|
755
|
+
url: string;
|
|
756
|
+
name: string;
|
|
757
|
+
description?: string | null;
|
|
758
|
+
images?: readonly string[];
|
|
759
|
+
brand?: string | null;
|
|
760
|
+
variants: readonly ProductLdVariant[];
|
|
761
|
+
/** ISO 4217. Without one no offer is written: a price with no currency is not a price. */
|
|
762
|
+
currency?: string | null;
|
|
763
|
+
/** Only real review data; `undefined` writes nothing. */
|
|
764
|
+
ratings?: {
|
|
765
|
+
value: number;
|
|
766
|
+
count: number;
|
|
767
|
+
} | null;
|
|
768
|
+
}
|
|
769
|
+
/** The amount as the number written in an offer: rounded to the currency's own digits. */
|
|
770
|
+
export declare function ldPrice(amount: number, currency: string): number;
|
|
771
|
+
/**
|
|
772
|
+
* The GTIN if `value` is a valid GTIN-8/12/13/14 (digits only, GS1 check digit correct), else
|
|
773
|
+
* `null`. A barcode field is free text, so anything else (an internal code, a mistyped digit) is
|
|
774
|
+
* left out rather than sent to a crawler as an identifier.
|
|
775
|
+
*/
|
|
776
|
+
export declare function validGtin(value: string | null | undefined): string | null;
|
|
777
|
+
/**
|
|
778
|
+
* A `Product`. One variant, or several at one price, is an `Offer`; variants at different prices
|
|
779
|
+
* are an `AggregateOffer` (`lowPrice`, `highPrice`, `offerCount`, one `Offer` each). With no
|
|
780
|
+
* currency or no variants the node carries no offers at all.
|
|
781
|
+
*/
|
|
782
|
+
export declare function buildProductLd(input: ProductLdInput): JsonLd;
|
|
783
|
+
/** A `BreadcrumbList`, root first. Every level carries its URL, the last one included. */
|
|
784
|
+
export declare function buildBreadcrumbLd(items: readonly {
|
|
785
|
+
name: string;
|
|
786
|
+
url: string;
|
|
787
|
+
}[]): JsonLd;
|
|
788
|
+
/** An `ItemList` of the things a listing page shows, in the order shown. */
|
|
789
|
+
export declare function buildItemListLd(items: readonly {
|
|
790
|
+
url: string;
|
|
791
|
+
name: string;
|
|
792
|
+
}[]): JsonLd;
|
|
793
|
+
export interface OrganizationLdInput {
|
|
794
|
+
name: string;
|
|
795
|
+
url: string;
|
|
796
|
+
logo?: string | null;
|
|
797
|
+
sameAs?: readonly string[];
|
|
798
|
+
contact?: {
|
|
799
|
+
email?: string | null;
|
|
800
|
+
telephone?: string | null;
|
|
801
|
+
} | null;
|
|
802
|
+
}
|
|
803
|
+
export declare function buildOrganizationLd(input: OrganizationLdInput): JsonLd;
|
|
804
|
+
export interface WebSiteLdInput {
|
|
805
|
+
name: string;
|
|
806
|
+
url: string;
|
|
807
|
+
/** The site's search page path (`/search`), or `null`/absent when there is none. A SearchAction
|
|
808
|
+
* pointing at a page that does not exist is worse than none. It is queried with `?q=`. */
|
|
809
|
+
searchPath?: string | null;
|
|
810
|
+
}
|
|
811
|
+
export declare function buildWebSiteLd(input: WebSiteLdInput): JsonLd;
|
|
812
|
+
/**
|
|
813
|
+
* The text of `<script type="application/ld+json">`. One node is written as itself, several as an
|
|
814
|
+
* array. `<` is written as its JSON escape (so `</script>` and `<!--` cannot occur) and U+2028/U+2029 are
|
|
815
|
+
* escaped; the result is still plain JSON.
|
|
816
|
+
*/
|
|
817
|
+
export declare function serializeLd(nodes: readonly JsonLd[]): string;
|
|
818
|
+
export declare const LD_DESCRIPTION_MAX = 5000;
|
|
819
|
+
/**
|
|
820
|
+
* A description as plain text for `description`: a string with its HTML tags dropped, or a rich-text
|
|
821
|
+
* document (nodes with `text`/`content`) flattened, whitespace collapsed, cut at `max` characters
|
|
822
|
+
* on a word boundary.
|
|
823
|
+
*/
|
|
824
|
+
export declare function ldPlainText(value: unknown, max?: number): string;
|
|
825
|
+
/** A built node and what kind it is. */
|
|
826
|
+
export interface StructuredDataEntry {
|
|
827
|
+
type: StructuredDataType;
|
|
828
|
+
node: JsonLd;
|
|
829
|
+
}
|
|
830
|
+
/** What a theme can say about the nodes it writes. */
|
|
831
|
+
export interface StructuredDataPolicy {
|
|
832
|
+
/** `true` writes none; a list switches those node kinds off. */
|
|
833
|
+
disable?: readonly StructuredDataType[] | boolean;
|
|
834
|
+
/** Edit a node (return the new one) or drop it (return `null`). Runs after `disable`. */
|
|
835
|
+
extend?: (type: StructuredDataType, node: JsonLd, context: StructuredDataContext) => JsonLd | null;
|
|
836
|
+
}
|
|
837
|
+
export interface StructuredDataContext {
|
|
838
|
+
path: string;
|
|
839
|
+
locale: string | null;
|
|
840
|
+
}
|
|
841
|
+
/** Applies the theme's opt-out and extender to the nodes a page built. Pure. */
|
|
842
|
+
export declare function applyStructuredDataPolicy(entries: readonly StructuredDataEntry[], policy: StructuredDataPolicy, context: StructuredDataContext): JsonLd[];
|
|
843
|
+
//#endregion
|
|
449
844
|
export { type BeforeInputClassification, type BlockFieldDefinition, type BlockFieldsMap, BlockSlotDefinition, type BuildRichTextTreeOptions, CatalogDoc, CatalogList, CatalogQuery, ColorLiteral, ColorSelection, ContainerOverride, ContainerPreset, CssLength, CssTokenLength, DEFAULT_IMAGE_FRAMING, DEFAULT_LAYOUT_BREAKPOINTS, DesignTokenCatalog, DesignTokenId, DesignTokenValidationCode, DesignTokenValidationError, DynamicRouteResolution, EDIT_MODE_HIDDEN_OPACITY, EldraCatalogReader, EldraClient, EldraClientError, EldraClientOptions, EldraRetryOptions, EntryDoc, EntryList, EntryQuery, FrameRect, IMAGE_FRAMING_MAX_ZOOM, IMAGE_FRAMING_MIN_ZOOM, ImageFraming, LAYOUT_BREAKPOINTS, LayoutBlockNode, LayoutBreakpoint, LayoutBreakpoints, LayoutContainerNode, LayoutDocument, LayoutNode, LayoutRenderBlockNode, LayoutRenderModel, LayoutRenderNode, LayoutStyle, LayoutValidationCode, LayoutValidationError, LayoutValidationIssue, MAX_DYNAMIC_ROUTE_PATTERN_BYTES, type NegotiatedEditorCapabilities, NormalizedLayoutResult, type OverlayRuntime, type OverlayRuntimeOptions, PREVIEW_ROUTER_MESSAGE_TYPES, PageLayoutDocument, PageLayoutNode, type PageLike, PageMeta, ParsedDynamicRoutePattern, type PreviewMessageRouter, type PreviewRouterMessageType, ResolveEntryListBody, ResolvedLayoutDocument, ResolvedLayoutNode, ResolvedLayoutStyle, Responsive, ResponsiveTokenValue, type ReusableComponentBinding, type ReusableComponentPlacement, type ReusableComponentProjection, type ReusableComponentResolver, type ReusableComponentRevision, ReusableComponentSnapshotCache, ReusableLayoutOptions, ReusableLayoutRenderModel, ReusableLayoutRenderNode, ReusablePerspective, type ReusableRenderIdentity, type RichTextDomPoint, type RichTextFieldIdentity, type RichTextMark, type RichTextNode, type RichTextPositionNode, type RichTextPositions, type RichTextRenderChild, type RichTextRenderNode, type RichTextRenderStateChange, type RichTextSelectionContext, type RichTextToolbarControl, RouteTemplateLike, SiteDesignTokenOverrides, SizingLength, SlotValidationContext, Spacing, type StegaMeta, TemplateBlockDefinition, TemplateBlockFieldDefinition, TemplateBlockNode, TemplateLayoutContext, TemplateLayoutDocument, TemplateLayoutNode, TemplateLayoutRenderModel, TemplateLayoutRenderNode, ThemeColorToken, ThemeDesignTokens, WidthLength, activeLayoutBreakpoint, applyDesignTokenOverrides, buildDynamicRoutePath, buildTemplateBlockRenames, catalogRouteTarget, clampFocal, clampImageFraming, classifyBeforeInput, createLayoutRenderModel, createOverlayRuntime, createPreviewMessageRouter, createProjectionResolver, createReusableLayoutRenderModel, createTemplateLayoutRenderModel, decodeStega, designTokenRevisionHash, encodeStega, focalBand, framingDrag, framingZoom, generateDesignTokenCss, generateLayoutCss, generateTailwindThemeCss, hiddenLayoutBreakpoints, imageFramingAttrs, imageFramingStyle, layoutNodeClass, layoutRenderNodeId, matchDynamicRoutePattern, normalizeColorSelection, normalizeImageFraming, normalizeLayoutDocument, normalizeSiteDesignTokenOverrides, normalizeThemeDesignTokens, parseDynamicRoutePattern, parseImageFramingValueAttr, resolveColorSelection, resolveDesignTokenCatalog, resolveLayoutBreakpoints, resolveLayoutDocument, resolvePagePath, resolveRoute, responsiveValue, stripStega, unscaledFrameRect, validateLayoutDocument };
|
package/dist/index.js
CHANGED
|
@@ -531,6 +531,7 @@ function createEldraClient(opts) {
|
|
|
531
531
|
const headers = new Headers(init?.headers);
|
|
532
532
|
headers.set("X-Org-Id", opts.orgId);
|
|
533
533
|
if (previewToken !== null) headers.set("X-Preview-Token", previewToken);
|
|
534
|
+
if (opts.buildToken) headers.set("X-Eldra-Build-Token", opts.buildToken);
|
|
534
535
|
const merged = {
|
|
535
536
|
...init,
|
|
536
537
|
headers
|
|
@@ -810,6 +811,80 @@ function projectLocalizedLeaves(data, locale, defaultLocale, apiId) {
|
|
|
810
811
|
return projectLocalizedValue(data, locale, defaultLocale, apiId, "");
|
|
811
812
|
}
|
|
812
813
|
//#endregion
|
|
814
|
+
//#region src/analytics.ts
|
|
815
|
+
/** Core's ingest limits (`SanitizeProps`): 30 entries, keys up to 60 bytes, values 300 bytes. */
|
|
816
|
+
const ANALYTICS_MAX_PROPS = 30;
|
|
817
|
+
const ANALYTICS_MAX_KEY_BYTES = 60;
|
|
818
|
+
const ANALYTICS_MAX_VALUE_BYTES = 300;
|
|
819
|
+
/** Core cuts an event name at 120 bytes. */
|
|
820
|
+
const ANALYTICS_MAX_NAME_BYTES = 120;
|
|
821
|
+
/** Events held back before the tracker script has loaded; the oldest are dropped past this. */
|
|
822
|
+
const ANALYTICS_QUEUE_LIMIT = 50;
|
|
823
|
+
/** Cuts a string to at most `maxBytes` of UTF-8 without splitting a character. */
|
|
824
|
+
function truncateUtf8(value, maxBytes) {
|
|
825
|
+
const encoder = new TextEncoder();
|
|
826
|
+
if (encoder.encode(value).length <= maxBytes) return value;
|
|
827
|
+
let out = "";
|
|
828
|
+
let size = 0;
|
|
829
|
+
for (const char of value) {
|
|
830
|
+
const next = encoder.encode(char).length;
|
|
831
|
+
if (size + next > maxBytes) break;
|
|
832
|
+
out += char;
|
|
833
|
+
size += next;
|
|
834
|
+
}
|
|
835
|
+
return out;
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Coerces a theme's props to what Core stores: strings only, `null`/`undefined`/non-finite numbers
|
|
839
|
+
* dropped, keys and values cut to the ingest limits, at most 30 entries.
|
|
840
|
+
*/
|
|
841
|
+
function normalizeAnalyticsProps(props) {
|
|
842
|
+
const out = {};
|
|
843
|
+
if (props === void 0) return out;
|
|
844
|
+
for (const [rawKey, raw] of Object.entries(props)) {
|
|
845
|
+
if (Object.keys(out).length >= 30) break;
|
|
846
|
+
if (raw === null || raw === void 0) continue;
|
|
847
|
+
if (typeof raw === "number" && !Number.isFinite(raw)) continue;
|
|
848
|
+
const key = truncateUtf8(rawKey, 60);
|
|
849
|
+
if (key === "") continue;
|
|
850
|
+
out[key] = truncateUtf8(String(raw), 300);
|
|
851
|
+
}
|
|
852
|
+
return out;
|
|
853
|
+
}
|
|
854
|
+
function createAnalytics(options) {
|
|
855
|
+
const queue = [];
|
|
856
|
+
function send(sender, name, props) {
|
|
857
|
+
try {
|
|
858
|
+
sender("event", name, { props });
|
|
859
|
+
} catch {}
|
|
860
|
+
}
|
|
861
|
+
return {
|
|
862
|
+
enabled: options.enabled,
|
|
863
|
+
track(rawName, props) {
|
|
864
|
+
if (!options.enabled) return;
|
|
865
|
+
const name = truncateUtf8(rawName.trim(), 120);
|
|
866
|
+
if (name === "" || name === "pageview") return;
|
|
867
|
+
const normalized = normalizeAnalyticsProps(props);
|
|
868
|
+
const sender = options.sender();
|
|
869
|
+
if (sender === void 0) {
|
|
870
|
+
queue.push({
|
|
871
|
+
name,
|
|
872
|
+
props: normalized
|
|
873
|
+
});
|
|
874
|
+
if (queue.length > 50) queue.shift();
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
send(sender, name, normalized);
|
|
878
|
+
},
|
|
879
|
+
flush() {
|
|
880
|
+
if (!options.enabled) return;
|
|
881
|
+
const sender = options.sender();
|
|
882
|
+
if (sender === void 0) return;
|
|
883
|
+
for (const event of queue.splice(0)) send(sender, event.name, event.props);
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
//#endregion
|
|
813
888
|
//#region src/richText.ts
|
|
814
889
|
/**
|
|
815
890
|
* Ordered ids of every rich-text toolbar control a `block.json` may request
|
|
@@ -1138,4 +1213,553 @@ function buildFileAttachmentMark(mark, options, child) {
|
|
|
1138
1213
|
};
|
|
1139
1214
|
}
|
|
1140
1215
|
//#endregion
|
|
1141
|
-
|
|
1216
|
+
//#region src/seo.ts
|
|
1217
|
+
/** The only pattern syntax version this resolver understands. */
|
|
1218
|
+
const SEO_SYNTAX = 1;
|
|
1219
|
+
const PLACEHOLDER = /\{\{([^{}]+)\}\}/g;
|
|
1220
|
+
const SEPARATORS = /* @__PURE__ */ new Set([
|
|
1221
|
+
"·",
|
|
1222
|
+
"|",
|
|
1223
|
+
"–",
|
|
1224
|
+
"—",
|
|
1225
|
+
"-"
|
|
1226
|
+
]);
|
|
1227
|
+
/** The title pattern used when neither the context nor the site sets one. */
|
|
1228
|
+
const DEFAULT_TITLE_PATTERN = "{{page.title}} · {{site.name}}";
|
|
1229
|
+
/** The home page's default: the site's name alone. */
|
|
1230
|
+
const DEFAULT_HOME_TITLE_PATTERN = "{{site.name}}";
|
|
1231
|
+
/** Looks `path` up in `data`: first as a flat key, then walking nested objects. */
|
|
1232
|
+
function lookup(data, path) {
|
|
1233
|
+
let value = Object.prototype.hasOwnProperty.call(data, path) ? data[path] : void 0;
|
|
1234
|
+
if (value === void 0) {
|
|
1235
|
+
value = data;
|
|
1236
|
+
for (const part of path.split(".")) {
|
|
1237
|
+
if (typeof value !== "object" || value === null || !Object.hasOwn(value, part)) return "";
|
|
1238
|
+
value = value[part];
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
if (typeof value === "string") return value;
|
|
1242
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
1243
|
+
return "";
|
|
1244
|
+
}
|
|
1245
|
+
/** One pass of `{{path}}` substitution; unknown and empty values become `''`. No tidying. */
|
|
1246
|
+
function substituteSeoPattern(pattern, data) {
|
|
1247
|
+
return pattern.replace(PLACEHOLDER, (_match, path) => lookup(data, path.trim()));
|
|
1248
|
+
}
|
|
1249
|
+
/** Collapses whitespace and drops leading, trailing and doubled separators. */
|
|
1250
|
+
function tidySeoTitle(value) {
|
|
1251
|
+
const tokens = value.split(/\s+/).filter((token) => token !== "");
|
|
1252
|
+
const kept = [];
|
|
1253
|
+
for (const token of tokens) {
|
|
1254
|
+
if (SEPARATORS.has(token) && (kept.length === 0 || SEPARATORS.has(kept[kept.length - 1]))) continue;
|
|
1255
|
+
kept.push(token);
|
|
1256
|
+
}
|
|
1257
|
+
while (kept.length > 0 && SEPARATORS.has(kept[kept.length - 1])) kept.pop();
|
|
1258
|
+
return kept.join(" ");
|
|
1259
|
+
}
|
|
1260
|
+
/** Substitutes, then tidies: the title rule the shared vectors pin down. */
|
|
1261
|
+
function renderSeoTitle(pattern, data) {
|
|
1262
|
+
return tidySeoTitle(substituteSeoPattern(pattern, data));
|
|
1263
|
+
}
|
|
1264
|
+
function renderSeoText(pattern, data) {
|
|
1265
|
+
return substituteSeoPattern(pattern, data).replace(/\s+/g, " ").trim();
|
|
1266
|
+
}
|
|
1267
|
+
/**
|
|
1268
|
+
* One locale's string out of a string or a locale map: the exact tag, the same language, the
|
|
1269
|
+
* default locale, then `''`.
|
|
1270
|
+
*/
|
|
1271
|
+
function pickSeoLocale(value, locale, defaultLocale) {
|
|
1272
|
+
if (typeof value === "string") return value;
|
|
1273
|
+
if (typeof value !== "object" || value === null) return "";
|
|
1274
|
+
const own = (key) => {
|
|
1275
|
+
if (key === null || key === void 0 || !Object.hasOwn(value, key)) return "";
|
|
1276
|
+
const text = value[key];
|
|
1277
|
+
return typeof text === "string" ? text : "";
|
|
1278
|
+
};
|
|
1279
|
+
const language = locale?.split("-")[0]?.toLowerCase();
|
|
1280
|
+
const sameLanguage = language === void 0 ? "" : own(Object.keys(value).find((key) => key.split("-")[0]?.toLowerCase() === language));
|
|
1281
|
+
return [
|
|
1282
|
+
own(locale),
|
|
1283
|
+
sameLanguage,
|
|
1284
|
+
own(defaultLocale)
|
|
1285
|
+
].find((text) => text.trim() !== "") ?? "";
|
|
1286
|
+
}
|
|
1287
|
+
function absolute(url, siteUrl) {
|
|
1288
|
+
const value = url?.trim();
|
|
1289
|
+
if (value === void 0 || value === "") return null;
|
|
1290
|
+
try {
|
|
1291
|
+
const resolved = siteUrl === null ? new URL(value) : new URL(value, siteUrl);
|
|
1292
|
+
return resolved.protocol === "https:" || resolved.protocol === "http:" ? resolved.href : null;
|
|
1293
|
+
} catch {
|
|
1294
|
+
return null;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
function originOf(siteUrl) {
|
|
1298
|
+
const value = siteUrl?.trim();
|
|
1299
|
+
if (value === void 0 || value === "") return null;
|
|
1300
|
+
try {
|
|
1301
|
+
const url = new URL(value);
|
|
1302
|
+
return url.protocol === "https:" || url.protocol === "http:" ? url.origin : null;
|
|
1303
|
+
} catch {
|
|
1304
|
+
return null;
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
/** Resolves every SEO value one route needs. Pure; never throws on malformed content. */
|
|
1308
|
+
function resolveSeo(input) {
|
|
1309
|
+
const { locale, context, site } = input;
|
|
1310
|
+
const pick = (value) => pickSeoLocale(value, locale, input.defaultLocale);
|
|
1311
|
+
const origin = originOf(input.siteUrl);
|
|
1312
|
+
const siteName = site?.site.name?.trim() || input.siteName?.trim() || "";
|
|
1313
|
+
const data = {
|
|
1314
|
+
...input.data,
|
|
1315
|
+
"site.name": siteName,
|
|
1316
|
+
"site.url": origin ?? "",
|
|
1317
|
+
"site.locale": locale ?? ""
|
|
1318
|
+
};
|
|
1319
|
+
const entry = input.entry ?? null;
|
|
1320
|
+
const template = input.template ?? null;
|
|
1321
|
+
const patterns = site?.templates[context];
|
|
1322
|
+
const titleOverride = pick(entry?.title) || pick(template?.title);
|
|
1323
|
+
let title = "";
|
|
1324
|
+
if (titleOverride.trim() !== "") title = renderSeoTitle(titleOverride, data);
|
|
1325
|
+
if (title === "") title = renderSeoTitle(pick(patterns?.titlePattern) || pick(site?.site.titlePattern) || (context === "home" ? "{{site.name}}" : "{{page.title}} · {{site.name}}"), data);
|
|
1326
|
+
if (title === "") title = renderSeoTitle("{{page.title}}", data) || siteName;
|
|
1327
|
+
const description = renderSeoText(pick(entry?.description) || pick(template?.description) || pick(patterns?.descriptionPattern) || pick(site?.site.description), data);
|
|
1328
|
+
const ogTitle = renderSeoText(pick(entry?.ogTitle) || pick(template?.ogTitle), data) || title;
|
|
1329
|
+
const ogDescription = renderSeoText(pick(entry?.ogDescription) || pick(template?.ogDescription), data) || description;
|
|
1330
|
+
const image = absolute(entry?.imageUrl, origin) ?? absolute(template?.imageUrl, origin) ?? absolute(input.contentImage, origin) ?? absolute(site?.site.imageUrl, origin);
|
|
1331
|
+
let canonical = null;
|
|
1332
|
+
const canonicalPattern = pick(entry?.canonicalUrl) || pick(template?.canonicalUrl);
|
|
1333
|
+
let useOwnPath = canonicalPattern.trim() === "";
|
|
1334
|
+
if (!useOwnPath) {
|
|
1335
|
+
const rendered = renderSeoText(canonicalPattern, data);
|
|
1336
|
+
if (/[{}]/.test(rendered)) useOwnPath = true;
|
|
1337
|
+
else canonical = absolute(rendered, origin);
|
|
1338
|
+
}
|
|
1339
|
+
if (useOwnPath && origin !== null && input.path !== void 0 && input.path !== null) try {
|
|
1340
|
+
const url = new URL(input.path, origin);
|
|
1341
|
+
canonical = `${url.origin}${url.pathname}`;
|
|
1342
|
+
} catch {
|
|
1343
|
+
canonical = null;
|
|
1344
|
+
}
|
|
1345
|
+
const handle = site?.site.twitterHandle?.trim().replace(/^@+/, "") ?? "";
|
|
1346
|
+
return {
|
|
1347
|
+
title,
|
|
1348
|
+
description,
|
|
1349
|
+
ogTitle,
|
|
1350
|
+
ogDescription,
|
|
1351
|
+
image,
|
|
1352
|
+
canonical,
|
|
1353
|
+
noindex: input.isPreview === true || entry?.noindex === true || template?.noindex === true,
|
|
1354
|
+
ogType: context === "catalog:product" ? "product" : "website",
|
|
1355
|
+
twitterSite: handle === "" ? null : `@${handle}`
|
|
1356
|
+
};
|
|
1357
|
+
}
|
|
1358
|
+
//#endregion
|
|
1359
|
+
//#region src/sitemap.ts
|
|
1360
|
+
const SITEMAP_MAX_URLS = 5e4;
|
|
1361
|
+
const SITEMAP_MAX_BYTES = 52428800;
|
|
1362
|
+
const URLSET_OPEN = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n";
|
|
1363
|
+
const URLSET_CLOSE = "</urlset>\n";
|
|
1364
|
+
const byteLength = (text) => new TextEncoder().encode(text).length;
|
|
1365
|
+
/** The absolute origin of `siteUrl` (`https://shop.example`, no trailing slash), or `null`. */
|
|
1366
|
+
function siteOrigin(siteUrl) {
|
|
1367
|
+
const value = siteUrl?.trim();
|
|
1368
|
+
if (value === void 0 || value === "") return null;
|
|
1369
|
+
try {
|
|
1370
|
+
const url = new URL(value);
|
|
1371
|
+
return url.protocol === "https:" || url.protocol === "http:" ? url.origin : null;
|
|
1372
|
+
} catch {
|
|
1373
|
+
return null;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
function escapeXml(value) {
|
|
1377
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1378
|
+
}
|
|
1379
|
+
/** A W3C datetime (`2026-01-02T03:04:05.000Z`), or `null` for anything that is not a date. */
|
|
1380
|
+
function sitemapLastmod(value) {
|
|
1381
|
+
if (value === null || value === void 0 || value === "") return null;
|
|
1382
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
1383
|
+
return Number.isNaN(date.getTime()) ? null : date.toISOString();
|
|
1384
|
+
}
|
|
1385
|
+
/**
|
|
1386
|
+
* The URL a variant is listed under: its own canonical when that is on this site's origin, else
|
|
1387
|
+
* the path-derived URL. A canonical on another host is not a page of this site and must not put
|
|
1388
|
+
* a foreign URL in this site's sitemap.
|
|
1389
|
+
*/
|
|
1390
|
+
function locOf(variant, origin) {
|
|
1391
|
+
const canonical = variant.canonical?.trim();
|
|
1392
|
+
if (canonical !== void 0 && canonical !== "") try {
|
|
1393
|
+
const url = new URL(canonical, origin);
|
|
1394
|
+
if (url.origin === origin) return `${url.origin}${url.pathname}${url.search}`;
|
|
1395
|
+
} catch {}
|
|
1396
|
+
try {
|
|
1397
|
+
const url = new URL(variant.path, origin);
|
|
1398
|
+
return `${url.origin}${url.pathname}${url.search}`;
|
|
1399
|
+
} catch {
|
|
1400
|
+
return null;
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
/** The `<url>` blocks of every indexable page, one per variant, in input order, deduplicated by `loc`. */
|
|
1404
|
+
function urlBlocks(pages, origin) {
|
|
1405
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1406
|
+
const blocks = [];
|
|
1407
|
+
for (const page of pages) {
|
|
1408
|
+
if (page.noindex === true) continue;
|
|
1409
|
+
const located = page.variants.map((variant) => ({
|
|
1410
|
+
variant,
|
|
1411
|
+
loc: locOf(variant, origin)
|
|
1412
|
+
})).filter((entry) => entry.loc !== null);
|
|
1413
|
+
const lastmod = sitemapLastmod(page.lastmod);
|
|
1414
|
+
const alternates = [];
|
|
1415
|
+
if (located.length > 1) {
|
|
1416
|
+
for (const { variant, loc } of located) {
|
|
1417
|
+
if (variant.locale === null) continue;
|
|
1418
|
+
alternates.push(linkTag(variant.locale, loc));
|
|
1419
|
+
}
|
|
1420
|
+
const fallback = located.find((entry) => entry.variant.isDefault === true);
|
|
1421
|
+
if (fallback !== void 0) alternates.push(linkTag("x-default", fallback.loc));
|
|
1422
|
+
}
|
|
1423
|
+
for (const { loc } of located) {
|
|
1424
|
+
if (seen.has(loc)) continue;
|
|
1425
|
+
seen.add(loc);
|
|
1426
|
+
blocks.push(` <url>\n <loc>${escapeXml(loc)}</loc>\n` + (lastmod === null ? "" : ` <lastmod>${lastmod}</lastmod>\n`) + alternates.map((tag) => ` ${tag}\n`).join("") + " </url>\n");
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
return blocks;
|
|
1430
|
+
}
|
|
1431
|
+
function linkTag(hreflang, href) {
|
|
1432
|
+
return `<xhtml:link rel="alternate" hreflang="${escapeXml(hreflang)}" href="${escapeXml(href)}"/>`;
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
1435
|
+
* The sitemap files for `pages`: one `sitemap.xml` (a `urlset`), or, when the URLs do not fit the
|
|
1436
|
+
* limits, a `sitemap.xml` that is a `sitemapindex` over `sitemap-1.xml`, `sitemap-2.xml`, ...
|
|
1437
|
+
*
|
|
1438
|
+
* Empty when `siteUrl` is not an absolute http(s) URL (a sitemap of relative URLs is invalid) and
|
|
1439
|
+
* when no page is indexable.
|
|
1440
|
+
*/
|
|
1441
|
+
function buildSitemap(input) {
|
|
1442
|
+
const origin = siteOrigin(input.siteUrl);
|
|
1443
|
+
if (origin === null) return [];
|
|
1444
|
+
const blocks = urlBlocks(input.pages, origin);
|
|
1445
|
+
if (blocks.length === 0) return [];
|
|
1446
|
+
const maxUrls = Math.max(1, input.limits?.maxUrls ?? 5e4);
|
|
1447
|
+
const maxBytes = input.limits?.maxBytes ?? 52428800;
|
|
1448
|
+
const envelope = byteLength(URLSET_OPEN) + byteLength(URLSET_CLOSE);
|
|
1449
|
+
const chunks = [];
|
|
1450
|
+
let current = [];
|
|
1451
|
+
let size = envelope;
|
|
1452
|
+
for (const block of blocks) {
|
|
1453
|
+
const blockSize = byteLength(block);
|
|
1454
|
+
if (current.length > 0 && (current.length >= maxUrls || size + blockSize > maxBytes)) {
|
|
1455
|
+
chunks.push(current);
|
|
1456
|
+
current = [];
|
|
1457
|
+
size = envelope;
|
|
1458
|
+
}
|
|
1459
|
+
current.push(block);
|
|
1460
|
+
size += blockSize;
|
|
1461
|
+
}
|
|
1462
|
+
chunks.push(current);
|
|
1463
|
+
const urlset = (chunk) => `${URLSET_OPEN}${chunk.join("")}${URLSET_CLOSE}`;
|
|
1464
|
+
if (chunks.length === 1) return [{
|
|
1465
|
+
name: "sitemap.xml",
|
|
1466
|
+
xml: urlset(chunks[0])
|
|
1467
|
+
}];
|
|
1468
|
+
const files = chunks.map((chunk, index) => ({
|
|
1469
|
+
name: `sitemap-${index + 1}.xml`,
|
|
1470
|
+
xml: urlset(chunk)
|
|
1471
|
+
}));
|
|
1472
|
+
return [{
|
|
1473
|
+
name: "sitemap.xml",
|
|
1474
|
+
xml: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n" + files.map((file) => ` <sitemap>\n <loc>${escapeXml(`${origin}/${file.name}`)}</loc>\n </sitemap>\n`).join("") + "</sitemapindex>\n"
|
|
1475
|
+
}, ...files];
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* The `robots.txt` body.
|
|
1479
|
+
*
|
|
1480
|
+
* A **preview** build disallows everything and names no sitemap. A production build allows
|
|
1481
|
+
* everything, adds the merchant's own lines (`extra`), and names the sitemap when there is one.
|
|
1482
|
+
* `extra` is untrusted text: control characters are dropped, every line is trimmed, and a line
|
|
1483
|
+
* that opens a second `User-agent` group is kept as the merchant wrote it (that is the point of
|
|
1484
|
+
* the field), after the platform's group.
|
|
1485
|
+
*/
|
|
1486
|
+
function buildRobots(input) {
|
|
1487
|
+
if (input.target !== "production") return "User-agent: *\nDisallow: /\n";
|
|
1488
|
+
const lines = ["User-agent: *", "Allow: /"];
|
|
1489
|
+
const extra = (input.extra ?? "").replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, "").split(/\r?\n/).map((line) => line.trim()).filter((line) => line !== "");
|
|
1490
|
+
lines.push(...extra);
|
|
1491
|
+
const origin = siteOrigin(input.siteUrl);
|
|
1492
|
+
if (input.sitemap === true && origin !== null) lines.push("", `Sitemap: ${origin}/sitemap.xml`);
|
|
1493
|
+
return `${lines.join("\n")}\n`;
|
|
1494
|
+
}
|
|
1495
|
+
/**
|
|
1496
|
+
* The `<link rel="alternate" hreflang>` set for one page, for the head: one per locale plus
|
|
1497
|
+
* `x-default`. `pathFor(locale)` spells the page under that locale (`undefined`: the one
|
|
1498
|
+
* served at `/`, for `x-default`). Absolute when `siteUrl` is known, otherwise the paths as given. Empty for fewer
|
|
1499
|
+
* than two locales: a single-locale site has no alternates.
|
|
1500
|
+
*/
|
|
1501
|
+
function buildAlternates(input) {
|
|
1502
|
+
if (input.locales.length < 2) return [];
|
|
1503
|
+
const origin = siteOrigin(input.siteUrl);
|
|
1504
|
+
const href = (path) => origin === null ? path : `${origin}${path}`;
|
|
1505
|
+
return [...input.locales.map((locale) => ({
|
|
1506
|
+
rel: "alternate",
|
|
1507
|
+
hreflang: locale,
|
|
1508
|
+
href: href(input.pathFor(locale))
|
|
1509
|
+
})), {
|
|
1510
|
+
rel: "alternate",
|
|
1511
|
+
hreflang: "x-default",
|
|
1512
|
+
href: href(input.pathFor(void 0))
|
|
1513
|
+
}];
|
|
1514
|
+
}
|
|
1515
|
+
//#endregion
|
|
1516
|
+
//#region src/structuredData.ts
|
|
1517
|
+
const STRUCTURED_DATA_TYPES = [
|
|
1518
|
+
"product",
|
|
1519
|
+
"breadcrumb",
|
|
1520
|
+
"itemList",
|
|
1521
|
+
"organization",
|
|
1522
|
+
"website"
|
|
1523
|
+
];
|
|
1524
|
+
const SCHEMA = "https://schema.org";
|
|
1525
|
+
const AVAILABILITY_URL = {
|
|
1526
|
+
InStock: `${SCHEMA}/InStock`,
|
|
1527
|
+
OutOfStock: `${SCHEMA}/OutOfStock`,
|
|
1528
|
+
PreOrder: `${SCHEMA}/PreOrder`,
|
|
1529
|
+
LimitedAvailability: `${SCHEMA}/LimitedAvailability`
|
|
1530
|
+
};
|
|
1531
|
+
/** Which availability wins when one price covers variants that differ: the most buyable one. */
|
|
1532
|
+
const AVAILABILITY_RANK = {
|
|
1533
|
+
InStock: 3,
|
|
1534
|
+
LimitedAvailability: 2,
|
|
1535
|
+
PreOrder: 1,
|
|
1536
|
+
OutOfStock: 0
|
|
1537
|
+
};
|
|
1538
|
+
/** Drops every empty value, recursively. Numbers (including `0`) and booleans are kept. */
|
|
1539
|
+
function clean(value) {
|
|
1540
|
+
if (value === null || value === void 0) return void 0;
|
|
1541
|
+
if (typeof value === "string") return value.trim() === "" ? void 0 : value;
|
|
1542
|
+
if (Array.isArray(value)) {
|
|
1543
|
+
const items = value.map((item) => clean(item)).filter((item) => item !== void 0);
|
|
1544
|
+
return items.length === 0 ? void 0 : items;
|
|
1545
|
+
}
|
|
1546
|
+
if (typeof value === "object") {
|
|
1547
|
+
const entries = Object.entries(value).map(([key, item]) => [key, clean(item)]).filter(([, item]) => item !== void 0);
|
|
1548
|
+
return entries.length === 0 ? void 0 : Object.fromEntries(entries);
|
|
1549
|
+
}
|
|
1550
|
+
return value;
|
|
1551
|
+
}
|
|
1552
|
+
function node(type, fields) {
|
|
1553
|
+
return clean({
|
|
1554
|
+
"@context": SCHEMA,
|
|
1555
|
+
"@type": type,
|
|
1556
|
+
...fields
|
|
1557
|
+
}) ?? {};
|
|
1558
|
+
}
|
|
1559
|
+
/** Fraction digits of a currency; `2` for a code `Intl` does not know. */
|
|
1560
|
+
function fractionDigits(currency) {
|
|
1561
|
+
try {
|
|
1562
|
+
return new Intl.NumberFormat("en", {
|
|
1563
|
+
style: "currency",
|
|
1564
|
+
currency
|
|
1565
|
+
}).resolvedOptions().maximumFractionDigits ?? 2;
|
|
1566
|
+
} catch {
|
|
1567
|
+
return 2;
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
/** The amount as the number written in an offer: rounded to the currency's own digits. */
|
|
1571
|
+
function ldPrice(amount, currency) {
|
|
1572
|
+
return Number(amount.toFixed(fractionDigits(currency)));
|
|
1573
|
+
}
|
|
1574
|
+
/**
|
|
1575
|
+
* The GTIN if `value` is a valid GTIN-8/12/13/14 (digits only, GS1 check digit correct), else
|
|
1576
|
+
* `null`. A barcode field is free text, so anything else (an internal code, a mistyped digit) is
|
|
1577
|
+
* left out rather than sent to a crawler as an identifier.
|
|
1578
|
+
*/
|
|
1579
|
+
function validGtin(value) {
|
|
1580
|
+
const digits = (value ?? "").replace(/[\s-]/g, "");
|
|
1581
|
+
if (!/^\d+$/.test(digits) || ![
|
|
1582
|
+
8,
|
|
1583
|
+
12,
|
|
1584
|
+
13,
|
|
1585
|
+
14
|
|
1586
|
+
].includes(digits.length)) return null;
|
|
1587
|
+
let sum = 0;
|
|
1588
|
+
for (let i = digits.length - 2, weight = 3; i >= 0; i--, weight = weight === 3 ? 1 : 3) sum += Number(digits[i]) * weight;
|
|
1589
|
+
return (10 - sum % 10) % 10 === Number(digits[digits.length - 1]) ? digits : null;
|
|
1590
|
+
}
|
|
1591
|
+
function offerOf(variant, currency, extra = {}) {
|
|
1592
|
+
const price = ldPrice(variant.price, currency);
|
|
1593
|
+
const listPrice = variant.compareAt === null || variant.compareAt === void 0 ? void 0 : ldPrice(variant.compareAt, currency);
|
|
1594
|
+
return {
|
|
1595
|
+
"@type": "Offer",
|
|
1596
|
+
url: variant.url,
|
|
1597
|
+
price,
|
|
1598
|
+
priceCurrency: currency,
|
|
1599
|
+
availability: AVAILABILITY_URL[variant.availability],
|
|
1600
|
+
priceValidUntil: variant.priceValidUntil,
|
|
1601
|
+
...listPrice !== void 0 && listPrice > price ? { priceSpecification: {
|
|
1602
|
+
"@type": "UnitPriceSpecification",
|
|
1603
|
+
priceType: `${SCHEMA}/ListPrice`,
|
|
1604
|
+
price: listPrice,
|
|
1605
|
+
priceCurrency: currency
|
|
1606
|
+
} } : {},
|
|
1607
|
+
...extra
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1611
|
+
* A `Product`. One variant, or several at one price, is an `Offer`; variants at different prices
|
|
1612
|
+
* are an `AggregateOffer` (`lowPrice`, `highPrice`, `offerCount`, one `Offer` each). With no
|
|
1613
|
+
* currency or no variants the node carries no offers at all.
|
|
1614
|
+
*/
|
|
1615
|
+
function buildProductLd(input) {
|
|
1616
|
+
const currency = (input.currency ?? "").trim();
|
|
1617
|
+
const variants = input.variants.filter((variant) => Number.isFinite(variant.price));
|
|
1618
|
+
const single = variants.length === 1 ? variants[0] : void 0;
|
|
1619
|
+
const identity = (variant) => ({
|
|
1620
|
+
sku: variant.sku,
|
|
1621
|
+
gtin: validGtin(variant.gtin)
|
|
1622
|
+
});
|
|
1623
|
+
let offers;
|
|
1624
|
+
if (currency !== "" && variants.length > 0) {
|
|
1625
|
+
const prices = variants.map((variant) => ldPrice(variant.price, currency));
|
|
1626
|
+
const low = Math.min(...prices);
|
|
1627
|
+
const high = Math.max(...prices);
|
|
1628
|
+
if (low === high) offers = offerOf(variants.reduce((a, b) => AVAILABILITY_RANK[b.availability] > AVAILABILITY_RANK[a.availability] ? b : a), currency, single === void 0 ? {} : identity(single));
|
|
1629
|
+
else offers = {
|
|
1630
|
+
"@type": "AggregateOffer",
|
|
1631
|
+
lowPrice: low,
|
|
1632
|
+
highPrice: high,
|
|
1633
|
+
priceCurrency: currency,
|
|
1634
|
+
offerCount: variants.length,
|
|
1635
|
+
offers: variants.map((variant) => offerOf(variant, currency, identity(variant)))
|
|
1636
|
+
};
|
|
1637
|
+
}
|
|
1638
|
+
const ratings = input.ratings !== null && input.ratings !== void 0 && input.ratings.count > 0 && Number.isFinite(input.ratings.value) ? {
|
|
1639
|
+
"@type": "AggregateRating",
|
|
1640
|
+
ratingValue: input.ratings.value,
|
|
1641
|
+
reviewCount: input.ratings.count
|
|
1642
|
+
} : void 0;
|
|
1643
|
+
return node("Product", {
|
|
1644
|
+
name: input.name,
|
|
1645
|
+
url: input.url,
|
|
1646
|
+
description: input.description,
|
|
1647
|
+
image: input.images,
|
|
1648
|
+
brand: input.brand ? {
|
|
1649
|
+
"@type": "Brand",
|
|
1650
|
+
name: input.brand
|
|
1651
|
+
} : void 0,
|
|
1652
|
+
...single === void 0 ? {} : identity(single),
|
|
1653
|
+
offers,
|
|
1654
|
+
aggregateRating: ratings
|
|
1655
|
+
});
|
|
1656
|
+
}
|
|
1657
|
+
/** A `BreadcrumbList`, root first. Every level carries its URL, the last one included. */
|
|
1658
|
+
function buildBreadcrumbLd(items) {
|
|
1659
|
+
return node("BreadcrumbList", { itemListElement: items.filter((item) => item.name.trim() !== "").map((item, index) => ({
|
|
1660
|
+
"@type": "ListItem",
|
|
1661
|
+
position: index + 1,
|
|
1662
|
+
name: item.name,
|
|
1663
|
+
item: item.url
|
|
1664
|
+
})) });
|
|
1665
|
+
}
|
|
1666
|
+
/** An `ItemList` of the things a listing page shows, in the order shown. */
|
|
1667
|
+
function buildItemListLd(items) {
|
|
1668
|
+
return node("ItemList", { itemListElement: items.map((item, index) => ({
|
|
1669
|
+
"@type": "ListItem",
|
|
1670
|
+
position: index + 1,
|
|
1671
|
+
url: item.url,
|
|
1672
|
+
name: item.name
|
|
1673
|
+
})) });
|
|
1674
|
+
}
|
|
1675
|
+
function buildOrganizationLd(input) {
|
|
1676
|
+
const contact = input.contact;
|
|
1677
|
+
return node("Organization", {
|
|
1678
|
+
name: input.name,
|
|
1679
|
+
url: input.url,
|
|
1680
|
+
logo: input.logo,
|
|
1681
|
+
sameAs: input.sameAs,
|
|
1682
|
+
contactPoint: contact && (contact.email || contact.telephone) ? {
|
|
1683
|
+
"@type": "ContactPoint",
|
|
1684
|
+
contactType: "customer service",
|
|
1685
|
+
email: contact.email,
|
|
1686
|
+
telephone: contact.telephone
|
|
1687
|
+
} : void 0
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
function buildWebSiteLd(input) {
|
|
1691
|
+
const search = (input.searchPath ?? "").trim();
|
|
1692
|
+
return node("WebSite", {
|
|
1693
|
+
name: input.name,
|
|
1694
|
+
url: input.url,
|
|
1695
|
+
potentialAction: search === "" ? void 0 : {
|
|
1696
|
+
"@type": "SearchAction",
|
|
1697
|
+
target: {
|
|
1698
|
+
"@type": "EntryPoint",
|
|
1699
|
+
urlTemplate: `${trimTrailingSlashes(input.url)}${search.startsWith("/") ? "" : "/"}${search}?q={search_term_string}`
|
|
1700
|
+
},
|
|
1701
|
+
"query-input": "required name=search_term_string"
|
|
1702
|
+
}
|
|
1703
|
+
});
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* The text of `<script type="application/ld+json">`. One node is written as itself, several as an
|
|
1707
|
+
* array. `<` is written as its JSON escape (so `<\/script>` and `<!--` cannot occur) and U+2028/U+2029 are
|
|
1708
|
+
* escaped; the result is still plain JSON.
|
|
1709
|
+
*/
|
|
1710
|
+
function serializeLd(nodes) {
|
|
1711
|
+
return JSON.stringify(nodes.length === 1 ? nodes[0] : nodes).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
1712
|
+
}
|
|
1713
|
+
const LD_DESCRIPTION_MAX = 5e3;
|
|
1714
|
+
/**
|
|
1715
|
+
* A description as plain text for `description`: a string with its HTML tags dropped, or a rich-text
|
|
1716
|
+
* document (nodes with `text`/`content`) flattened, whitespace collapsed, cut at `max` characters
|
|
1717
|
+
* on a word boundary.
|
|
1718
|
+
*/
|
|
1719
|
+
function ldPlainText(value, max = LD_DESCRIPTION_MAX) {
|
|
1720
|
+
const plain = (typeof value === "string" ? stripTags(value) : flatten(value)).replace(/\s+/g, " ").trim();
|
|
1721
|
+
if (plain.length <= max) return plain;
|
|
1722
|
+
const cut = plain.slice(0, max);
|
|
1723
|
+
const space = cut.lastIndexOf(" ");
|
|
1724
|
+
return (space > max * .8 ? cut.slice(0, space) : cut).trim();
|
|
1725
|
+
}
|
|
1726
|
+
function trimTrailingSlashes(url) {
|
|
1727
|
+
let end = url.length;
|
|
1728
|
+
while (end > 0 && url[end - 1] === "/") end--;
|
|
1729
|
+
return url.slice(0, end);
|
|
1730
|
+
}
|
|
1731
|
+
/** Drops `<…>` tags in one pass (a linear scan; an unclosed `<` keeps the rest as text). */
|
|
1732
|
+
function stripTags(html) {
|
|
1733
|
+
let out = "";
|
|
1734
|
+
let i = 0;
|
|
1735
|
+
while (i < html.length) {
|
|
1736
|
+
const open = html.indexOf("<", i);
|
|
1737
|
+
if (open === -1) break;
|
|
1738
|
+
const close = html.indexOf(">", open + 1);
|
|
1739
|
+
if (close === -1) break;
|
|
1740
|
+
out += `${html.slice(i, open)} `;
|
|
1741
|
+
i = close + 1;
|
|
1742
|
+
}
|
|
1743
|
+
return out + html.slice(i);
|
|
1744
|
+
}
|
|
1745
|
+
function flatten(value) {
|
|
1746
|
+
if (typeof value !== "object" || value === null) return "";
|
|
1747
|
+
const { type, text, content } = value;
|
|
1748
|
+
if (type === "text") return typeof text === "string" ? text : "";
|
|
1749
|
+
return Array.isArray(content) ? content.map(flatten).join(" ") : "";
|
|
1750
|
+
}
|
|
1751
|
+
/** Applies the theme's opt-out and extender to the nodes a page built. Pure. */
|
|
1752
|
+
function applyStructuredDataPolicy(entries, policy, context) {
|
|
1753
|
+
const disable = policy.disable;
|
|
1754
|
+
if (disable === true) return [];
|
|
1755
|
+
const off = new Set(Array.isArray(disable) ? disable : []);
|
|
1756
|
+
const out = [];
|
|
1757
|
+
for (const entry of entries) {
|
|
1758
|
+
if (off.has(entry.type) || Object.keys(entry.node).length === 0) continue;
|
|
1759
|
+
const next = policy.extend ? policy.extend(entry.type, entry.node, context) : entry.node;
|
|
1760
|
+
if (next !== null && Object.keys(next).length > 0) out.push(next);
|
|
1761
|
+
}
|
|
1762
|
+
return out;
|
|
1763
|
+
}
|
|
1764
|
+
//#endregion
|
|
1765
|
+
export { ANALYTICS_MAX_KEY_BYTES, ANALYTICS_MAX_NAME_BYTES, ANALYTICS_MAX_PROPS, ANALYTICS_MAX_VALUE_BYTES, ANALYTICS_QUEUE_LIMIT, DEFAULT_HOME_TITLE_PATTERN, DEFAULT_IMAGE_FRAMING, DEFAULT_LAYOUT_BREAKPOINTS, DEFAULT_TITLE_PATTERN, DesignTokenValidationError, EDIT_MODE_HIDDEN_OPACITY, EldraClientError, IMAGE_FRAMING_MAX_ZOOM, IMAGE_FRAMING_MIN_ZOOM, LAYOUT_BREAKPOINTS, LD_DESCRIPTION_MAX, LayoutValidationError, MAX_DYNAMIC_ROUTE_PATTERN_BYTES, PREVIEW_ROUTER_MESSAGE_TYPES, RESERVED_THEME_IDS, RICH_TEXT_LEAF_TYPES, RICH_TEXT_MARK_ELEMENTS, RICH_TEXT_PAD_ATTR, RICH_TEXT_TOOLBAR_CONTROLS, ReusableComponentSnapshotCache, SEO_SYNTAX, SITEMAP_MAX_BYTES, SITEMAP_MAX_URLS, STRUCTURED_DATA_TYPES, THEME_ID_PATTERN, activeLayoutBreakpoint, applyDesignTokenOverrides, applyStructuredDataPolicy, blockApiIdOf, buildAlternates, buildBreadcrumbLd, buildDynamicRoutePath, buildItemListLd, buildOrganizationLd, buildProductLd, buildRichTextTree, buildRobots, buildSitemap, buildTemplateBlockRenames, buildWebSiteLd, catalogRouteTarget, clampFocal, clampImageFraming, classifyBeforeInput, computeRichTextPositions, createAnalytics, createEldraClient, createLayoutRenderModel, createOverlayRuntime, createPreviewMessageRouter, createProjectionResolver, createReusableLayoutRenderModel, createTemplateLayoutRenderModel, decodeStega, describeSelectionContext, designTokenRevisionHash, domRangeToPositions, encodeEntryDataStega, encodeStega, escapeXml, focalBand, framingDrag, framingZoom, generateDesignTokenCss, generateLayoutCss, generateTailwindThemeCss, getRegisteredThemeId, hiddenLayoutBreakpoints, imageFramingAttrs, imageFramingStyle, isBlockFieldLocalized, layoutIdentityOf, layoutNodeClass, layoutRenderNodeId, ldPlainText, ldPrice, matchDynamicRoutePattern, normalizeAnalyticsProps, normalizeColorSelection, normalizeImageFraming, normalizeLayoutDocument, normalizeSiteDesignTokenOverrides, normalizeThemeDesignTokens, parseDynamicRoutePattern, parseImageFramingValueAttr, pickSeoLocale, projectEntryDataLocale, registerBlockFields, registerThemeId, renderSeoTitle, resolveColorSelection, resolveDesignTokenCatalog, resolveDomPoint, resolveDomPosition, resolveLayoutBreakpoints, resolveLayoutDocument, resolvePagePath, resolveRoute, resolveSeo, responsiveValue, restampRichTextPositions, richTextMarkNameOf, richTextNodeSize, richTextText, safeHref, serializeLd, siteOrigin, sitemapLastmod, stripStega, substituteSeoPattern, themeSchemaApiId, tidySeoTitle, truncateUtf8, unscaledFrameRect, validGtin, validateLayoutDocument };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as TemplateLayoutDocument, c as TemplateLayoutRenderNode, i as TemplateLayoutContext, l as buildTemplateBlockRenames, n as TemplateBlockFieldDefinition, o as TemplateLayoutNode, r as TemplateBlockNode, s as TemplateLayoutRenderModel, t as TemplateBlockDefinition, u as createTemplateLayoutRenderModel } from "./templateLayout-
|
|
1
|
+
import { a as TemplateLayoutDocument, c as TemplateLayoutRenderNode, i as TemplateLayoutContext, l as buildTemplateBlockRenames, n as TemplateBlockFieldDefinition, o as TemplateLayoutNode, r as TemplateBlockNode, s as TemplateLayoutRenderModel, t as TemplateBlockDefinition, u as createTemplateLayoutRenderModel } from "./templateLayout-7rT_TH_E.js";
|
|
2
2
|
import { n as ReusableComponentPlacement, o as ReusableRenderIdentity, r as ReusableComponentProjection } from "./reusableExpansion-CXvs_ckx.js";
|
|
3
3
|
export { type ReusableComponentPlacement, type ReusableComponentProjection, type ReusableRenderIdentity, TemplateBlockDefinition, TemplateBlockFieldDefinition, TemplateBlockNode, TemplateLayoutContext, TemplateLayoutDocument, TemplateLayoutNode, TemplateLayoutRenderModel, TemplateLayoutRenderNode, buildTemplateBlockRenames, createTemplateLayoutRenderModel };
|
|
@@ -26,6 +26,13 @@ interface EldraClientOptions {
|
|
|
26
26
|
stega?: boolean;
|
|
27
27
|
fetch?: typeof globalThis.fetch;
|
|
28
28
|
retry?: EldraRetryOptions;
|
|
29
|
+
/**
|
|
30
|
+
* The organisation's read-only build token (`eldra_bld_…`, Studio → Settings → Developers →
|
|
31
|
+
* Build tokens), sent as `X-Eldra-Build-Token` on every request so the gateway counts a
|
|
32
|
+
* theme build's reads against the build's own rate-limit budget. Server and build only: never
|
|
33
|
+
* pass it from browser code or a public config. Omitted or empty sends no header.
|
|
34
|
+
*/
|
|
35
|
+
buildToken?: string;
|
|
29
36
|
/**
|
|
30
37
|
* The organisation's default content locale (e.g. `"en-US"`). A `link`
|
|
31
38
|
* field's value is a per-locale record, and this drives a per-field
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eldrajs/theme-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Framework-free core of the Eldra theme SDK: the Studio preview bridge, stega encoding, the overlay runtime, layout CSS, rich-text positions, design tokens and image framing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|