@marktiderman/genesis-sites 0.7.5 → 0.8.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/README.md +74 -8
- package/SKILL.md +10 -0
- package/dist/assets/form-island.da6c662a73.js +51 -0
- package/dist/assets/{islands.33a445f34e.js → islands.83aaf5e0df.js} +1 -1
- package/dist/assets/sites-forms.bac9a6aafd.css +10 -0
- package/dist/assets/sites-forms.css +1 -1
- package/dist/assets/sites.323090ba26.css +2 -0
- package/dist/assets/sites.css +1 -1
- package/dist/assets.generated-YGLB7VKL.js +3 -0
- package/dist/{assets.generated-LLUGUUWZ.js.map → assets.generated-YGLB7VKL.js.map} +1 -1
- package/dist/blocks.js +2 -1
- package/dist/blocks.js.map +1 -1
- package/dist/{chunk-IU6AI75R.js → chunk-6CXTOPYI.js} +343 -158
- package/dist/chunk-6CXTOPYI.js.map +1 -0
- package/dist/{chunk-7E3YGYVH.js → chunk-FMQTSXJN.js} +26 -12
- package/dist/chunk-FMQTSXJN.js.map +1 -0
- package/dist/{chunk-SMJMXQ3T.js → chunk-I767PDBR.js} +260 -62
- package/dist/chunk-I767PDBR.js.map +1 -0
- package/dist/chunk-MXV2HOJO.js +19 -0
- package/dist/chunk-MXV2HOJO.js.map +1 -0
- package/dist/{chunk-KY4ALBVH.js → chunk-QE7KS2JS.js} +65 -7
- package/dist/chunk-QE7KS2JS.js.map +1 -0
- package/dist/{chunk-VJ4HOFBA.js → chunk-YAMQ2JKO.js} +20 -9
- package/dist/chunk-YAMQ2JKO.js.map +1 -0
- package/dist/editor.d.ts +22 -14
- package/dist/editor.js +701 -157
- package/dist/editor.js.map +1 -1
- package/dist/handler-J5BCH2VW.js +10 -0
- package/dist/{handler-UMGSZY33.js.map → handler-J5BCH2VW.js.map} +1 -1
- package/dist/import.d.ts +3 -3
- package/dist/index.d.ts +51 -10
- package/dist/index.js +3 -3
- package/dist/redirects-BNSD9MKa.d.ts +43 -0
- package/dist/{registry-BIijndsq.d.ts → registry-BPn-tDlL.d.ts} +75 -0
- package/dist/sections.d.ts +86 -4
- package/dist/sections.js +2 -2
- package/dist/{store-BImtGmoF.d.ts → store-B_GMH42V.d.ts} +2 -2
- package/dist/supabase.d.ts +4 -4
- package/dist/supabase.js +3 -3
- package/dist/{templates-kA-jrnWA.d.ts → templates-CFSSG1iU.d.ts} +2 -2
- package/dist/templates.d.ts +3 -3
- package/dist/{theme-Cg-inpk5.d.ts → theme-Dw42GDI_.d.ts} +1 -1
- package/dist/web.d.ts +21 -11
- package/dist/web.js +5 -5
- package/migrations/0003_genesis_sites_post_dates.sql +117 -0
- package/migrations/tests/0003_genesis_sites_post_dates.test.sql +76 -0
- package/package.json +9 -5
- package/dist/assets/form-island.defb8daccc.js +0 -51
- package/dist/assets/sites-forms.aff23b5617.css +0 -10
- package/dist/assets/sites.5b3f64c627.css +0 -2
- package/dist/assets.generated-LLUGUUWZ.js +0 -3
- package/dist/chunk-7E3YGYVH.js.map +0 -1
- package/dist/chunk-IU6AI75R.js.map +0 -1
- package/dist/chunk-KY4ALBVH.js.map +0 -1
- package/dist/chunk-RLYO6VVP.js +0 -19
- package/dist/chunk-RLYO6VVP.js.map +0 -1
- package/dist/chunk-SMJMXQ3T.js.map +0 -1
- package/dist/chunk-VJ4HOFBA.js.map +0 -1
- package/dist/handler-UMGSZY33.js +0 -10
|
@@ -102,7 +102,14 @@ var MenuItem = z.object({
|
|
|
102
102
|
var Redirect = z.object({
|
|
103
103
|
from: PagePath,
|
|
104
104
|
to: Href,
|
|
105
|
-
status: z.union([z.literal(301), z.literal(302)])
|
|
105
|
+
status: z.union([z.literal(301), z.literal(302)]),
|
|
106
|
+
/**
|
|
107
|
+
* `"prefix"`: also every address under `from` (`/people` takes
|
|
108
|
+
* `/people/ana`), where no page or post is: pages win. Unset: `from` only.
|
|
109
|
+
*/
|
|
110
|
+
match: z.literal("prefix").optional(),
|
|
111
|
+
/** With `"prefix"` and a site path `to`: keep the rest of the address (`/people/ana` → `/team/ana`). */
|
|
112
|
+
keepRest: z.boolean().optional()
|
|
106
113
|
});
|
|
107
114
|
var FontChoice = z.enum(FONT_IDS);
|
|
108
115
|
var BodyFontChoice = FontChoice.exclude(["bebas-neue"]);
|
|
@@ -122,6 +129,35 @@ var SeoDefaults = z.object({
|
|
|
122
129
|
logo: z.string().max(MAX_URL_LENGTH).refine(isSafeImageSrc).optional(),
|
|
123
130
|
sameAs: z.array(z.url({ protocol: /^https$/ }).max(MAX_URL_LENGTH)).max(10).optional()
|
|
124
131
|
}).optional(),
|
|
132
|
+
/**
|
|
133
|
+
* The business at an address, for JSON-LD on the home page (and `pages`):
|
|
134
|
+
* `type` is a schema.org LocalBusiness type (`LocalBusiness`, or a more
|
|
135
|
+
* specific one such as `Store`); its logo, links and URL come from the site.
|
|
136
|
+
*/
|
|
137
|
+
localBusiness: z.object({
|
|
138
|
+
type: z.string().regex(/^[A-Z][A-Za-z]{2,40}$/, "A schema.org type, such as LocalBusiness.").default("LocalBusiness"),
|
|
139
|
+
name: z.string().trim().min(1).max(120).optional(),
|
|
140
|
+
description: z.string().trim().max(300).optional(),
|
|
141
|
+
telephone: z.string().trim().regex(/^\+?[0-9 ().-]{5,30}$/).optional(),
|
|
142
|
+
email: z.email().max(254).optional(),
|
|
143
|
+
/** `YYYY`, `YYYY-MM` or `YYYY-MM-DD`. */
|
|
144
|
+
foundingDate: z.string().regex(/^\d{4}(-\d{2}){0,2}$/).optional(),
|
|
145
|
+
priceRange: z.string().trim().max(20).optional(),
|
|
146
|
+
image: z.string().max(MAX_URL_LENGTH).refine(isSafeImageSrc).optional(),
|
|
147
|
+
address: z.object({
|
|
148
|
+
streetAddress: z.string().trim().min(1).max(200),
|
|
149
|
+
addressLocality: z.string().trim().min(1).max(100),
|
|
150
|
+
addressRegion: z.string().trim().max(100).optional(),
|
|
151
|
+
postalCode: z.string().trim().max(20).optional(),
|
|
152
|
+
/** ISO 3166-1 alpha-2, such as US. */
|
|
153
|
+
addressCountry: z.string().regex(/^[A-Z]{2}$/).optional()
|
|
154
|
+
}),
|
|
155
|
+
geo: z.object({ latitude: z.number().min(-90).max(90), longitude: z.number().min(-180).max(180) }).optional(),
|
|
156
|
+
/** schema.org opening hours: `"Mo-Fr 06:00-20:00"`, `"Sa 08:00-12:00"`. */
|
|
157
|
+
openingHours: z.array(z.string().regex(/^(Mo|Tu|We|Th|Fr|Sa|Su)(-(Mo|Tu|We|Th|Fr|Sa|Su))?(,(Mo|Tu|We|Th|Fr|Sa|Su)(-(Mo|Tu|We|Th|Fr|Sa|Su))?)* \d{2}:\d{2}-\d{2}:\d{2}$/)).max(14).optional(),
|
|
158
|
+
/** The pages that carry it besides the home page (a contact page). */
|
|
159
|
+
pages: z.array(z.string().max(200).regex(PAGE_PATH)).max(10).optional()
|
|
160
|
+
}).optional(),
|
|
125
161
|
noindex: z.boolean().optional()
|
|
126
162
|
});
|
|
127
163
|
var SiteDoc = z.object({
|
|
@@ -187,159 +223,32 @@ function parseSnapshot(value, report = (m) => console.error(`[genesis-sites] ${m
|
|
|
187
223
|
return { schemaVersion: 1, site: site.data, pages };
|
|
188
224
|
}
|
|
189
225
|
var MAX_DOC_BYTES = 512 * 1024;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this.problems = problems;
|
|
196
|
-
this.name = "SectionDefinitionError";
|
|
197
|
-
}
|
|
198
|
-
problems;
|
|
199
|
-
};
|
|
200
|
-
var TYPE = /^[a-z][a-z0-9-]{0,63}$/;
|
|
201
|
-
function definitionProblems(def) {
|
|
202
|
-
const problems = [];
|
|
203
|
-
if (!def || typeof def !== "object") return ["a section definition is an object"];
|
|
204
|
-
const at = typeof def.type === "string" ? `"${def.type}"` : "a section";
|
|
205
|
-
if (typeof def.type !== "string" || !TYPE.test(def.type)) problems.push(`${at}: \`type\` is lowercase letters, digits and -`);
|
|
206
|
-
if (!Number.isInteger(def.version) || def.version < 1) problems.push(`${at}: \`version\` is a whole number from 1`);
|
|
207
|
-
if (typeof def.label !== "string" || !def.label.trim()) problems.push(`${at}: needs a \`label\``);
|
|
208
|
-
if (!SECTION_CATEGORIES.includes(def.category)) problems.push(`${at}: \`category\` is one of ${SECTION_CATEGORIES.join(", ")}`);
|
|
209
|
-
if (!def.schema || typeof def.schema.safeParse !== "function") problems.push(`${at}: \`schema\` is a zod schema`);
|
|
210
|
-
if (typeof def.render !== "function") problems.push(`${at}: \`render\` is a function`);
|
|
211
|
-
const ids = /* @__PURE__ */ new Set();
|
|
212
|
-
if (!Array.isArray(def.variants) || def.variants.length === 0) problems.push(`${at}: needs at least one variant`);
|
|
213
|
-
else
|
|
214
|
-
for (const v of def.variants) {
|
|
215
|
-
if (!v || typeof v.id !== "string" || !/^[a-z][a-z0-9-]{0,63}$/.test(v.id) || typeof v.label !== "string") problems.push(`${at}: a variant is { id, label }`);
|
|
216
|
-
else if (ids.has(v.id)) problems.push(`${at}: variant "${v.id}" is listed twice`);
|
|
217
|
-
else ids.add(v.id);
|
|
218
|
-
}
|
|
219
|
-
if (!ids.has(def.defaultVariant)) problems.push(`${at}: \`defaultVariant\` "${String(def.defaultVariant)}" is not one of its variants`);
|
|
220
|
-
if (def.limit !== void 0 && (!Number.isInteger(def.limit) || def.limit < 1)) problems.push(`${at}: \`limit\` is a whole number from 1`);
|
|
221
|
-
if (def.placement !== void 0 && !["header", "body", "footer"].includes(def.placement)) problems.push(`${at}: \`placement\` is header, body or footer`);
|
|
222
|
-
if (def.frameOrigins !== void 0 && typeof def.frameOrigins !== "function") problems.push(`${at}: \`frameOrigins\` is a function`);
|
|
223
|
-
for (const [key, fn] of Object.entries(def.migrations ?? {})) {
|
|
224
|
-
const n = Number(key);
|
|
225
|
-
if (!Number.isInteger(n) || n < 2 || n > def.version) problems.push(`${at}: migration ${key} must be between 2 and the version (${def.version})`);
|
|
226
|
-
if (typeof fn !== "function") problems.push(`${at}: migration ${key} is a function`);
|
|
227
|
-
}
|
|
228
|
-
for (let n = 2; n <= (Number.isInteger(def.version) ? def.version : 0); n++) {
|
|
229
|
-
if (!def.migrations?.[n]) problems.push(`${at}: version ${def.version} needs a migration to ${n}`);
|
|
230
|
-
}
|
|
231
|
-
if (!Array.isArray(def.presets) || def.presets.length === 0) problems.push(`${at}: needs at least one preset (the editor's Add picker)`);
|
|
232
|
-
else if (def.schema && typeof def.schema.safeParse === "function")
|
|
233
|
-
for (const preset of def.presets) {
|
|
234
|
-
if (!preset || typeof preset.name !== "string" || !ids.has(preset.variant)) {
|
|
235
|
-
problems.push(`${at}: preset ${JSON.stringify(preset?.name)} needs a name and one of its variants`);
|
|
236
|
-
continue;
|
|
237
|
-
}
|
|
238
|
-
const parsed = def.schema.safeParse(preset.props);
|
|
239
|
-
if (!parsed.success) problems.push(`${at}: preset "${preset.name}" doesn't match the schema: ${parsed.error.issues.map((i) => `${i.path.join(".") || "props"} ${i.message}`).join("; ")}`);
|
|
240
|
-
}
|
|
241
|
-
return problems;
|
|
242
|
-
}
|
|
243
|
-
function defineSection(def) {
|
|
244
|
-
const problems = definitionProblems(def);
|
|
245
|
-
if (problems.length) throw new SectionDefinitionError(problems);
|
|
246
|
-
return Object.freeze({
|
|
247
|
-
...def,
|
|
248
|
-
variants: Object.freeze(def.variants.map((v) => Object.freeze({ ...v }))),
|
|
249
|
-
presets: Object.freeze(def.presets.map((p) => Object.freeze({ ...p }))),
|
|
250
|
-
...def.enabledOn ? { enabledOn: Object.freeze([...def.enabledOn]) } : {},
|
|
251
|
-
...def.migrations ? { migrations: Object.freeze({ ...def.migrations }) } : {}
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
var REGISTRY = /* @__PURE__ */ Symbol.for("@marktiderman/genesis-sites/sections@1");
|
|
255
|
-
var BUILT_IN = /* @__PURE__ */ Symbol.for("@marktiderman/genesis-sites/built-in-sections@1");
|
|
256
|
-
var scope = globalThis;
|
|
257
|
-
var registry = scope[REGISTRY] ??= /* @__PURE__ */ new Map();
|
|
258
|
-
var builtIns = scope[BUILT_IN] ??= /* @__PURE__ */ new Set();
|
|
259
|
-
var BUILT_IN_SECTION_TYPES = Object.freeze([
|
|
260
|
-
"nav",
|
|
261
|
-
"hero",
|
|
262
|
-
"features",
|
|
263
|
-
"cta",
|
|
264
|
-
"testimonials",
|
|
265
|
-
"faq",
|
|
266
|
-
"pricing",
|
|
267
|
-
"logos",
|
|
268
|
-
"stats",
|
|
269
|
-
"gallery",
|
|
270
|
-
"rich-text",
|
|
271
|
-
"form-embed",
|
|
272
|
-
"footer",
|
|
273
|
-
"schedule",
|
|
274
|
-
"team",
|
|
275
|
-
"blog-list",
|
|
276
|
-
"post-body",
|
|
277
|
-
"map",
|
|
278
|
-
"timeline",
|
|
279
|
-
"file"
|
|
280
|
-
]);
|
|
281
|
-
function registerSection(def, options = {}) {
|
|
282
|
-
const frozen = Object.isFrozen(def) && definitionProblems(def).length === 0 ? def : defineSection(def);
|
|
283
|
-
if (BUILT_IN_SECTION_TYPES.includes(frozen.type) && options.replace !== true) {
|
|
284
|
-
throw new Error(
|
|
285
|
-
`registerSection: "${frozen.type}" is a built-in section; pass { replace: true } to replace it for every site in this process.`
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
registry.set(frozen.type, frozen);
|
|
289
|
-
}
|
|
290
|
-
function registerBuiltInSection(def) {
|
|
291
|
-
if (!registry.has(def.type)) registry.set(def.type, def);
|
|
292
|
-
builtIns.add(def.type);
|
|
293
|
-
}
|
|
294
|
-
function getSection(type) {
|
|
295
|
-
return registry.get(type);
|
|
296
|
-
}
|
|
297
|
-
function listSections() {
|
|
298
|
-
return [...registry.values()];
|
|
299
|
-
}
|
|
300
|
-
function unregisterSection(type) {
|
|
301
|
-
if (BUILT_IN_SECTION_TYPES.includes(type)) throw new Error(`unregisterSection: "${type}" is built in; replace it with registerSection(\u2026, { replace: true }).`);
|
|
302
|
-
return registry.delete(type);
|
|
303
|
-
}
|
|
304
|
-
var jsonSchemas = /* @__PURE__ */ new WeakMap();
|
|
305
|
-
function sectionJsonSchema(typeOrDef) {
|
|
306
|
-
const def = typeof typeOrDef === "string" ? registry.get(typeOrDef) : typeOrDef;
|
|
307
|
-
if (!def) throw new Error(`sectionJsonSchema: no section "${String(typeOrDef)}" is registered.`);
|
|
308
|
-
let schema = jsonSchemas.get(def.schema);
|
|
309
|
-
if (!schema) {
|
|
310
|
-
schema = z.toJSONSchema(def.schema, { io: "input", unrepresentable: "any" });
|
|
311
|
-
jsonSchemas.set(def.schema, schema);
|
|
312
|
-
}
|
|
313
|
-
return schema;
|
|
314
|
-
}
|
|
315
|
-
function sectionManifests() {
|
|
316
|
-
return listSections().map((def) => ({
|
|
317
|
-
type: def.type,
|
|
318
|
-
version: def.version,
|
|
319
|
-
label: def.label,
|
|
320
|
-
...def.description ? { description: def.description } : {},
|
|
321
|
-
category: def.category,
|
|
322
|
-
placement: def.placement ?? "body",
|
|
323
|
-
variants: def.variants,
|
|
324
|
-
defaultVariant: def.defaultVariant,
|
|
325
|
-
presets: def.presets,
|
|
326
|
-
...def.limit ? { limit: def.limit } : {},
|
|
327
|
-
...def.enabledOn ? { enabledOn: def.enabledOn } : {},
|
|
328
|
-
jsonSchema: sectionJsonSchema(def)
|
|
329
|
-
}));
|
|
330
|
-
}
|
|
331
|
-
var counter = 0;
|
|
332
|
-
function newSectionId(prefix = "s") {
|
|
333
|
-
counter = (counter + 1) % 1e6;
|
|
334
|
-
const random = Math.random().toString(36).slice(2, 8);
|
|
335
|
-
return `${prefix}${Date.now().toString(36)}${counter.toString(36)}${random}`.slice(0, 64);
|
|
226
|
+
|
|
227
|
+
// src/core/not-found.ts
|
|
228
|
+
var NOT_FOUND_PATH = "/404";
|
|
229
|
+
function isNotFoundPage(page) {
|
|
230
|
+
return page.path === NOT_FOUND_PATH;
|
|
336
231
|
}
|
|
337
|
-
function
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
232
|
+
function notFoundPageDoc(input = {}) {
|
|
233
|
+
const title = input.title?.trim() || "Page not found";
|
|
234
|
+
return {
|
|
235
|
+
schemaVersion: 1,
|
|
236
|
+
root: { props: { title: title.slice(0, 120) } },
|
|
237
|
+
content: [
|
|
238
|
+
{
|
|
239
|
+
id: "not-found",
|
|
240
|
+
type: "hero",
|
|
241
|
+
v: 1,
|
|
242
|
+
variant: "centered",
|
|
243
|
+
props: {
|
|
244
|
+
heading: title.slice(0, 90),
|
|
245
|
+
body: "There's no page at this address. It may have moved.",
|
|
246
|
+
primaryCta: { label: "Go to the home page", href: "/" }
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
],
|
|
250
|
+
seo: { noindex: true }
|
|
251
|
+
};
|
|
343
252
|
}
|
|
344
253
|
var PostSlug = z.string().max(80).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "A post slug is lowercase letters, digits and single hyphens.");
|
|
345
254
|
var PostAuthor = z.object({
|
|
@@ -479,6 +388,67 @@ function organizationJsonLd(site, origin, basePath = "") {
|
|
|
479
388
|
if (org?.sameAs?.length) out.sameAs = org.sameAs;
|
|
480
389
|
return out;
|
|
481
390
|
}
|
|
391
|
+
function localBusinessJsonLd(site, path, origin, basePath = "") {
|
|
392
|
+
const biz = site.seo.localBusiness;
|
|
393
|
+
if (!biz || path !== "/" && !(biz.pages ?? []).includes(path)) return null;
|
|
394
|
+
const org = site.seo.organization;
|
|
395
|
+
const abs = (src) => src.startsWith("/") ? absoluteUrl(origin, basePath, src) : src;
|
|
396
|
+
const out = {
|
|
397
|
+
"@context": "https://schema.org",
|
|
398
|
+
"@type": biz.type ?? "LocalBusiness",
|
|
399
|
+
name: biz.name ?? org?.name ?? site.name,
|
|
400
|
+
url: absoluteUrl(origin, basePath, "/"),
|
|
401
|
+
address: { "@type": "PostalAddress", ...biz.address }
|
|
402
|
+
};
|
|
403
|
+
if (biz.description) out.description = biz.description;
|
|
404
|
+
if (biz.telephone) out.telephone = biz.telephone;
|
|
405
|
+
if (biz.email) out.email = biz.email;
|
|
406
|
+
if (biz.foundingDate) out.foundingDate = biz.foundingDate;
|
|
407
|
+
if (biz.priceRange) out.priceRange = biz.priceRange;
|
|
408
|
+
if (biz.image ?? org?.logo) out.image = abs(biz.image ?? org?.logo);
|
|
409
|
+
if (org?.logo) out.logo = abs(org.logo);
|
|
410
|
+
if (biz.geo) out.geo = { "@type": "GeoCoordinates", ...biz.geo };
|
|
411
|
+
if (biz.openingHours?.length) out.openingHours = biz.openingHours;
|
|
412
|
+
if (org?.sameAs?.length) out.sameAs = org.sameAs;
|
|
413
|
+
return out;
|
|
414
|
+
}
|
|
415
|
+
function answerText(answer) {
|
|
416
|
+
if (typeof answer === "string") return answer.trim();
|
|
417
|
+
const out = [];
|
|
418
|
+
const walk = (node) => {
|
|
419
|
+
if (!node || typeof node !== "object") return;
|
|
420
|
+
const n = node;
|
|
421
|
+
if (n.type === "text" && typeof n.text === "string") out.push(n.text);
|
|
422
|
+
else if (n.type === "hardBreak") out.push(" ");
|
|
423
|
+
if (Array.isArray(n.content)) {
|
|
424
|
+
n.content.forEach(walk);
|
|
425
|
+
if (n.type !== "doc") out.push(" ");
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
walk(answer);
|
|
429
|
+
return out.join("").replace(/\s+/g, " ").trim();
|
|
430
|
+
}
|
|
431
|
+
function faqPageJsonLd(page) {
|
|
432
|
+
const items = [];
|
|
433
|
+
const walk = (nodes) => {
|
|
434
|
+
for (const node of nodes) {
|
|
435
|
+
if (node.hidden) continue;
|
|
436
|
+
if (node.type === "faq" && Array.isArray(node.props.items)) {
|
|
437
|
+
for (const item of node.props.items) {
|
|
438
|
+
const answer = answerText(item?.answer);
|
|
439
|
+
if (typeof item?.question === "string" && item.question.trim() && answer) items.push({ question: item.question.trim(), answer });
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
walk(page.content);
|
|
445
|
+
if (!items.length) return null;
|
|
446
|
+
return {
|
|
447
|
+
"@context": "https://schema.org",
|
|
448
|
+
"@type": "FAQPage",
|
|
449
|
+
mainEntity: items.map((i) => ({ "@type": "Question", name: i.question, acceptedAnswer: { "@type": "Answer", text: i.answer } }))
|
|
450
|
+
};
|
|
451
|
+
}
|
|
482
452
|
function websiteJsonLd(site, origin, basePath = "") {
|
|
483
453
|
return {
|
|
484
454
|
"@context": "https://schema.org",
|
|
@@ -577,7 +547,7 @@ function escapeXml(text) {
|
|
|
577
547
|
return text.replace(/[<>&'"]/g, (c) => ({ "<": "<", ">": ">", "&": "&", "'": "'", '"': """ })[c]);
|
|
578
548
|
}
|
|
579
549
|
function sitemapXml({ site, pages, origin, basePath = "", lastModified, posts }) {
|
|
580
|
-
const urls = site.seo.noindex ? [] : pages.filter((p) => !p.doc.seo?.noindex && !p.doc.seo?.canonical).sort((a, b) => a.path === "/" ? -1 : b.path === "/" ? 1 : a.path.localeCompare(b.path)).map((p) => {
|
|
550
|
+
const urls = site.seo.noindex ? [] : pages.filter((p) => !p.doc.seo?.noindex && !p.doc.seo?.canonical && !isNotFoundPage(p)).sort((a, b) => a.path === "/" ? -1 : b.path === "/" ? 1 : a.path.localeCompare(b.path)).map((p) => {
|
|
581
551
|
const loc = `<loc>${escapeXml(absoluteUrl(origin, basePath, p.path))}</loc>`;
|
|
582
552
|
const mod = lastModified ? `<lastmod>${escapeXml(new Date(lastModified).toISOString())}</lastmod>` : "";
|
|
583
553
|
return `<url>${loc}${mod}</url>`;
|
|
@@ -606,10 +576,225 @@ function redirectsAfterMove(redirects, from, to) {
|
|
|
606
576
|
next.push({ from, to, status: 301 });
|
|
607
577
|
return next;
|
|
608
578
|
}
|
|
579
|
+
function isUnderPrefix(path, from) {
|
|
580
|
+
return path === from || path.startsWith(`${from}/`);
|
|
581
|
+
}
|
|
609
582
|
function matchRedirect(redirects, path) {
|
|
610
|
-
return redirects.find((r) => r.from === path && isSafeHref(r.to));
|
|
583
|
+
return redirects.find((r) => r.match !== "prefix" && r.from === path && isSafeHref(r.to));
|
|
584
|
+
}
|
|
585
|
+
function matchPrefixRedirect(redirects, path) {
|
|
586
|
+
let best;
|
|
587
|
+
for (const r of redirects) {
|
|
588
|
+
if (r.match !== "prefix" || !isSafeHref(r.to) || !isUnderPrefix(path, r.from)) continue;
|
|
589
|
+
if (!best || r.from.length > best.from.length) best = r;
|
|
590
|
+
}
|
|
591
|
+
if (!best) return void 0;
|
|
592
|
+
const rest = path.slice(best.from.length);
|
|
593
|
+
if (!best.keepRest || !rest || !best.to.startsWith("/")) return { redirect: best, to: best.to };
|
|
594
|
+
const escaped = rest.split("/").map(escapePathSegment).join("/");
|
|
595
|
+
const cut = best.to.search(/[?#]/);
|
|
596
|
+
const base = cut < 0 ? best.to : best.to.slice(0, cut);
|
|
597
|
+
const tail = cut < 0 ? "" : best.to.slice(cut);
|
|
598
|
+
return { redirect: best, to: `${base === "/" ? "" : base.replace(/\/+$/, "")}${escaped}${tail}` };
|
|
599
|
+
}
|
|
600
|
+
function escapePathSegment(segment) {
|
|
601
|
+
return encodeURIComponent(segment).replace(/%(?:21|24|26|27|28|29|2A|2B|2C|3A|3B|3D|40)/gi, (m) => decodeURIComponent(m));
|
|
602
|
+
}
|
|
603
|
+
function redirectTargetPath(to) {
|
|
604
|
+
if (!to.startsWith("/")) return null;
|
|
605
|
+
const path = to.split(/[?#]/)[0];
|
|
606
|
+
let decoded = path;
|
|
607
|
+
try {
|
|
608
|
+
decoded = decodeURIComponent(path);
|
|
609
|
+
} catch {
|
|
610
|
+
}
|
|
611
|
+
const lower = decoded.toLowerCase();
|
|
612
|
+
return lower.length > 1 && lower.endsWith("/") ? lower.slice(0, -1) : lower;
|
|
613
|
+
}
|
|
614
|
+
function redirectStep(redirects, hasPage) {
|
|
615
|
+
return (path) => {
|
|
616
|
+
const exact = matchRedirect(redirects, path);
|
|
617
|
+
if (exact) return redirectTargetPath(exact.to);
|
|
618
|
+
if (hasPage(path)) return null;
|
|
619
|
+
const prefix = matchPrefixRedirect(redirects, path);
|
|
620
|
+
return prefix ? redirectTargetPath(prefix.to) : null;
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
function redirectLoops(redirects, hasPage = () => false, maxHops = 10) {
|
|
624
|
+
const step = redirectStep(redirects, hasPage);
|
|
625
|
+
const loops = [];
|
|
626
|
+
for (const r of redirects) {
|
|
627
|
+
const starts = r.match === "prefix" ? [r.from, `${r.from === "/" ? "" : r.from}/x-check`] : [r.from];
|
|
628
|
+
const loops_ = starts.some((start) => {
|
|
629
|
+
const seen = /* @__PURE__ */ new Set([start]);
|
|
630
|
+
let at = start;
|
|
631
|
+
for (let hop = 0; hop <= maxHops; hop++) {
|
|
632
|
+
at = step(at);
|
|
633
|
+
if (at === null) return false;
|
|
634
|
+
if (seen.has(at)) return true;
|
|
635
|
+
seen.add(at);
|
|
636
|
+
}
|
|
637
|
+
return true;
|
|
638
|
+
});
|
|
639
|
+
if (loops_) loops.push(r.from);
|
|
640
|
+
}
|
|
641
|
+
return loops;
|
|
642
|
+
}
|
|
643
|
+
var SECTION_CATEGORIES = ["header", "intro", "content", "social-proof", "conversion", "footer"];
|
|
644
|
+
var SectionDefinitionError = class extends Error {
|
|
645
|
+
constructor(problems) {
|
|
646
|
+
super(`Invalid section definition:
|
|
647
|
+
${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
648
|
+
this.problems = problems;
|
|
649
|
+
this.name = "SectionDefinitionError";
|
|
650
|
+
}
|
|
651
|
+
problems;
|
|
652
|
+
};
|
|
653
|
+
var TYPE = /^[a-z][a-z0-9-]{0,63}$/;
|
|
654
|
+
function definitionProblems(def) {
|
|
655
|
+
const problems = [];
|
|
656
|
+
if (!def || typeof def !== "object") return ["a section definition is an object"];
|
|
657
|
+
const at = typeof def.type === "string" ? `"${def.type}"` : "a section";
|
|
658
|
+
if (typeof def.type !== "string" || !TYPE.test(def.type)) problems.push(`${at}: \`type\` is lowercase letters, digits and -`);
|
|
659
|
+
if (!Number.isInteger(def.version) || def.version < 1) problems.push(`${at}: \`version\` is a whole number from 1`);
|
|
660
|
+
if (typeof def.label !== "string" || !def.label.trim()) problems.push(`${at}: needs a \`label\``);
|
|
661
|
+
if (!SECTION_CATEGORIES.includes(def.category)) problems.push(`${at}: \`category\` is one of ${SECTION_CATEGORIES.join(", ")}`);
|
|
662
|
+
if (!def.schema || typeof def.schema.safeParse !== "function") problems.push(`${at}: \`schema\` is a zod schema`);
|
|
663
|
+
if (typeof def.render !== "function") problems.push(`${at}: \`render\` is a function`);
|
|
664
|
+
const ids = /* @__PURE__ */ new Set();
|
|
665
|
+
if (!Array.isArray(def.variants) || def.variants.length === 0) problems.push(`${at}: needs at least one variant`);
|
|
666
|
+
else
|
|
667
|
+
for (const v of def.variants) {
|
|
668
|
+
if (!v || typeof v.id !== "string" || !/^[a-z][a-z0-9-]{0,63}$/.test(v.id) || typeof v.label !== "string") problems.push(`${at}: a variant is { id, label }`);
|
|
669
|
+
else if (ids.has(v.id)) problems.push(`${at}: variant "${v.id}" is listed twice`);
|
|
670
|
+
else ids.add(v.id);
|
|
671
|
+
}
|
|
672
|
+
if (!ids.has(def.defaultVariant)) problems.push(`${at}: \`defaultVariant\` "${String(def.defaultVariant)}" is not one of its variants`);
|
|
673
|
+
if (def.limit !== void 0 && (!Number.isInteger(def.limit) || def.limit < 1)) problems.push(`${at}: \`limit\` is a whole number from 1`);
|
|
674
|
+
if (def.placement !== void 0 && !["header", "body", "footer"].includes(def.placement)) problems.push(`${at}: \`placement\` is header, body or footer`);
|
|
675
|
+
if (def.frameOrigins !== void 0 && typeof def.frameOrigins !== "function") problems.push(`${at}: \`frameOrigins\` is a function`);
|
|
676
|
+
for (const [key, fn] of Object.entries(def.migrations ?? {})) {
|
|
677
|
+
const n = Number(key);
|
|
678
|
+
if (!Number.isInteger(n) || n < 2 || n > def.version) problems.push(`${at}: migration ${key} must be between 2 and the version (${def.version})`);
|
|
679
|
+
if (typeof fn !== "function") problems.push(`${at}: migration ${key} is a function`);
|
|
680
|
+
}
|
|
681
|
+
for (let n = 2; n <= (Number.isInteger(def.version) ? def.version : 0); n++) {
|
|
682
|
+
if (!def.migrations?.[n]) problems.push(`${at}: version ${def.version} needs a migration to ${n}`);
|
|
683
|
+
}
|
|
684
|
+
if (!Array.isArray(def.presets) || def.presets.length === 0) problems.push(`${at}: needs at least one preset (the editor's Add picker)`);
|
|
685
|
+
else if (def.schema && typeof def.schema.safeParse === "function")
|
|
686
|
+
for (const preset of def.presets) {
|
|
687
|
+
if (!preset || typeof preset.name !== "string" || !ids.has(preset.variant)) {
|
|
688
|
+
problems.push(`${at}: preset ${JSON.stringify(preset?.name)} needs a name and one of its variants`);
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
const parsed = def.schema.safeParse(preset.props);
|
|
692
|
+
if (!parsed.success) problems.push(`${at}: preset "${preset.name}" doesn't match the schema: ${parsed.error.issues.map((i) => `${i.path.join(".") || "props"} ${i.message}`).join("; ")}`);
|
|
693
|
+
}
|
|
694
|
+
return problems;
|
|
695
|
+
}
|
|
696
|
+
function defineSection(def) {
|
|
697
|
+
const problems = definitionProblems(def);
|
|
698
|
+
if (problems.length) throw new SectionDefinitionError(problems);
|
|
699
|
+
return Object.freeze({
|
|
700
|
+
...def,
|
|
701
|
+
variants: Object.freeze(def.variants.map((v) => Object.freeze({ ...v }))),
|
|
702
|
+
presets: Object.freeze(def.presets.map((p) => Object.freeze({ ...p }))),
|
|
703
|
+
...def.enabledOn ? { enabledOn: Object.freeze([...def.enabledOn]) } : {},
|
|
704
|
+
...def.migrations ? { migrations: Object.freeze({ ...def.migrations }) } : {}
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
var REGISTRY = /* @__PURE__ */ Symbol.for("@marktiderman/genesis-sites/sections@1");
|
|
708
|
+
var BUILT_IN = /* @__PURE__ */ Symbol.for("@marktiderman/genesis-sites/built-in-sections@1");
|
|
709
|
+
var scope = globalThis;
|
|
710
|
+
var registry = scope[REGISTRY] ??= /* @__PURE__ */ new Map();
|
|
711
|
+
var builtIns = scope[BUILT_IN] ??= /* @__PURE__ */ new Set();
|
|
712
|
+
var BUILT_IN_SECTION_TYPES = Object.freeze([
|
|
713
|
+
"nav",
|
|
714
|
+
"hero",
|
|
715
|
+
"features",
|
|
716
|
+
"cta",
|
|
717
|
+
"testimonials",
|
|
718
|
+
"faq",
|
|
719
|
+
"pricing",
|
|
720
|
+
"logos",
|
|
721
|
+
"stats",
|
|
722
|
+
"gallery",
|
|
723
|
+
"rich-text",
|
|
724
|
+
"form-embed",
|
|
725
|
+
"footer",
|
|
726
|
+
"schedule",
|
|
727
|
+
"team",
|
|
728
|
+
"blog-list",
|
|
729
|
+
"post-body",
|
|
730
|
+
"map",
|
|
731
|
+
"timeline",
|
|
732
|
+
"file"
|
|
733
|
+
]);
|
|
734
|
+
function registerSection(def, options = {}) {
|
|
735
|
+
const frozen = Object.isFrozen(def) && definitionProblems(def).length === 0 ? def : defineSection(def);
|
|
736
|
+
if (BUILT_IN_SECTION_TYPES.includes(frozen.type) && options.replace !== true) {
|
|
737
|
+
throw new Error(
|
|
738
|
+
`registerSection: "${frozen.type}" is a built-in section; pass { replace: true } to replace it for every site in this process.`
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
registry.set(frozen.type, frozen);
|
|
742
|
+
}
|
|
743
|
+
function registerBuiltInSection(def) {
|
|
744
|
+
if (!registry.has(def.type)) registry.set(def.type, def);
|
|
745
|
+
builtIns.add(def.type);
|
|
746
|
+
}
|
|
747
|
+
function getSection(type) {
|
|
748
|
+
return registry.get(type);
|
|
749
|
+
}
|
|
750
|
+
function listSections() {
|
|
751
|
+
return [...registry.values()];
|
|
752
|
+
}
|
|
753
|
+
function unregisterSection(type) {
|
|
754
|
+
if (BUILT_IN_SECTION_TYPES.includes(type)) throw new Error(`unregisterSection: "${type}" is built in; replace it with registerSection(\u2026, { replace: true }).`);
|
|
755
|
+
return registry.delete(type);
|
|
756
|
+
}
|
|
757
|
+
var jsonSchemas = /* @__PURE__ */ new WeakMap();
|
|
758
|
+
function sectionJsonSchema(typeOrDef) {
|
|
759
|
+
const def = typeof typeOrDef === "string" ? registry.get(typeOrDef) : typeOrDef;
|
|
760
|
+
if (!def) throw new Error(`sectionJsonSchema: no section "${String(typeOrDef)}" is registered.`);
|
|
761
|
+
let schema = jsonSchemas.get(def.schema);
|
|
762
|
+
if (!schema) {
|
|
763
|
+
schema = z.toJSONSchema(def.schema, { io: "input", unrepresentable: "any" });
|
|
764
|
+
jsonSchemas.set(def.schema, schema);
|
|
765
|
+
}
|
|
766
|
+
return schema;
|
|
767
|
+
}
|
|
768
|
+
function sectionManifests() {
|
|
769
|
+
return listSections().map((def) => ({
|
|
770
|
+
type: def.type,
|
|
771
|
+
version: def.version,
|
|
772
|
+
label: def.label,
|
|
773
|
+
...def.description ? { description: def.description } : {},
|
|
774
|
+
category: def.category,
|
|
775
|
+
placement: def.placement ?? "body",
|
|
776
|
+
variants: def.variants,
|
|
777
|
+
defaultVariant: def.defaultVariant,
|
|
778
|
+
presets: def.presets,
|
|
779
|
+
...def.limit ? { limit: def.limit } : {},
|
|
780
|
+
...def.enabledOn ? { enabledOn: def.enabledOn } : {},
|
|
781
|
+
jsonSchema: sectionJsonSchema(def)
|
|
782
|
+
}));
|
|
783
|
+
}
|
|
784
|
+
var counter = 0;
|
|
785
|
+
function newSectionId(prefix = "s") {
|
|
786
|
+
counter = (counter + 1) % 1e6;
|
|
787
|
+
const random = Math.random().toString(36).slice(2, 8);
|
|
788
|
+
return `${prefix}${Date.now().toString(36)}${counter.toString(36)}${random}`.slice(0, 64);
|
|
789
|
+
}
|
|
790
|
+
function nodeFromPreset(type, presetName, id = newSectionId(type.replace(/-/g, "").slice(0, 6))) {
|
|
791
|
+
const def = registry.get(type);
|
|
792
|
+
if (!def) throw new Error(`nodeFromPreset: no section "${type}" is registered.`);
|
|
793
|
+
const preset = presetName ? def.presets.find((p) => p.name === presetName) : def.presets[0];
|
|
794
|
+
if (!preset) throw new Error(`nodeFromPreset: "${type}" has no preset "${presetName}".`);
|
|
795
|
+
return { id, type, v: def.version, variant: preset.variant, props: structuredClone(preset.props) };
|
|
611
796
|
}
|
|
612
797
|
|
|
613
|
-
export { BUILT_IN_SECTION_TYPES, BodyFontChoice, Copy, FileRef, FontChoice, Href, Image, Line, Link, LinkEvent, MAX_DOC_BYTES, MAX_IMPORT_POSTS, MAX_LIVE_POSTS, MenuItem, PageDoc, PageKind, PagePath, PostAuthor, PostDoc, PostSlug, PostSummarySchema, Redirect, ReleasePage, ReleaseSnapshot, RichText, SECTION_CATEGORIES, SectionDefinitionError, SectionId, SectionNode, Seo, SeoDefaults, SiteDoc, Surface, TokenOverrides, absoluteUrl, articleJsonLd, breadcrumbJsonLd, defineSection, escapeXml, getSection, listSections, matchRedirect, newSectionId, nodeFromPreset, opensInNewTab, organizationJsonLd, pageMeta, pageTitle, parseSnapshot, postDescription, postPath, postSummary, redirectsAfterMove, registerBuiltInSection, registerSection, richTextPlain, robotsTxt, rssXml, safeJsonForHtml, sectionJsonSchema, sectionManifests, sitemapXml, unregisterSection, validatePostSlug, websiteJsonLd };
|
|
614
|
-
//# sourceMappingURL=chunk-
|
|
615
|
-
//# sourceMappingURL=chunk-
|
|
798
|
+
export { BUILT_IN_SECTION_TYPES, BodyFontChoice, Copy, FileRef, FontChoice, Href, Image, Line, Link, LinkEvent, MAX_DOC_BYTES, MAX_IMPORT_POSTS, MAX_LIVE_POSTS, MenuItem, NOT_FOUND_PATH, PageDoc, PageKind, PagePath, PostAuthor, PostDoc, PostSlug, PostSummarySchema, Redirect, ReleasePage, ReleaseSnapshot, RichText, SECTION_CATEGORIES, SectionDefinitionError, SectionId, SectionNode, Seo, SeoDefaults, SiteDoc, Surface, TokenOverrides, absoluteUrl, articleJsonLd, breadcrumbJsonLd, defineSection, escapeXml, faqPageJsonLd, getSection, isNotFoundPage, isUnderPrefix, listSections, localBusinessJsonLd, matchPrefixRedirect, matchRedirect, newSectionId, nodeFromPreset, notFoundPageDoc, opensInNewTab, organizationJsonLd, pageMeta, pageTitle, parseSnapshot, postDescription, postPath, postSummary, redirectLoops, redirectsAfterMove, registerBuiltInSection, registerSection, richTextPlain, robotsTxt, rssXml, safeJsonForHtml, sectionJsonSchema, sectionManifests, sitemapXml, unregisterSection, validatePostSlug, websiteJsonLd };
|
|
799
|
+
//# sourceMappingURL=chunk-6CXTOPYI.js.map
|
|
800
|
+
//# sourceMappingURL=chunk-6CXTOPYI.js.map
|