@marktiderman/genesis-sites 0.7.6 → 0.9.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.
Files changed (71) hide show
  1. package/README.md +202 -19
  2. package/SKILL.md +15 -0
  3. package/dist/analytics.d.ts +184 -0
  4. package/dist/analytics.js +3 -0
  5. package/dist/analytics.js.map +1 -0
  6. package/dist/assets/form-island.da6c662a73.js +51 -0
  7. package/dist/assets/islands.399b13ea6f.js +1 -0
  8. package/dist/assets/sites-forms.b64c156079.css +10 -0
  9. package/dist/assets/sites-forms.css +1 -1
  10. package/dist/assets/sites.2fac65f96a.css +2 -0
  11. package/dist/assets/sites.css +1 -1
  12. package/dist/assets.generated-ZBFSP23U.js +3 -0
  13. package/dist/{assets.generated-LLUGUUWZ.js.map → assets.generated-ZBFSP23U.js.map} +1 -1
  14. package/dist/blocks.js +2 -1
  15. package/dist/blocks.js.map +1 -1
  16. package/dist/chunk-5G2H6EZ2.js +19 -0
  17. package/dist/chunk-5G2H6EZ2.js.map +1 -0
  18. package/dist/chunk-5RYCQEEE.js +256 -0
  19. package/dist/chunk-5RYCQEEE.js.map +1 -0
  20. package/dist/{chunk-7E3YGYVH.js → chunk-ATRS5GSD.js} +77 -22
  21. package/dist/chunk-ATRS5GSD.js.map +1 -0
  22. package/dist/{chunk-MU2Z2C4F.js → chunk-CXBBUKGB.js} +14 -4
  23. package/dist/chunk-CXBBUKGB.js.map +1 -0
  24. package/dist/{chunk-IU6AI75R.js → chunk-QGU6FDH5.js} +413 -162
  25. package/dist/chunk-QGU6FDH5.js.map +1 -0
  26. package/dist/{chunk-SMJMXQ3T.js → chunk-SBONYMUC.js} +294 -73
  27. package/dist/chunk-SBONYMUC.js.map +1 -0
  28. package/dist/{chunk-VJ4HOFBA.js → chunk-UOKNFG5O.js} +144 -20
  29. package/dist/chunk-UOKNFG5O.js.map +1 -0
  30. package/dist/{chunk-KY4ALBVH.js → chunk-UUC5USJH.js} +58 -37
  31. package/dist/chunk-UUC5USJH.js.map +1 -0
  32. package/dist/editor.d.ts +76 -19
  33. package/dist/editor.js +1217 -245
  34. package/dist/editor.js.map +1 -1
  35. package/dist/handler-OR554RTS.js +11 -0
  36. package/dist/{handler-UMGSZY33.js.map → handler-OR554RTS.js.map} +1 -1
  37. package/dist/import.d.ts +3 -3
  38. package/dist/import.js +1 -1
  39. package/dist/index.d.ts +66 -11
  40. package/dist/index.js +4 -4
  41. package/dist/redirects-LcCNIJHQ.d.ts +43 -0
  42. package/dist/{registry-BIijndsq.d.ts → registry-Cw7NF_le.d.ts} +92 -1
  43. package/dist/sections.d.ts +86 -4
  44. package/dist/sections.js +3 -3
  45. package/dist/{store-BImtGmoF.d.ts → store-BNYD5NAQ.d.ts} +30 -4
  46. package/dist/supabase.d.ts +4 -4
  47. package/dist/supabase.js +4 -4
  48. package/dist/{templates-kA-jrnWA.d.ts → templates-DPv0OYLl.d.ts} +2 -2
  49. package/dist/templates.d.ts +3 -3
  50. package/dist/templates.js +7 -3
  51. package/dist/templates.js.map +1 -1
  52. package/dist/{theme-Cg-inpk5.d.ts → theme-HJzN2tOm.d.ts} +2 -2
  53. package/dist/web.d.ts +64 -18
  54. package/dist/web.js +7 -6
  55. package/migrations/0003_genesis_sites_post_dates.sql +117 -0
  56. package/migrations/tests/0003_genesis_sites_post_dates.test.sql +76 -0
  57. package/package.json +12 -4
  58. package/dist/assets/form-island.defb8daccc.js +0 -51
  59. package/dist/assets/islands.33a445f34e.js +0 -1
  60. package/dist/assets/sites-forms.aff23b5617.css +0 -10
  61. package/dist/assets/sites.5b3f64c627.css +0 -2
  62. package/dist/assets.generated-LLUGUUWZ.js +0 -3
  63. package/dist/chunk-7E3YGYVH.js.map +0 -1
  64. package/dist/chunk-IU6AI75R.js.map +0 -1
  65. package/dist/chunk-KY4ALBVH.js.map +0 -1
  66. package/dist/chunk-MU2Z2C4F.js.map +0 -1
  67. package/dist/chunk-RLYO6VVP.js +0 -19
  68. package/dist/chunk-RLYO6VVP.js.map +0 -1
  69. package/dist/chunk-SMJMXQ3T.js.map +0 -1
  70. package/dist/chunk-VJ4HOFBA.js.map +0 -1
  71. package/dist/handler-UMGSZY33.js +0 -10
@@ -1,4 +1,4 @@
1
- import { MAX_URL_LENGTH, isSafeHref, isSafeImageSrc, PAGE_PATH } from './chunk-MU2Z2C4F.js';
1
+ import { MAX_URL_LENGTH, isSafeHref, isSafeImageSrc, PAGE_PATH } from './chunk-CXBBUKGB.js';
2
2
  import { MAX_PLACEHOLDER, isSafePlaceholder } from '@marktiderman/genesis-media';
3
3
  import { z } from 'zod';
4
4
  import { FONT_IDS } from '@marktiderman/genesis-design-system/fonts';
@@ -87,7 +87,11 @@ var PageDoc = z.object({
87
87
  props: z.looseObject({
88
88
  title: z.string().trim().min(1).max(120),
89
89
  /** Leave out the site's header and footer (a focused landing page). */
90
- hideSiteChrome: z.boolean().optional()
90
+ hideSiteChrome: z.boolean().optional(),
91
+ /** Shown from this time (ISO, with an offset); before it, as if the page weren't there. */
92
+ showFrom: z.iso.datetime({ offset: true }).optional(),
93
+ /** Shown until this time (ISO, with an offset); from it, as if the page weren't there. */
94
+ showUntil: z.iso.datetime({ offset: true }).optional()
91
95
  })
92
96
  }),
93
97
  content: z.array(SectionNode).max(60),
@@ -102,7 +106,14 @@ var MenuItem = z.object({
102
106
  var Redirect = z.object({
103
107
  from: PagePath,
104
108
  to: Href,
105
- status: z.union([z.literal(301), z.literal(302)])
109
+ status: z.union([z.literal(301), z.literal(302)]),
110
+ /**
111
+ * `"prefix"`: also every address under `from` (`/people` takes
112
+ * `/people/ana`), where no page or post is: pages win. Unset: `from` only.
113
+ */
114
+ match: z.literal("prefix").optional(),
115
+ /** With `"prefix"` and a site path `to`: keep the rest of the address (`/people/ana` → `/team/ana`). */
116
+ keepRest: z.boolean().optional()
106
117
  });
107
118
  var FontChoice = z.enum(FONT_IDS);
108
119
  var BodyFontChoice = FontChoice.exclude(["bebas-neue"]);
@@ -122,6 +133,35 @@ var SeoDefaults = z.object({
122
133
  logo: z.string().max(MAX_URL_LENGTH).refine(isSafeImageSrc).optional(),
123
134
  sameAs: z.array(z.url({ protocol: /^https$/ }).max(MAX_URL_LENGTH)).max(10).optional()
124
135
  }).optional(),
136
+ /**
137
+ * The business at an address, for JSON-LD on the home page (and `pages`):
138
+ * `type` is a schema.org LocalBusiness type (`LocalBusiness`, or a more
139
+ * specific one such as `Store`); its logo, links and URL come from the site.
140
+ */
141
+ localBusiness: z.object({
142
+ type: z.string().regex(/^[A-Z][A-Za-z]{2,40}$/, "A schema.org type, such as LocalBusiness.").default("LocalBusiness"),
143
+ name: z.string().trim().min(1).max(120).optional(),
144
+ description: z.string().trim().max(300).optional(),
145
+ telephone: z.string().trim().regex(/^\+?[0-9 ().-]{5,30}$/).optional(),
146
+ email: z.email().max(254).optional(),
147
+ /** `YYYY`, `YYYY-MM` or `YYYY-MM-DD`. */
148
+ foundingDate: z.string().regex(/^\d{4}(-\d{2}){0,2}$/).optional(),
149
+ priceRange: z.string().trim().max(20).optional(),
150
+ image: z.string().max(MAX_URL_LENGTH).refine(isSafeImageSrc).optional(),
151
+ address: z.object({
152
+ streetAddress: z.string().trim().min(1).max(200),
153
+ addressLocality: z.string().trim().min(1).max(100),
154
+ addressRegion: z.string().trim().max(100).optional(),
155
+ postalCode: z.string().trim().max(20).optional(),
156
+ /** ISO 3166-1 alpha-2, such as US. */
157
+ addressCountry: z.string().regex(/^[A-Z]{2}$/).optional()
158
+ }),
159
+ geo: z.object({ latitude: z.number().min(-90).max(90), longitude: z.number().min(-180).max(180) }).optional(),
160
+ /** schema.org opening hours: `"Mo-Fr 06:00-20:00"`, `"Sa 08:00-12:00"`. */
161
+ 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(),
162
+ /** The pages that carry it besides the home page (a contact page). */
163
+ pages: z.array(z.string().max(200).regex(PAGE_PATH)).max(10).optional()
164
+ }).optional(),
125
165
  noindex: z.boolean().optional()
126
166
  });
127
167
  var SiteDoc = z.object({
@@ -165,7 +205,14 @@ var ReleasePage = z.object({
165
205
  var ReleaseSnapshot = z.object({
166
206
  schemaVersion: z.literal(1),
167
207
  site: SiteDoc,
168
- pages: z.array(ReleasePage).max(500)
208
+ pages: z.array(ReleasePage).max(500),
209
+ /**
210
+ * The brand the release was published with (a `BrandInput`). The live site
211
+ * renders with it, so a brand edit goes live with the next publish and a
212
+ * rollback brings back the look it had. Releases from before it have none:
213
+ * they render with the host's current brand.
214
+ */
215
+ brand: z.record(z.string(), z.unknown()).optional()
169
216
  });
170
217
  function parseSnapshot(value, report = (m) => console.error(`[genesis-sites] ${m}`)) {
171
218
  const raw = value && typeof value === "object" ? value : {};
@@ -184,162 +231,36 @@ function parseSnapshot(value, report = (m) => console.error(`[genesis-sites] ${m
184
231
  if (parsed.success) pages.push(parsed.data);
185
232
  else report(`the page ${JSON.stringify(page?.path ?? "?")} doesn't parse and is left out: ${parsed.error.message}`);
186
233
  }
187
- return { schemaVersion: 1, site: site.data, pages };
234
+ const brand = raw && typeof raw.brand === "object" && raw.brand !== null && !Array.isArray(raw.brand) ? raw.brand : void 0;
235
+ return { schemaVersion: 1, site: site.data, pages, ...brand ? { brand } : {} };
188
236
  }
189
237
  var MAX_DOC_BYTES = 512 * 1024;
190
- var SECTION_CATEGORIES = ["header", "intro", "content", "social-proof", "conversion", "footer"];
191
- var SectionDefinitionError = class extends Error {
192
- constructor(problems) {
193
- super(`Invalid section definition:
194
- ${problems.map((p) => ` - ${p}`).join("\n")}`);
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);
238
+
239
+ // src/core/not-found.ts
240
+ var NOT_FOUND_PATH = "/404";
241
+ function isNotFoundPage(page) {
242
+ return page.path === NOT_FOUND_PATH;
336
243
  }
337
- function nodeFromPreset(type, presetName, id = newSectionId(type.replace(/-/g, "").slice(0, 6))) {
338
- const def = registry.get(type);
339
- if (!def) throw new Error(`nodeFromPreset: no section "${type}" is registered.`);
340
- const preset = presetName ? def.presets.find((p) => p.name === presetName) : def.presets[0];
341
- if (!preset) throw new Error(`nodeFromPreset: "${type}" has no preset "${presetName}".`);
342
- return { id, type, v: def.version, variant: preset.variant, props: structuredClone(preset.props) };
244
+ function notFoundPageDoc(input = {}) {
245
+ const title = input.title?.trim() || "Page not found";
246
+ return {
247
+ schemaVersion: 1,
248
+ root: { props: { title: title.slice(0, 120) } },
249
+ content: [
250
+ {
251
+ id: "not-found",
252
+ type: "hero",
253
+ v: 1,
254
+ variant: "centered",
255
+ props: {
256
+ heading: title.slice(0, 90),
257
+ body: "There's no page at this address. It may have moved.",
258
+ primaryCta: { label: "Go to the home page", href: "/" }
259
+ }
260
+ }
261
+ ],
262
+ seo: { noindex: true }
263
+ };
343
264
  }
344
265
  var PostSlug = z.string().max(80).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "A post slug is lowercase letters, digits and single hyphens.");
345
266
  var PostAuthor = z.object({
@@ -424,8 +345,18 @@ function pageTitle(site, doc, _path) {
424
345
  const title = doc.root.props.title;
425
346
  const template = site.seo.titleTemplate;
426
347
  if (!template || !template.includes("%s")) return title;
348
+ const rest = trimSeparators(template.replace("%s", ""));
349
+ if (rest && rest.toLowerCase() === title.trim().toLowerCase()) return title;
427
350
  return template.replace("%s", title);
428
351
  }
352
+ var SEPARATOR = /[\s·|•—–:-]/;
353
+ function trimSeparators(text) {
354
+ let start = 0;
355
+ let end = text.length;
356
+ while (start < end && SEPARATOR.test(text[start])) start++;
357
+ while (end > start && SEPARATOR.test(text[end - 1])) end--;
358
+ return text.slice(start, end);
359
+ }
429
360
  function pageMeta({ site, page, origin, basePath = "", preview = false, article }) {
430
361
  const doc = page.doc;
431
362
  const title = pageTitle(site, doc, page.path);
@@ -479,6 +410,67 @@ function organizationJsonLd(site, origin, basePath = "") {
479
410
  if (org?.sameAs?.length) out.sameAs = org.sameAs;
480
411
  return out;
481
412
  }
413
+ function localBusinessJsonLd(site, path, origin, basePath = "") {
414
+ const biz = site.seo.localBusiness;
415
+ if (!biz || path !== "/" && !(biz.pages ?? []).includes(path)) return null;
416
+ const org = site.seo.organization;
417
+ const abs = (src) => src.startsWith("/") ? absoluteUrl(origin, basePath, src) : src;
418
+ const out = {
419
+ "@context": "https://schema.org",
420
+ "@type": biz.type ?? "LocalBusiness",
421
+ name: biz.name ?? org?.name ?? site.name,
422
+ url: absoluteUrl(origin, basePath, "/"),
423
+ address: { "@type": "PostalAddress", ...biz.address }
424
+ };
425
+ if (biz.description) out.description = biz.description;
426
+ if (biz.telephone) out.telephone = biz.telephone;
427
+ if (biz.email) out.email = biz.email;
428
+ if (biz.foundingDate) out.foundingDate = biz.foundingDate;
429
+ if (biz.priceRange) out.priceRange = biz.priceRange;
430
+ if (biz.image ?? org?.logo) out.image = abs(biz.image ?? org?.logo);
431
+ if (org?.logo) out.logo = abs(org.logo);
432
+ if (biz.geo) out.geo = { "@type": "GeoCoordinates", ...biz.geo };
433
+ if (biz.openingHours?.length) out.openingHours = biz.openingHours;
434
+ if (org?.sameAs?.length) out.sameAs = org.sameAs;
435
+ return out;
436
+ }
437
+ function answerText(answer) {
438
+ if (typeof answer === "string") return answer.trim();
439
+ const out = [];
440
+ const walk = (node) => {
441
+ if (!node || typeof node !== "object") return;
442
+ const n = node;
443
+ if (n.type === "text" && typeof n.text === "string") out.push(n.text);
444
+ else if (n.type === "hardBreak") out.push(" ");
445
+ if (Array.isArray(n.content)) {
446
+ n.content.forEach(walk);
447
+ if (n.type !== "doc") out.push(" ");
448
+ }
449
+ };
450
+ walk(answer);
451
+ return out.join("").replace(/\s+/g, " ").trim();
452
+ }
453
+ function faqPageJsonLd(page) {
454
+ const items = [];
455
+ const walk = (nodes) => {
456
+ for (const node of nodes) {
457
+ if (node.hidden) continue;
458
+ if (node.type === "faq" && Array.isArray(node.props.items)) {
459
+ for (const item of node.props.items) {
460
+ const answer = answerText(item?.answer);
461
+ if (typeof item?.question === "string" && item.question.trim() && answer) items.push({ question: item.question.trim(), answer });
462
+ }
463
+ }
464
+ }
465
+ };
466
+ walk(page.content);
467
+ if (!items.length) return null;
468
+ return {
469
+ "@context": "https://schema.org",
470
+ "@type": "FAQPage",
471
+ mainEntity: items.map((i) => ({ "@type": "Question", name: i.question, acceptedAnswer: { "@type": "Answer", text: i.answer } }))
472
+ };
473
+ }
482
474
  function websiteJsonLd(site, origin, basePath = "") {
483
475
  return {
484
476
  "@context": "https://schema.org",
@@ -577,7 +569,7 @@ function escapeXml(text) {
577
569
  return text.replace(/[<>&'"]/g, (c) => ({ "<": "&lt;", ">": "&gt;", "&": "&amp;", "'": "&apos;", '"': "&quot;" })[c]);
578
570
  }
579
571
  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) => {
572
+ 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
573
  const loc = `<loc>${escapeXml(absoluteUrl(origin, basePath, p.path))}</loc>`;
582
574
  const mod = lastModified ? `<lastmod>${escapeXml(new Date(lastModified).toISOString())}</lastmod>` : "";
583
575
  return `<url>${loc}${mod}</url>`;
@@ -606,10 +598,269 @@ function redirectsAfterMove(redirects, from, to) {
606
598
  next.push({ from, to, status: 301 });
607
599
  return next;
608
600
  }
601
+ function isUnderPrefix(path, from) {
602
+ return path === from || path.startsWith(`${from}/`);
603
+ }
609
604
  function matchRedirect(redirects, path) {
610
- return redirects.find((r) => r.from === path && isSafeHref(r.to));
605
+ return redirects.find((r) => r.match !== "prefix" && r.from === path && isSafeHref(r.to));
606
+ }
607
+ function matchPrefixRedirect(redirects, path) {
608
+ let best;
609
+ for (const r of redirects) {
610
+ if (r.match !== "prefix" || !isSafeHref(r.to) || !isUnderPrefix(path, r.from)) continue;
611
+ if (!best || r.from.length > best.from.length) best = r;
612
+ }
613
+ if (!best) return void 0;
614
+ const rest = path.slice(best.from.length);
615
+ if (!best.keepRest || !rest || !best.to.startsWith("/")) return { redirect: best, to: best.to };
616
+ const escaped = rest.split("/").map(escapePathSegment).join("/");
617
+ const cut = best.to.search(/[?#]/);
618
+ const base = cut < 0 ? best.to : best.to.slice(0, cut);
619
+ const tail = cut < 0 ? "" : best.to.slice(cut);
620
+ return { redirect: best, to: `${base === "/" ? "" : base.replace(/\/+$/, "")}${escaped}${tail}` };
621
+ }
622
+ function escapePathSegment(segment) {
623
+ return encodeURIComponent(segment).replace(/%(?:21|24|26|27|28|29|2A|2B|2C|3A|3B|3D|40)/gi, (m) => decodeURIComponent(m));
624
+ }
625
+ function redirectTargetPath(to) {
626
+ if (!to.startsWith("/")) return null;
627
+ const path = to.split(/[?#]/)[0];
628
+ let decoded = path;
629
+ try {
630
+ decoded = decodeURIComponent(path);
631
+ } catch {
632
+ }
633
+ const lower = decoded.toLowerCase();
634
+ return lower.length > 1 && lower.endsWith("/") ? lower.slice(0, -1) : lower;
635
+ }
636
+ function redirectStep(redirects, hasPage) {
637
+ return (path) => {
638
+ const exact = matchRedirect(redirects, path);
639
+ if (exact) return redirectTargetPath(exact.to);
640
+ if (hasPage(path)) return null;
641
+ const prefix = matchPrefixRedirect(redirects, path);
642
+ return prefix ? redirectTargetPath(prefix.to) : null;
643
+ };
644
+ }
645
+ function redirectLoops(redirects, hasPage = () => false, maxHops = 10) {
646
+ const step = redirectStep(redirects, hasPage);
647
+ const loops = [];
648
+ for (const r of redirects) {
649
+ const starts = r.match === "prefix" ? [r.from, `${r.from === "/" ? "" : r.from}/x-check`] : [r.from];
650
+ const loops_ = starts.some((start) => {
651
+ const seen = /* @__PURE__ */ new Set([start]);
652
+ let at = start;
653
+ for (let hop = 0; hop <= maxHops; hop++) {
654
+ at = step(at);
655
+ if (at === null) return false;
656
+ if (seen.has(at)) return true;
657
+ seen.add(at);
658
+ }
659
+ return true;
660
+ });
661
+ if (loops_) loops.push(r.from);
662
+ }
663
+ return loops;
664
+ }
665
+ var SECTION_CATEGORIES = ["header", "intro", "content", "social-proof", "conversion", "footer"];
666
+ var SectionDefinitionError = class extends Error {
667
+ constructor(problems) {
668
+ super(`Invalid section definition:
669
+ ${problems.map((p) => ` - ${p}`).join("\n")}`);
670
+ this.problems = problems;
671
+ this.name = "SectionDefinitionError";
672
+ }
673
+ problems;
674
+ };
675
+ var TYPE = /^[a-z][a-z0-9-]{0,63}$/;
676
+ function definitionProblems(def) {
677
+ const problems = [];
678
+ if (!def || typeof def !== "object") return ["a section definition is an object"];
679
+ const at = typeof def.type === "string" ? `"${def.type}"` : "a section";
680
+ if (typeof def.type !== "string" || !TYPE.test(def.type)) problems.push(`${at}: \`type\` is lowercase letters, digits and -`);
681
+ if (!Number.isInteger(def.version) || def.version < 1) problems.push(`${at}: \`version\` is a whole number from 1`);
682
+ if (typeof def.label !== "string" || !def.label.trim()) problems.push(`${at}: needs a \`label\``);
683
+ if (!SECTION_CATEGORIES.includes(def.category)) problems.push(`${at}: \`category\` is one of ${SECTION_CATEGORIES.join(", ")}`);
684
+ if (!def.schema || typeof def.schema.safeParse !== "function") problems.push(`${at}: \`schema\` is a zod schema`);
685
+ if (typeof def.render !== "function") problems.push(`${at}: \`render\` is a function`);
686
+ const ids = /* @__PURE__ */ new Set();
687
+ if (!Array.isArray(def.variants) || def.variants.length === 0) problems.push(`${at}: needs at least one variant`);
688
+ else
689
+ for (const v of def.variants) {
690
+ 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 }`);
691
+ else if (ids.has(v.id)) problems.push(`${at}: variant "${v.id}" is listed twice`);
692
+ else ids.add(v.id);
693
+ }
694
+ if (!ids.has(def.defaultVariant)) problems.push(`${at}: \`defaultVariant\` "${String(def.defaultVariant)}" is not one of its variants`);
695
+ if (def.limit !== void 0 && (!Number.isInteger(def.limit) || def.limit < 1)) problems.push(`${at}: \`limit\` is a whole number from 1`);
696
+ if (def.placement !== void 0 && !["header", "body", "footer"].includes(def.placement)) problems.push(`${at}: \`placement\` is header, body or footer`);
697
+ if (def.frameOrigins !== void 0 && typeof def.frameOrigins !== "function") problems.push(`${at}: \`frameOrigins\` is a function`);
698
+ for (const [key, fn] of Object.entries(def.migrations ?? {})) {
699
+ const n = Number(key);
700
+ if (!Number.isInteger(n) || n < 2 || n > def.version) problems.push(`${at}: migration ${key} must be between 2 and the version (${def.version})`);
701
+ if (typeof fn !== "function") problems.push(`${at}: migration ${key} is a function`);
702
+ }
703
+ for (let n = 2; n <= (Number.isInteger(def.version) ? def.version : 0); n++) {
704
+ if (!def.migrations?.[n]) problems.push(`${at}: version ${def.version} needs a migration to ${n}`);
705
+ }
706
+ if (!Array.isArray(def.presets) || def.presets.length === 0) problems.push(`${at}: needs at least one preset (the editor's Add picker)`);
707
+ else if (def.schema && typeof def.schema.safeParse === "function")
708
+ for (const preset of def.presets) {
709
+ if (!preset || typeof preset.name !== "string" || !ids.has(preset.variant)) {
710
+ problems.push(`${at}: preset ${JSON.stringify(preset?.name)} needs a name and one of its variants`);
711
+ continue;
712
+ }
713
+ const parsed = def.schema.safeParse(preset.props);
714
+ 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("; ")}`);
715
+ }
716
+ return problems;
717
+ }
718
+ function defineSection(def) {
719
+ const problems = definitionProblems(def);
720
+ if (problems.length) throw new SectionDefinitionError(problems);
721
+ return Object.freeze({
722
+ ...def,
723
+ variants: Object.freeze(def.variants.map((v) => Object.freeze({ ...v }))),
724
+ presets: Object.freeze(def.presets.map((p) => Object.freeze({ ...p }))),
725
+ ...def.enabledOn ? { enabledOn: Object.freeze([...def.enabledOn]) } : {},
726
+ ...def.migrations ? { migrations: Object.freeze({ ...def.migrations }) } : {}
727
+ });
728
+ }
729
+ var REGISTRY = /* @__PURE__ */ Symbol.for("@marktiderman/genesis-sites/sections@1");
730
+ var BUILT_IN = /* @__PURE__ */ Symbol.for("@marktiderman/genesis-sites/built-in-sections@1");
731
+ var scope = globalThis;
732
+ var registry = scope[REGISTRY] ??= /* @__PURE__ */ new Map();
733
+ var builtIns = scope[BUILT_IN] ??= /* @__PURE__ */ new Set();
734
+ var BUILT_IN_SECTION_TYPES = Object.freeze([
735
+ "nav",
736
+ "hero",
737
+ "features",
738
+ "cta",
739
+ "testimonials",
740
+ "faq",
741
+ "pricing",
742
+ "logos",
743
+ "stats",
744
+ "gallery",
745
+ "rich-text",
746
+ "form-embed",
747
+ "footer",
748
+ "schedule",
749
+ "team",
750
+ "blog-list",
751
+ "post-body",
752
+ "map",
753
+ "timeline",
754
+ "file"
755
+ ]);
756
+ function registerSection(def, options = {}) {
757
+ const frozen = Object.isFrozen(def) && definitionProblems(def).length === 0 ? def : defineSection(def);
758
+ if (BUILT_IN_SECTION_TYPES.includes(frozen.type) && options.replace !== true) {
759
+ throw new Error(
760
+ `registerSection: "${frozen.type}" is a built-in section; pass { replace: true } to replace it for every site in this process.`
761
+ );
762
+ }
763
+ registry.set(frozen.type, frozen);
764
+ }
765
+ function registerBuiltInSection(def) {
766
+ if (!registry.has(def.type)) registry.set(def.type, def);
767
+ builtIns.add(def.type);
768
+ }
769
+ function getSection(type) {
770
+ return registry.get(type);
771
+ }
772
+ function listSections() {
773
+ return [...registry.values()];
774
+ }
775
+ function unregisterSection(type) {
776
+ if (BUILT_IN_SECTION_TYPES.includes(type)) throw new Error(`unregisterSection: "${type}" is built in; replace it with registerSection(\u2026, { replace: true }).`);
777
+ return registry.delete(type);
778
+ }
779
+ var jsonSchemas = /* @__PURE__ */ new WeakMap();
780
+ function sectionJsonSchema(typeOrDef) {
781
+ const def = typeof typeOrDef === "string" ? registry.get(typeOrDef) : typeOrDef;
782
+ if (!def) throw new Error(`sectionJsonSchema: no section "${String(typeOrDef)}" is registered.`);
783
+ let schema = jsonSchemas.get(def.schema);
784
+ if (!schema) {
785
+ schema = z.toJSONSchema(def.schema, { io: "input", unrepresentable: "any" });
786
+ jsonSchemas.set(def.schema, schema);
787
+ }
788
+ return schema;
789
+ }
790
+ function sectionManifests() {
791
+ return listSections().map((def) => ({
792
+ type: def.type,
793
+ version: def.version,
794
+ label: def.label,
795
+ ...def.description ? { description: def.description } : {},
796
+ category: def.category,
797
+ placement: def.placement ?? "body",
798
+ variants: def.variants,
799
+ defaultVariant: def.defaultVariant,
800
+ presets: def.presets,
801
+ ...def.limit ? { limit: def.limit } : {},
802
+ ...def.enabledOn ? { enabledOn: def.enabledOn } : {},
803
+ jsonSchema: sectionJsonSchema(def)
804
+ }));
805
+ }
806
+ var counter = 0;
807
+ function newSectionId(prefix = "s") {
808
+ counter = (counter + 1) % 1e6;
809
+ const random = Math.random().toString(36).slice(2, 8);
810
+ return `${prefix}${Date.now().toString(36)}${counter.toString(36)}${random}`.slice(0, 64);
811
+ }
812
+ function nodeFromPreset(type, presetName, id = newSectionId(type.replace(/-/g, "").slice(0, 6))) {
813
+ const def = registry.get(type);
814
+ if (!def) throw new Error(`nodeFromPreset: no section "${type}" is registered.`);
815
+ const preset = presetName ? def.presets.find((p) => p.name === presetName) : def.presets[0];
816
+ if (!preset) throw new Error(`nodeFromPreset: "${type}" has no preset "${presetName}".`);
817
+ return { id, type, v: def.version, variant: preset.variant, ...preset.sample ? { placeholder: true } : {}, props: structuredClone(preset.props) };
818
+ }
819
+
820
+ // src/core/sample-images.ts
821
+ var SAMPLE_IMAGE_PREFIX = "/_gs/sample/";
822
+ var LEGACY_SAMPLES = {
823
+ "/photo-1.jpg": "photo",
824
+ "/photo-2.jpg": "photo",
825
+ "/photo-3.jpg": "photo",
826
+ "/logo-partner.svg": "logo"
827
+ };
828
+ var svg = (body, w, h) => `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${w} ${h}" width="${w}" height="${h}">${body}</svg>`)}`;
829
+ var SAMPLES = {
830
+ // A grey frame with a sun and hills: a photo goes here.
831
+ photo: {
832
+ src: svg(
833
+ `<rect width="800" height="800" fill="gainsboro"/><circle cx="560" cy="270" r="70" fill="silver"/><path d="M0 620 L250 360 L430 540 L560 420 L800 640 L800 800 L0 800 Z" fill="silver"/>`,
834
+ 800,
835
+ 800
836
+ ),
837
+ width: 800,
838
+ height: 800
839
+ },
840
+ // A rounded grey mark: a logo goes here.
841
+ logo: {
842
+ src: svg(`<rect x="4" y="4" width="232" height="72" rx="14" fill="none" stroke="darkgray" stroke-width="4" stroke-dasharray="10 8"/><text x="120" y="50" font-family="system-ui, sans-serif" font-size="24" fill="gray" text-anchor="middle">Logo</text>`, 240, 80),
843
+ width: 240,
844
+ height: 80
845
+ }
846
+ };
847
+ var sampleName = (src) => {
848
+ if (typeof src !== "string") return null;
849
+ if (src.startsWith(SAMPLE_IMAGE_PREFIX)) {
850
+ const name = src.slice(SAMPLE_IMAGE_PREFIX.length).replace(/\.svg$/, "");
851
+ return name in SAMPLES ? name : null;
852
+ }
853
+ return LEGACY_SAMPLES[src] ?? null;
854
+ };
855
+ function isSampleImage(src) {
856
+ return sampleName(src) !== null;
857
+ }
858
+ function sampleImage(src) {
859
+ const name = sampleName(src);
860
+ return name ? SAMPLES[name] : null;
611
861
  }
862
+ var samplePath = (name) => `${SAMPLE_IMAGE_PREFIX}${name}.svg`;
612
863
 
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-IU6AI75R.js.map
615
- //# sourceMappingURL=chunk-IU6AI75R.js.map
864
+ 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, isSampleImage, isUnderPrefix, listSections, localBusinessJsonLd, matchPrefixRedirect, matchRedirect, newSectionId, nodeFromPreset, notFoundPageDoc, opensInNewTab, organizationJsonLd, pageMeta, pageTitle, parseSnapshot, postDescription, postPath, postSummary, redirectLoops, redirectsAfterMove, registerBuiltInSection, registerSection, richTextPlain, robotsTxt, rssXml, safeJsonForHtml, sampleImage, samplePath, sectionJsonSchema, sectionManifests, sitemapXml, unregisterSection, validatePostSlug, websiteJsonLd };
865
+ //# sourceMappingURL=chunk-QGU6FDH5.js.map
866
+ //# sourceMappingURL=chunk-QGU6FDH5.js.map