@vectoriox/iox-ui 5.181.0 → 5.182.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.
@@ -6,7 +6,7 @@ import type { LegalContext } from './legal';
6
6
  import { GenerationTier, SitePlan, SitePlanSource } from './site-plan.model';
7
7
  import { SitePlanIssueCode } from './validate-site-plan';
8
8
  import { planSells } from './shop-plan';
9
- import { importedPicturesOf } from './import-plan';
9
+ import { importedPicturesOf, importRedirects } from './import-plan';
10
10
  import type { PictureSupply, TypeLed } from './type-led';
11
11
  import { isPopupNode, POPUP_GLOBAL_ID } from './popup-plan';
12
12
  import { SerializedNode, walkSerialized } from './serialized-node';
@@ -63,6 +63,9 @@ export enum BuildStep {
63
63
  Shop = 'shop',
64
64
  DataSources = 'data-sources',
65
65
  Pages = 'pages',
66
+ /** Bring my site X7: the owner's old addresses answer with a 301 to where each page and item now lives — only in a run
67
+ * whose plan was read from a site and moved something to a new address (`importRedirects`). */
68
+ Redirects = 'redirects',
66
69
  Globals = 'globals',
67
70
  Look = 'look',
68
71
  }
@@ -70,11 +73,14 @@ export enum BuildStep {
70
73
  export const BUILD_STEPS: ReadonlyArray<BuildStep> = Object.values(BuildStep);
71
74
 
72
75
  /** The steps a build of `plan` takes, in order: every one, the shop's only when the plan sells (commerce G1), the imported
73
- * pictures' only when the plan was read from a site that has some (X5). */
76
+ * pictures' only when the plan was read from a site that has some (X5), the redirects' only when it moved an old address
77
+ * (X7). */
74
78
  export function buildStepsOf(plan: unknown): BuildStep[] {
75
79
  const sells = planSells(plan);
76
80
  const pictures = importedPicturesOf(plan as SitePlan).length > 0;
77
- return BUILD_STEPS.filter(step => (step !== BuildStep.Shop || sells) && (step !== BuildStep.ImportPictures || pictures));
81
+ const redirects = importRedirects(plan as SitePlan).length > 0;
82
+ return BUILD_STEPS.filter(step => (step !== BuildStep.Shop || sells) && (step !== BuildStep.ImportPictures || pictures)
83
+ && (step !== BuildStep.Redirects || redirects));
78
84
  }
79
85
 
80
86
  export enum StepState {
@@ -105,6 +111,9 @@ export enum CreatedKind {
105
111
  /** RD3-D3 (a) Replace: a page an earlier Undo kept, moved aside (`/<route>-previous`, a draft) so the plan's page takes
106
112
  * its address — Undo puts it back while it is as the move left it and its address is free (`CreatedRecord.from`). */
107
113
  PageMoved = 'page-moved',
114
+ /** Bring my site X7: a redirect from one of the owner's old addresses (`source: 'import'`) — removed by Undo while it is
115
+ * as the build wrote it. */
116
+ Redirect = 'redirect',
108
117
  Global = 'global',
109
118
  Look = 'look',
110
119
  }
@@ -221,6 +230,10 @@ export enum BuildNoticeCode {
221
230
  * from the owner's news was not written — said once, so the owner knows the news is not on the site and where to
222
231
  * show it (Replace, or the builder). */
223
232
  PopupKept = 'popup-kept',
233
+ /** Bring my site X7: some old addresses were not redirected — a page of the site answers there, or it would chain to
234
+ * another redirect (seo-core `redirectRefusal`); said once with how many, so the owner knows those links land on the
235
+ * page that now stands there (or adds a redirect of their own). */
236
+ RedirectsRefused = 'redirects-refused',
224
237
  }
225
238
 
226
239
  /** RD3-D3 (a): what a build does with a page an earlier Undo kept at an address its plan builds — the header and footer's
@@ -430,6 +443,7 @@ export const buildKeys = {
430
443
  global: (nodeId: string) => `global:${nodeId}`,
431
444
  look: () => 'look',
432
445
  pageMoved: (pageId: string) => `page-moved:${pageId}`,
446
+ redirect: (from: string) => `redirect:${from}`,
433
447
  } as const;
434
448
 
435
449
  /** The id of the page a run made for the plan's home page, or null (not made yet, or no home page). */
@@ -469,6 +483,8 @@ export interface BuildStepFacts {
469
483
  items: number;
470
484
  /** X5: the pictures an import copies from the owner's site (0 = not an import). */
471
485
  pictures: number;
486
+ /** X7: the old addresses an import redirects (0 = not an import, or nothing moved). */
487
+ redirects: number;
472
488
  /** Commerce G1: sample products for the shop (0 = the plan sells nothing) and their categories. */
473
489
  products: number;
474
490
  categories: number;
@@ -492,6 +508,7 @@ export function buildStepFacts(plan: SitePlan, actions: Readonly<Record<string,
492
508
  contentTypeActions,
493
509
  items: plan.contentTypes.reduce((n, t) => n + (t.seed?.count ?? 0), 0),
494
510
  pictures: importedPicturesOf(plan).length,
511
+ redirects: importRedirects(plan).length,
495
512
  products: plan.shop?.products.length ?? 0,
496
513
  categories: plan.shop?.categories.length ?? 0,
497
514
  pages: plan.pages.length,
@@ -266,6 +266,9 @@ export interface PageSectionPlan {
266
266
  export interface PageSeoPlan {
267
267
  readonly title?: string;
268
268
  readonly description?: string;
269
+ /** Bring my site X6: a page the owner's old site kept out of search moves with `'noindex, follow'` (seo-core
270
+ * `SEO_ROBOTS_OPTIONS`). Only on an import plan; never a model's. */
271
+ readonly robots?: string;
269
272
  }
270
273
 
271
274
  /** The kinds of page a plan is made of (contract `site.archetypes`, L0-2). */
@@ -304,6 +307,9 @@ export interface PagePlan {
304
307
  /** The inferred need this page answers (the Plan screen tags it "we added") — a harness-core need id. */
305
308
  readonly need?: SiteNeedId;
306
309
  readonly seo?: PageSeoPlan;
310
+ /** Bring my site X7: the old address (absolute) this page's words were read from — its redirect starts there
311
+ * (`importRedirects`). Only on an import plan; never a model's. */
312
+ readonly importedFrom?: string;
307
313
  /** The page from patterns — a composed page keeps them as its fallback. */
308
314
  readonly sections: ReadonlyArray<PageSectionPlan>;
309
315
  /** M8 gate 2: the page is composed in the layout language (written with the pages; the layout step fills `layout`). */
@@ -182,6 +182,7 @@ export const SPEC_SITE_PLAN_SHAPE = {
182
182
  "template?": "string — the content type a template page renders one item of",
183
183
  "routeSource?": "string — the single source read by the route param (route.* binds it)",
184
184
  "seo?": "pageSeo",
185
+ "importedFrom?": "string — Bring my site X7: the old address (absolute) a page of the owner's words was read from (generation-core planImport) — its redirect starts there. Only on an import plan; never a model's",
185
186
  "sections": "section[] — the page from patterns; a composed page keeps them as its fallback",
186
187
  "compose?": "boolean — the page is composed in the layout language (M8 gate 2): which pages is the generation’s tier (AW-D23/24) — Basic the home page and at most one other, Award every page that is no per-item or legal page; written with the pages, the layout step fills `layout`",
187
188
  "layout?": "layoutPage — the composed page (the layout step's, never the Pages request's): when present the page is stamped from it and `sections` is not",
@@ -219,7 +220,8 @@ export const SPEC_SITE_PLAN_SHAPE = {
219
220
  },
220
221
  "pageSeo": {
221
222
  "title?": "string ≤ 60 — the page title in search results (absent = the page name · the business)",
222
- "description?": "string ≤ 160 — the line under it (absent = the tagline, else the page and the business)"
223
+ "description?": "string ≤ 160 — the line under it (absent = the tagline, else the page and the business)",
224
+ "robots?": "string — seo-core SEO_ROBOTS_OPTIONS: Bring my site X6, a page the owner's old site kept out of search ('noindex, follow'). Only on an import plan; never a model's"
223
225
  },
224
226
  "section": {
225
227
  "pattern": "string — a non-global pattern id",
@@ -1,7 +1,7 @@
1
1
  import { ARRIVE_IDS, flavorPackById, MOVE_IDS, parseHexColor, PRELOADER_IDS, SCRUB_IDS, SPEC_AXES } from '@vectoriox/iox-ui/design-core';
2
2
  import { formPresetById } from '@vectoriox/iox-ui/forms-core';
3
3
  import { filmScreensFor, normalizeFrameSequence } from '@vectoriox/iox-ui/media-core';
4
- import { SEO_DESCRIPTION_MAX, SEO_TITLE_MAX } from '@vectoriox/iox-ui/seo-core';
4
+ import { SEO_DESCRIPTION_MAX, SEO_ROBOTS_OPTIONS, SEO_TITLE_MAX } from '@vectoriox/iox-ui/seo-core';
5
5
 
6
6
  import {
7
7
  BindScope, patternById, patternHasForm, patternLinkSlots, patternNeedsBinding, patternOptionalParts, patternRoleNeeds, patternTakesBinding, patternScopes,
@@ -152,6 +152,7 @@ const DESIGN_KEYS = shapeKeys(SHAPE['design']);
152
152
  const CONTENT_TYPE_KEYS = shapeKeys(SHAPE['contentType']);
153
153
  const ROLE_KEYS = shapeKeys(SHAPE['roles']);
154
154
  const PAGE_SEO_KEYS = shapeKeys(SHAPE['pageSeo']);
155
+ const SEO_ROBOTS_KEY = 'robots';
155
156
  const ARRAY_TYPE = 'array';
156
157
  const FIELD_KEYS = shapeKeys(SHAPE['field']);
157
158
  const SLUG_FIELD = 'slug';
@@ -586,6 +587,7 @@ function validatePages(c: Collector, list: unknown[], types: Map<string, Content
586
587
  const archetype = c.string(raw, 'archetype', path, false);
587
588
  if (archetype && !has(PAGE_ARCHETYPES, archetype)) c.add(SitePlanIssueCode.Archetype, `${path}.archetype`, `"${archetype}" is not a page type (${Object.keys(PAGE_ARCHETYPES).join(', ')})`);
588
589
  validatePageSeo(c, raw['seo'], `${path}.seo`);
590
+ c.string(raw, IMPORTED_FROM, path, false);
589
591
  const need = c.string(raw, 'need', path, false);
590
592
  if (need && !(SITE_NEED_IDS as ReadonlyArray<string>).includes(need)) c.add(SitePlanIssueCode.UnknownNeed, `${path}.need`, `"${need}" is not a need (${SITE_NEED_IDS.join(', ')})`);
591
593
 
@@ -753,7 +755,9 @@ function validatePageSeo(c: Collector, seo: unknown, path: string): void {
753
755
  const limits: Readonly<Record<string, number>> = { title: SEO_TITLE_MAX, description: SEO_DESCRIPTION_MAX };
754
756
  for (const key of PAGE_SEO_KEYS) {
755
757
  const value = c.string(seo, key, path, false);
756
- if (value && value.length > limits[key]) c.add(SitePlanIssueCode.InvalidSeo, `${path}.${key}`, `${value.length} characters — a search result shows ${limits[key]}`);
758
+ if (!value) continue;
759
+ if (key in limits && value.length > limits[key]) c.add(SitePlanIssueCode.InvalidSeo, `${path}.${key}`, `${value.length} characters — a search result shows ${limits[key]}`);
760
+ if (key === SEO_ROBOTS_KEY && !SEO_ROBOTS_OPTIONS.some(o => o.value === value)) c.add(SitePlanIssueCode.InvalidSeo, `${path}.${key}`, `"${value}" is not a robots choice`);
757
761
  }
758
762
  }
759
763
 
@@ -124,3 +124,16 @@ function compact<T extends object>(value: Record<string, unknown>): T | undefine
124
124
  }
125
125
  return (Object.keys(out).length ? out : undefined) as T | undefined;
126
126
  }
127
+
128
+ /**
129
+ * Words cut to `max` characters on a word boundary, with an ellipsis only when something was cut — a search result's
130
+ * title (`SEO_TITLE_MAX`) or line (`SEO_DESCRIPTION_MAX`). White space collapses. Shared by the composer (a composed
131
+ * page's words) and Bring my site (an old page's own title and line, X6).
132
+ */
133
+ export function fitSeoText(text: string, max: number): string {
134
+ const clean = text.replace(/\s+/g, ' ').trim();
135
+ if (clean.length <= max) return clean;
136
+ const cut = clean.slice(0, max - 1);
137
+ const at = cut.lastIndexOf(' ');
138
+ return `${(at > max / 2 ? cut.slice(0, at) : cut).trimEnd()}…`;
139
+ }
@@ -14,3 +14,4 @@ export * from './seo.model';
14
14
  export * from './normalize';
15
15
  export * from './tags';
16
16
  export * from './schema';
17
+ export * from './redirects';
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Redirects — an old address that answers with another (Bring my site X7, site-build plan §3l, decision X-D3).
3
+ *
4
+ * ONE rule for the three places that need it: iox-cms refuses a redirect that would shadow a page or loop when it is
5
+ * written (an import's or the owner's own), the SSR engine answers a request with the redirect that matches it before it
6
+ * renders, and generation-core lists the redirects an import makes. Framework-free and pure.
7
+ *
8
+ * A redirect's `from` is a PATH on the studio's own site — exact (`/portfolio/blue-bowl`) or a pattern whose `:name`
9
+ * segments match one segment each (`/portfolio/:slug`); its `to` is a path that may use the same names
10
+ * (`/work/:slug`). Exact redirects win over patterns; the engine follows ONE hop.
11
+ */
12
+
13
+ /** The status a redirect answers with: moved for good (the import's, and the default) or for now. */
14
+ export enum RedirectCode {
15
+ Permanent = 301,
16
+ Temporary = 302,
17
+ }
18
+
19
+ export const REDIRECT_CODES: ReadonlyArray<number> = [RedirectCode.Permanent, RedirectCode.Temporary];
20
+
21
+ /** One redirect, as the engine reads it (`GET api/site/:orgId/redirects`). */
22
+ export interface SiteRedirect {
23
+ from: string;
24
+ to: string;
25
+ code: number;
26
+ }
27
+
28
+ /** Why a redirect is not written — said to the owner, never a silent skip. */
29
+ export enum RedirectRefusal {
30
+ /** `from` or `to` is not a path of this site (`/…`), or `to`'s `:name` is not one `from` has. */
31
+ NotAPath = 'not-a-path',
32
+ /** It would send an address to itself. */
33
+ Same = 'same',
34
+ /** `from` is the address of a page of the site — the page answers there; a redirect would hide it. (An exact old
35
+ * address under a page PATTERN — `/blog/Old-Post` beside `/blog/:slug` — is not: no item answers there yet.) */
36
+ ShadowsPage = 'shadows-page',
37
+ /** `to` is another redirect's `from`, or `from` another's `to` — a chain, or a loop. */
38
+ Loop = 'loop',
39
+ /** Another redirect already starts at this `from`. */
40
+ Taken = 'taken',
41
+ }
42
+
43
+ const MAX_PATH = 2_048;
44
+ const PARAM = /^:[a-z_][a-z0-9_]*$/i;
45
+
46
+ const segmentsOf = (path: string): string[] => path.split('/').filter(Boolean);
47
+ const isParam = (segment: string): boolean => PARAM.test(segment);
48
+
49
+ /**
50
+ * An address as a redirect path: an absolute address's path, or a path — without its query and fragment, with one leading
51
+ * slash, no repeated or trailing slash (`/about/` and `/about` are one address), each segment percent-encoded one way.
52
+ * Null when it is neither. Letter case is kept: `/About` is not `/about`.
53
+ */
54
+ export function redirectPath(address: string | null | undefined): string | null {
55
+ if (typeof address !== 'string') return null;
56
+ let text = address.trim();
57
+ if (!text || text.length > MAX_PATH) return null;
58
+ if (/^https?:\/\//i.test(text)) {
59
+ try {
60
+ text = new URL(text).pathname;
61
+ } catch {
62
+ return null;
63
+ }
64
+ }
65
+ if (!text.startsWith('/') || text.startsWith('//')) return null;
66
+ text = text.split(/[?#]/, 1)[0];
67
+ if (/\s/.test(text)) return null;
68
+ return `/${segmentsOf(text).map(sameEncoding).join('/')}`;
69
+ }
70
+
71
+ /** One segment as a browser sends it: `%d7%90` (a WordPress link) and `%D7%90` (what Chrome asks for) and `א` are one. */
72
+ function sameEncoding(segment: string): string {
73
+ if (isParam(segment)) return segment;
74
+ try {
75
+ return encodeURIComponent(decodeURIComponent(segment));
76
+ } catch {
77
+ return segment;
78
+ }
79
+ }
80
+
81
+ /** The two shapes overlap: some address answers both (a `:name` segment matches any one segment). */
82
+ function overlaps(a: string, b: string): boolean {
83
+ const x = segmentsOf(a);
84
+ const y = segmentsOf(b);
85
+ return x.length === y.length && x.every((s, i) => s === y[i] || isParam(s) || isParam(y[i]));
86
+ }
87
+
88
+ /** `path` against a pattern: the values of its `:name` segments, or null when it does not match. */
89
+ function bind(pattern: string, path: string): Record<string, string> | null {
90
+ const p = segmentsOf(pattern);
91
+ const s = segmentsOf(path);
92
+ if (p.length !== s.length) return null;
93
+ const values: Record<string, string> = {};
94
+ for (let i = 0; i < p.length; i++) {
95
+ if (isParam(p[i])) values[p[i]] = s[i];
96
+ else if (p[i] !== s[i]) return null;
97
+ }
98
+ return values;
99
+ }
100
+
101
+ /**
102
+ * The redirect a request for `path` follows, or null: an exact `from` first, then the first pattern that matches, its
103
+ * `:name` values put into `to`. ONE hop — what `to` answers is the next request's business.
104
+ */
105
+ export function matchRedirect(redirects: ReadonlyArray<SiteRedirect>, path: string): { to: string; code: number } | null {
106
+ const at = redirectPath(path);
107
+ if (!at) return null;
108
+ const exact = redirects.find(r => !segmentsOf(r.from).some(isParam) && redirectPath(r.from) === at);
109
+ if (exact) return { to: exact.to, code: exact.code };
110
+ for (const r of redirects) {
111
+ if (!segmentsOf(r.from).some(isParam)) continue;
112
+ const values = bind(r.from, at);
113
+ if (!values) continue;
114
+ const to = segmentsOf(r.to).map(s => (isParam(s) ? values[s] ?? s : s)).join('/');
115
+ return { to: `/${to}`, code: r.code };
116
+ }
117
+ return null;
118
+ }
119
+
120
+ /** What a new redirect is judged against: the site's page routes (`/work/:slug` included) and the redirects it has. */
121
+ export interface RedirectContext {
122
+ pageRoutes: ReadonlyArray<string>;
123
+ redirects: ReadonlyArray<Pick<SiteRedirect, 'from' | 'to'>>;
124
+ }
125
+
126
+ /**
127
+ * Why `candidate` may not be written, or null. A `from` must not be where a page answers (it would hide the page); a
128
+ * `to` must not be another redirect's `from` and a `from` not another's `to` (no chains, so no loops — the engine
129
+ * follows one hop); one redirect per `from`.
130
+ */
131
+ export function redirectRefusal(candidate: Pick<SiteRedirect, 'from' | 'to'>, context: RedirectContext): RedirectRefusal | null {
132
+ const from = redirectPath(candidate.from);
133
+ const to = redirectPath(candidate.to);
134
+ if (!from || !to || from === '/') return RedirectRefusal.NotAPath;
135
+ const names = new Set(segmentsOf(from).filter(isParam));
136
+ if (segmentsOf(to).some(s => isParam(s) && !names.has(s))) return RedirectRefusal.NotAPath;
137
+ if (from === to) return RedirectRefusal.Same;
138
+ const pattern = segmentsOf(from).some(isParam);
139
+ if (context.pageRoutes.some(route => (pattern ? overlaps(route, from) : redirectPath(route) === from))) return RedirectRefusal.ShadowsPage;
140
+ const others = context.redirects.map(r => ({ from: redirectPath(r.from), to: redirectPath(r.to) }));
141
+ if (others.some(r => r.from === from)) return RedirectRefusal.Taken;
142
+ if (others.some(r => (r.from && overlaps(r.from, to)) || (r.to && overlaps(r.to, from)))) return RedirectRefusal.Loop;
143
+ return null;
144
+ }
@@ -157,6 +157,10 @@ export const SEO_ROBOTS_OPTIONS: ReadonlyArray<{ label: string; value: string }>
157
157
  { label: 'No Index, No Follow', value: 'noindex, nofollow' },
158
158
  ];
159
159
 
160
+ /** A page kept out of search but its links still followed — what a page the owner's old site kept out of search moves
161
+ * with (Bring my site X6). */
162
+ export const SEO_ROBOTS_NOINDEX = 'noindex, follow';
163
+
160
164
  export const SEO_TWITTER_CARD_OPTIONS: ReadonlyArray<{ label: string; value: string }> = [
161
165
  { label: 'Summary', value: 'summary' },
162
166
  { label: 'Summary Large Image', value: 'summary_large_image' },