@vectoriox/iox-ui 4.33.0 → 4.34.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectoriox/iox-ui",
3
- "version": "4.33.0",
3
+ "version": "4.34.0",
4
4
  "peerDependencies": {
5
5
  "@angular/common": ">=20.0.0",
6
6
  "@angular/core": ">=20.0.0",
@@ -22,6 +22,10 @@
22
22
  "./forms-core": {
23
23
  "types": "./forms-core/index.d.ts",
24
24
  "default": "./fesm2022/vectoriox-iox-ui-forms-core.mjs"
25
+ },
26
+ "./seo-core": {
27
+ "types": "./seo-core/index.d.ts",
28
+ "default": "./fesm2022/vectoriox-iox-ui-seo-core.mjs"
25
29
  }
26
30
  },
27
31
  "sideEffects": false
@@ -0,0 +1,135 @@
1
+ /**
2
+ * The canonical shape of a page's SEO metadata, plus the flat tag list both renderers emit.
3
+ *
4
+ * ⚠️ This file is the ONLY declaration of that shape. Before it existed, `iox-cms` stored
5
+ * `seo.og.title` while the SSR engine read a flat `seo.ogTitle`, so no Open Graph tag had ever been
6
+ * emitted, and `iox-cms-client` carried a third, hand-copied variant of the same schema. See
7
+ * iox-ai-guidance `architecture/cms/seo-plan.md`.
8
+ */
9
+ /** Open Graph subset we author and emit. */
10
+ interface SeoOg {
11
+ title?: string;
12
+ description?: string;
13
+ image?: string;
14
+ }
15
+ /** Twitter-card subset. Emitted only when `card` is set — see `seoToTags`. */
16
+ interface SeoTwitter {
17
+ card?: string;
18
+ title?: string;
19
+ description?: string;
20
+ image?: string;
21
+ }
22
+ /** Sitemap participation for this page. Consumed by the sitemap route (plan phase 3). */
23
+ interface SeoSitemap {
24
+ include?: boolean;
25
+ priority?: number;
26
+ changeFreq?: string;
27
+ }
28
+ /**
29
+ * A page's stored SEO metadata, normalized.
30
+ *
31
+ * `keywords` has no authoring field — search engines have ignored the tag for over a decade — but
32
+ * it is read and emitted when a document already carries one, because the engine used to read it.
33
+ */
34
+ interface SeoDoc {
35
+ title?: string;
36
+ description?: string;
37
+ keywords?: string;
38
+ canonicalUrl?: string;
39
+ robots?: string;
40
+ og?: SeoOg;
41
+ twitter?: SeoTwitter;
42
+ structuredData?: unknown;
43
+ sitemap?: SeoSitemap;
44
+ }
45
+ /** `<title>`. */
46
+ interface SeoTitleTag {
47
+ kind: 'title';
48
+ content: string;
49
+ }
50
+ /**
51
+ * A `<meta>` tag. `attr` says which attribute identifies it — Open Graph is addressed by
52
+ * `property`, everything else by `name`. Both renderers need that distinction to update rather
53
+ * than duplicate a tag.
54
+ */
55
+ interface SeoMetaTag {
56
+ kind: 'meta';
57
+ attr: 'name' | 'property';
58
+ key: string;
59
+ content: string;
60
+ }
61
+ /** A `<link>`, currently only `rel="canonical"`. */
62
+ interface SeoLinkTag {
63
+ kind: 'link';
64
+ rel: string;
65
+ href: string;
66
+ }
67
+ type SeoTag = SeoTitleTag | SeoMetaTag | SeoLinkTag;
68
+ /** Context that lets `seoToTags` fill gaps without reaching for the DOM or a data source. */
69
+ interface SeoTagContext {
70
+ /** Used as `<title>` when the document has none — usually the page name. */
71
+ fallbackTitle?: string;
72
+ }
73
+ /** Recommended maximum before search results truncate the title. */
74
+ declare const SEO_TITLE_MAX = 60;
75
+ /** Recommended maximum before search results truncate the description. */
76
+ declare const SEO_DESCRIPTION_MAX = 160;
77
+ declare const SEO_ROBOTS_OPTIONS: ReadonlyArray<{
78
+ label: string;
79
+ value: string;
80
+ }>;
81
+ declare const SEO_TWITTER_CARD_OPTIONS: ReadonlyArray<{
82
+ label: string;
83
+ value: string;
84
+ }>;
85
+ declare const SEO_CHANGE_FREQ_OPTIONS: ReadonlyArray<{
86
+ label: string;
87
+ value: string;
88
+ }>;
89
+
90
+ /**
91
+ * Coerce whatever a page document happens to hold into a `SeoDoc`.
92
+ *
93
+ * Every consumer calls this before reading `seo`, because four shapes are in the wild:
94
+ * • the current nested shape (`og.title`);
95
+ * • the flat shape the SSR engine used to read (`ogTitle`) — never actually written, but a
96
+ * document hand-edited against the old engine code could carry it;
97
+ * • `""` for "not set", which must not become an empty `<meta>`;
98
+ * • `{ override: '…' }`, the per-field value object that plan phase 2 introduces — tolerated here
99
+ * so the ladder can land without a second normalizer.
100
+ *
101
+ * Empty branches are dropped rather than left as `{}`, so `if (seo.og)` is a meaningful test.
102
+ */
103
+ declare function normalizeSeoDoc(raw: unknown): SeoDoc;
104
+
105
+ /**
106
+ * Turn a page's SEO document into the flat list of head tags to emit.
107
+ *
108
+ * Both renderers call this, so a page cannot describe itself differently to a crawler than the
109
+ * builder previews. The order is fixed and part of the contract: title, description, keywords,
110
+ * canonical, Open Graph, Twitter, robots.
111
+ *
112
+ * Fallbacks are deliberately shallow — `og:title` reuses the page title, `twitter:*` reuses the
113
+ * Open Graph values — because a social scraper that finds no `og:title` falls back to `<title>`
114
+ * itself, and duplicating a value we did not author only makes the drift harder to see. The
115
+ * "derive from the page content" half of the ladder (first h1, first paragraph, first image) is
116
+ * `resolveSeo`, which runs BEFORE this and hands its output in as a filled-in `SeoDoc`.
117
+ */
118
+ declare function seoToTags(seo: SeoDoc | unknown, ctx?: SeoTagContext): SeoTag[];
119
+
120
+ /**
121
+ * The authoring schema for the `seo` object, in the platform's standard property dialect: `label`
122
+ * at property level, rendering metadata under `controller`.
123
+ *
124
+ * ONE builder, two callers: `iox-cms` spreads it into `PagesSchema` (the stored schema) and
125
+ * `iox-cms-client` feeds it to `<dynamic-form>`. Those used to be two hand-written copies that had
126
+ * already drifted — different controller types for the same field, and the client's copy missing
127
+ * `structuredData` entirely.
128
+ *
129
+ * `keywords` is deliberately absent: the tag is emitted when a document carries one, but there is
130
+ * no reason to invite new ones.
131
+ */
132
+ declare function buildSeoSchemaProperties(): Record<string, unknown>;
133
+
134
+ export { SEO_CHANGE_FREQ_OPTIONS, SEO_DESCRIPTION_MAX, SEO_ROBOTS_OPTIONS, SEO_TITLE_MAX, SEO_TWITTER_CARD_OPTIONS, buildSeoSchemaProperties, normalizeSeoDoc, seoToTags };
135
+ export type { SeoDoc, SeoLinkTag, SeoMetaTag, SeoOg, SeoSitemap, SeoTag, SeoTagContext, SeoTitleTag, SeoTwitter };
@@ -0,0 +1,3 @@
1
+ {
2
+ "module": "../fesm2022/vectoriox-iox-ui-seo-core.mjs"
3
+ }
@@ -0,0 +1,125 @@
1
+ import { SeoDoc, SeoOg, SeoSitemap, SeoTwitter } from './seo.model';
2
+
3
+ /**
4
+ * Coerce whatever a page document happens to hold into a `SeoDoc`.
5
+ *
6
+ * Every consumer calls this before reading `seo`, because four shapes are in the wild:
7
+ * • the current nested shape (`og.title`);
8
+ * • the flat shape the SSR engine used to read (`ogTitle`) — never actually written, but a
9
+ * document hand-edited against the old engine code could carry it;
10
+ * • `""` for "not set", which must not become an empty `<meta>`;
11
+ * • `{ override: '…' }`, the per-field value object that plan phase 2 introduces — tolerated here
12
+ * so the ladder can land without a second normalizer.
13
+ *
14
+ * Empty branches are dropped rather than left as `{}`, so `if (seo.og)` is a meaningful test.
15
+ */
16
+ export function normalizeSeoDoc(raw: unknown): SeoDoc {
17
+ const src = asRecord(raw);
18
+ if (!src) return {};
19
+
20
+ const og = compact<SeoOg>({
21
+ title: str(pick(src, 'og', 'title') ?? src['ogTitle']),
22
+ description: str(pick(src, 'og', 'description') ?? src['ogDescription']),
23
+ image: str(pick(src, 'og', 'image') ?? src['ogImage']),
24
+ });
25
+
26
+ const twitter = compact<SeoTwitter>({
27
+ card: str(pick(src, 'twitter', 'card')),
28
+ title: str(pick(src, 'twitter', 'title')),
29
+ description: str(pick(src, 'twitter', 'description')),
30
+ image: str(pick(src, 'twitter', 'image')),
31
+ });
32
+
33
+ const sitemap = compact<SeoSitemap>({
34
+ include: bool(pick(src, 'sitemap', 'include')),
35
+ priority: num(pick(src, 'sitemap', 'priority')),
36
+ changeFreq: str(pick(src, 'sitemap', 'changeFreq')),
37
+ });
38
+
39
+ const structuredData = structured(src['structuredData']);
40
+
41
+ const doc = compact<SeoDoc>({
42
+ title: str(src['title']),
43
+ description: str(src['description']),
44
+ keywords: str(src['keywords']),
45
+ canonicalUrl: str(src['canonicalUrl']),
46
+ robots: str(src['robots']),
47
+ og,
48
+ twitter,
49
+ sitemap,
50
+ structuredData,
51
+ });
52
+
53
+ return doc ?? {};
54
+ }
55
+
56
+ /** Read `src[branch][leaf]` without assuming the branch exists or is an object. */
57
+ function pick(src: Record<string, unknown>, branch: string, leaf: string): unknown {
58
+ const nested = asRecord(src[branch]);
59
+ return nested ? nested[leaf] : undefined;
60
+ }
61
+
62
+ /**
63
+ * A field's value as a trimmed string, or `undefined`.
64
+ *
65
+ * Unwraps the phase-2 value object: a bound or auto field has no `override`, so it correctly
66
+ * resolves to `undefined` here and the binding layer fills it in later.
67
+ */
68
+ function str(value: unknown): string | undefined {
69
+ const wrapper = asRecord(value);
70
+ const raw = wrapper ? wrapper['override'] : value;
71
+ if (typeof raw === 'number') return String(raw);
72
+ if (typeof raw !== 'string') return undefined;
73
+ const trimmed = raw.trim();
74
+ return trimmed.length ? trimmed : undefined;
75
+ }
76
+
77
+ /**
78
+ * `UIFormToDTO` can hand back `"true"` / `"false"` for a switch (see
79
+ * `architecture/cms/shop.md` — the boolean/number coercion pitfall), so accept both.
80
+ */
81
+ function bool(value: unknown): boolean | undefined {
82
+ if (typeof value === 'boolean') return value;
83
+ if (value === 'true') return true;
84
+ if (value === 'false') return false;
85
+ return undefined;
86
+ }
87
+
88
+ function num(value: unknown): number | undefined {
89
+ if (typeof value === 'number') return Number.isFinite(value) ? value : undefined;
90
+ if (typeof value !== 'string' || !value.trim().length) return undefined;
91
+ const parsed = Number(value);
92
+ return Number.isFinite(parsed) ? parsed : undefined;
93
+ }
94
+
95
+ /** JSON-LD is stored as an object or as a JSON string from the `json` controller. */
96
+ function structured(value: unknown): unknown {
97
+ if (typeof value === 'string') {
98
+ const trimmed = value.trim();
99
+ if (!trimmed.length) return undefined;
100
+ try {
101
+ return JSON.parse(trimmed);
102
+ } catch {
103
+ return undefined;
104
+ }
105
+ }
106
+ if (Array.isArray(value)) return value.length ? value : undefined;
107
+ const record = asRecord(value);
108
+ return record && Object.keys(record).length ? record : undefined;
109
+ }
110
+
111
+ function asRecord(value: unknown): Record<string, unknown> | undefined {
112
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
113
+ ? (value as Record<string, unknown>)
114
+ : undefined;
115
+ }
116
+
117
+ /** Drop `undefined` values and empty nested objects, so absence is always `undefined`. */
118
+ function compact<T extends object>(value: Record<string, unknown>): T | undefined {
119
+ const out: Record<string, unknown> = {};
120
+ for (const [key, entry] of Object.entries(value)) {
121
+ if (entry === undefined) continue;
122
+ out[key] = entry;
123
+ }
124
+ return (Object.keys(out).length ? out : undefined) as T | undefined;
125
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * @vectoriox/iox-ui/seo-core — the shared, FRAMEWORK-FREE core of page SEO.
3
+ *
4
+ * ⚠️ Nothing in this entry point may import Angular, RxJS, the DOM, or Node. It is consumed by
5
+ * THREE runtimes: the builder panel (Angular), the SSR engine (Angular), and `iox-cms` (NestJS,
6
+ * plain Node) — the same reason `forms-core` exists.
7
+ *
8
+ * A page describes itself to a crawler exactly once: `seoToTags` is the only place that decides
9
+ * which head tags a page emits, and `buildSeoSchemaProperties` the only place that declares what an
10
+ * author can fill in. See iox-ai-guidance `architecture/cms/seo-plan.md`.
11
+ */
12
+
13
+ export * from './seo.model';
14
+ export * from './normalize';
15
+ export * from './tags';
16
+ export * from './schema';
@@ -0,0 +1,140 @@
1
+ import {
2
+ SEO_CHANGE_FREQ_OPTIONS,
3
+ SEO_DESCRIPTION_MAX,
4
+ SEO_ROBOTS_OPTIONS,
5
+ SEO_TITLE_MAX,
6
+ SEO_TWITTER_CARD_OPTIONS,
7
+ } from './seo.model';
8
+
9
+ /**
10
+ * The authoring schema for the `seo` object, in the platform's standard property dialect: `label`
11
+ * at property level, rendering metadata under `controller`.
12
+ *
13
+ * ONE builder, two callers: `iox-cms` spreads it into `PagesSchema` (the stored schema) and
14
+ * `iox-cms-client` feeds it to `<dynamic-form>`. Those used to be two hand-written copies that had
15
+ * already drifted — different controller types for the same field, and the client's copy missing
16
+ * `structuredData` entirely.
17
+ *
18
+ * `keywords` is deliberately absent: the tag is emitted when a document carries one, but there is
19
+ * no reason to invite new ones.
20
+ */
21
+ export function buildSeoSchemaProperties(): Record<string, unknown> {
22
+ return {
23
+ title: {
24
+ type: 'string',
25
+ label: 'Meta Title',
26
+ controller: {
27
+ type: 'text',
28
+ placeholder: 'Page title for search engines',
29
+ maxLength: SEO_TITLE_MAX,
30
+ },
31
+ },
32
+ description: {
33
+ type: 'string',
34
+ label: 'Meta Description',
35
+ controller: {
36
+ type: 'textarea',
37
+ placeholder: 'Brief description for search results',
38
+ maxLength: SEO_DESCRIPTION_MAX,
39
+ },
40
+ },
41
+ canonicalUrl: {
42
+ type: 'string',
43
+ label: 'Canonical URL',
44
+ controller: {
45
+ type: 'text',
46
+ placeholder: 'https://example.com/page',
47
+ },
48
+ },
49
+ robots: {
50
+ type: 'string',
51
+ label: 'Robots',
52
+ controller: {
53
+ type: 'select',
54
+ options: SEO_ROBOTS_OPTIONS.map(option => ({ ...option })),
55
+ },
56
+ },
57
+ og: {
58
+ type: 'object',
59
+ label: 'Open Graph',
60
+ controller: { type: 'object' },
61
+ properties: {
62
+ title: {
63
+ type: 'string',
64
+ label: 'OG Title',
65
+ controller: { type: 'text', placeholder: 'Title for social sharing' },
66
+ },
67
+ description: {
68
+ type: 'string',
69
+ label: 'OG Description',
70
+ controller: { type: 'textarea', placeholder: 'Description for social sharing' },
71
+ },
72
+ image: {
73
+ type: 'string',
74
+ label: 'OG Image',
75
+ controller: { type: 'image' },
76
+ },
77
+ },
78
+ },
79
+ twitter: {
80
+ type: 'object',
81
+ label: 'Twitter Card',
82
+ controller: { type: 'object' },
83
+ properties: {
84
+ card: {
85
+ type: 'string',
86
+ label: 'Card Type',
87
+ controller: {
88
+ type: 'select',
89
+ options: SEO_TWITTER_CARD_OPTIONS.map(option => ({ ...option })),
90
+ },
91
+ },
92
+ title: {
93
+ type: 'string',
94
+ label: 'Twitter Title',
95
+ controller: { type: 'text' },
96
+ },
97
+ description: {
98
+ type: 'string',
99
+ label: 'Twitter Description',
100
+ controller: { type: 'textarea' },
101
+ },
102
+ image: {
103
+ type: 'string',
104
+ label: 'Twitter Image',
105
+ controller: { type: 'image' },
106
+ },
107
+ },
108
+ },
109
+ structuredData: {
110
+ type: 'object',
111
+ label: 'Structured Data (JSON-LD)',
112
+ controller: { type: 'json' },
113
+ },
114
+ sitemap: {
115
+ type: 'object',
116
+ label: 'Sitemap Settings',
117
+ controller: { type: 'object' },
118
+ properties: {
119
+ include: {
120
+ type: 'boolean',
121
+ label: 'Include in Sitemap',
122
+ controller: { type: 'switch' },
123
+ },
124
+ priority: {
125
+ type: 'number',
126
+ label: 'Priority',
127
+ controller: { type: 'range', options: { min: 0, max: 1, step: 0.1 } },
128
+ },
129
+ changeFreq: {
130
+ type: 'string',
131
+ label: 'Change Frequency',
132
+ controller: {
133
+ type: 'select',
134
+ options: SEO_CHANGE_FREQ_OPTIONS.map(option => ({ ...option })),
135
+ },
136
+ },
137
+ },
138
+ },
139
+ };
140
+ }
@@ -0,0 +1,111 @@
1
+ /**
2
+ * The canonical shape of a page's SEO metadata, plus the flat tag list both renderers emit.
3
+ *
4
+ * ⚠️ This file is the ONLY declaration of that shape. Before it existed, `iox-cms` stored
5
+ * `seo.og.title` while the SSR engine read a flat `seo.ogTitle`, so no Open Graph tag had ever been
6
+ * emitted, and `iox-cms-client` carried a third, hand-copied variant of the same schema. See
7
+ * iox-ai-guidance `architecture/cms/seo-plan.md`.
8
+ */
9
+
10
+ /** Open Graph subset we author and emit. */
11
+ export interface SeoOg {
12
+ title?: string;
13
+ description?: string;
14
+ image?: string;
15
+ }
16
+
17
+ /** Twitter-card subset. Emitted only when `card` is set — see `seoToTags`. */
18
+ export interface SeoTwitter {
19
+ card?: string;
20
+ title?: string;
21
+ description?: string;
22
+ image?: string;
23
+ }
24
+
25
+ /** Sitemap participation for this page. Consumed by the sitemap route (plan phase 3). */
26
+ export interface SeoSitemap {
27
+ include?: boolean;
28
+ priority?: number;
29
+ changeFreq?: string;
30
+ }
31
+
32
+ /**
33
+ * A page's stored SEO metadata, normalized.
34
+ *
35
+ * `keywords` has no authoring field — search engines have ignored the tag for over a decade — but
36
+ * it is read and emitted when a document already carries one, because the engine used to read it.
37
+ */
38
+ export interface SeoDoc {
39
+ title?: string;
40
+ description?: string;
41
+ keywords?: string;
42
+ canonicalUrl?: string;
43
+ robots?: string;
44
+ og?: SeoOg;
45
+ twitter?: SeoTwitter;
46
+ structuredData?: unknown;
47
+ sitemap?: SeoSitemap;
48
+ }
49
+
50
+ /** `<title>`. */
51
+ export interface SeoTitleTag {
52
+ kind: 'title';
53
+ content: string;
54
+ }
55
+
56
+ /**
57
+ * A `<meta>` tag. `attr` says which attribute identifies it — Open Graph is addressed by
58
+ * `property`, everything else by `name`. Both renderers need that distinction to update rather
59
+ * than duplicate a tag.
60
+ */
61
+ export interface SeoMetaTag {
62
+ kind: 'meta';
63
+ attr: 'name' | 'property';
64
+ key: string;
65
+ content: string;
66
+ }
67
+
68
+ /** A `<link>`, currently only `rel="canonical"`. */
69
+ export interface SeoLinkTag {
70
+ kind: 'link';
71
+ rel: string;
72
+ href: string;
73
+ }
74
+
75
+ export type SeoTag = SeoTitleTag | SeoMetaTag | SeoLinkTag;
76
+
77
+ /** Context that lets `seoToTags` fill gaps without reaching for the DOM or a data source. */
78
+ export interface SeoTagContext {
79
+ /** Used as `<title>` when the document has none — usually the page name. */
80
+ fallbackTitle?: string;
81
+ }
82
+
83
+ /** Recommended maximum before search results truncate the title. */
84
+ export const SEO_TITLE_MAX = 60;
85
+
86
+ /** Recommended maximum before search results truncate the description. */
87
+ export const SEO_DESCRIPTION_MAX = 160;
88
+
89
+ export const SEO_ROBOTS_OPTIONS: ReadonlyArray<{ label: string; value: string }> = [
90
+ { label: 'Index, Follow', value: 'index, follow' },
91
+ { label: 'Index, No Follow', value: 'index, nofollow' },
92
+ { label: 'No Index, Follow', value: 'noindex, follow' },
93
+ { label: 'No Index, No Follow', value: 'noindex, nofollow' },
94
+ ];
95
+
96
+ export const SEO_TWITTER_CARD_OPTIONS: ReadonlyArray<{ label: string; value: string }> = [
97
+ { label: 'Summary', value: 'summary' },
98
+ { label: 'Summary Large Image', value: 'summary_large_image' },
99
+ { label: 'App', value: 'app' },
100
+ { label: 'Player', value: 'player' },
101
+ ];
102
+
103
+ export const SEO_CHANGE_FREQ_OPTIONS: ReadonlyArray<{ label: string; value: string }> = [
104
+ { label: 'Always', value: 'always' },
105
+ { label: 'Hourly', value: 'hourly' },
106
+ { label: 'Daily', value: 'daily' },
107
+ { label: 'Weekly', value: 'weekly' },
108
+ { label: 'Monthly', value: 'monthly' },
109
+ { label: 'Yearly', value: 'yearly' },
110
+ { label: 'Never', value: 'never' },
111
+ ];
@@ -0,0 +1,57 @@
1
+ import { SeoDoc, SeoTag, SeoTagContext } from './seo.model';
2
+ import { normalizeSeoDoc } from './normalize';
3
+
4
+ /**
5
+ * Turn a page's SEO document into the flat list of head tags to emit.
6
+ *
7
+ * Both renderers call this, so a page cannot describe itself differently to a crawler than the
8
+ * builder previews. The order is fixed and part of the contract: title, description, keywords,
9
+ * canonical, Open Graph, Twitter, robots.
10
+ *
11
+ * Fallbacks are deliberately shallow — `og:title` reuses the page title, `twitter:*` reuses the
12
+ * Open Graph values — because a social scraper that finds no `og:title` falls back to `<title>`
13
+ * itself, and duplicating a value we did not author only makes the drift harder to see. The
14
+ * "derive from the page content" half of the ladder (first h1, first paragraph, first image) is
15
+ * `resolveSeo`, which runs BEFORE this and hands its output in as a filled-in `SeoDoc`.
16
+ */
17
+ export function seoToTags(seo: SeoDoc | unknown, ctx: SeoTagContext = {}): SeoTag[] {
18
+ const doc = normalizeSeoDoc(seo);
19
+ const tags: SeoTag[] = [];
20
+
21
+ const title = doc.title ?? trimmed(ctx.fallbackTitle);
22
+ if (title) tags.push({ kind: 'title', content: title });
23
+ if (doc.description) tags.push({ kind: 'meta', attr: 'name', key: 'description', content: doc.description });
24
+ if (doc.keywords) tags.push({ kind: 'meta', attr: 'name', key: 'keywords', content: doc.keywords });
25
+ if (doc.canonicalUrl) tags.push({ kind: 'link', rel: 'canonical', href: doc.canonicalUrl });
26
+
27
+ // Open Graph. `og:url` reuses the canonical URL, which is what it means.
28
+ const ogTitle = doc.og?.title ?? title;
29
+ const ogDescription = doc.og?.description ?? doc.description;
30
+ if (ogTitle) tags.push({ kind: 'meta', attr: 'property', key: 'og:title', content: ogTitle });
31
+ if (ogDescription) tags.push({ kind: 'meta', attr: 'property', key: 'og:description', content: ogDescription });
32
+ if (doc.og?.image) tags.push({ kind: 'meta', attr: 'property', key: 'og:image', content: doc.og.image });
33
+ if (doc.canonicalUrl) tags.push({ kind: 'meta', attr: 'property', key: 'og:url', content: doc.canonicalUrl });
34
+
35
+ // Twitter. Emitted ONLY when a card type is chosen: without `twitter:card` the other tags are
36
+ // ignored anyway, so writing them would be noise that looks like configuration.
37
+ if (doc.twitter?.card) {
38
+ tags.push({ kind: 'meta', attr: 'name', key: 'twitter:card', content: doc.twitter.card });
39
+ const twitterTitle = doc.twitter.title ?? ogTitle;
40
+ const twitterDescription = doc.twitter.description ?? ogDescription;
41
+ const twitterImage = doc.twitter.image ?? doc.og?.image;
42
+ if (twitterTitle) tags.push({ kind: 'meta', attr: 'name', key: 'twitter:title', content: twitterTitle });
43
+ if (twitterDescription) {
44
+ tags.push({ kind: 'meta', attr: 'name', key: 'twitter:description', content: twitterDescription });
45
+ }
46
+ if (twitterImage) tags.push({ kind: 'meta', attr: 'name', key: 'twitter:image', content: twitterImage });
47
+ }
48
+
49
+ if (doc.robots) tags.push({ kind: 'meta', attr: 'name', key: 'robots', content: doc.robots });
50
+
51
+ return tags;
52
+ }
53
+
54
+ function trimmed(value: string | undefined): string | undefined {
55
+ const out = value?.trim();
56
+ return out?.length ? out : undefined;
57
+ }