@vectoriox/iox-ui 5.180.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.
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +248 -51
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-seo-core.mjs +160 -1
- package/fesm2022/vectoriox-iox-ui-seo-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +159 -0
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/generation-core/index.d.ts +112 -11
- package/package.json +1 -1
- package/seo-core/index.d.ts +74 -2
- package/src/generation-core/audit-site.ts +4 -4
- package/src/generation-core/compose-site.ts +5 -13
- package/src/generation-core/footer-mix.ts +80 -16
- package/src/generation-core/import-plan.ts +90 -6
- package/src/generation-core/plan-wire.ts +2 -0
- package/src/generation-core/popup-plan.ts +11 -1
- package/src/generation-core/site-build-run.ts +51 -3
- package/src/generation-core/site-plan.model.ts +6 -0
- package/src/generation-core/site-spec.generated.ts +33 -3
- package/src/generation-core/validate-site-plan.ts +6 -2
- package/src/seo-core/normalize.ts +13 -0
- package/src/seo-core/public-api.ts +1 -0
- package/src/seo-core/redirects.ts +144 -0
- package/src/seo-core/seo.model.ts +4 -0
|
@@ -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' },
|