@se-studio/project-build 1.6.0 → 1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @se-studio/project-build
2
2
 
3
+ ## 1.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 621653a: marketing-routes.json gains `peopleTypeSlug` (CMS custom type slug for people when it differs from the `peopleSlug` URL; written as `PEOPLE_TYPE_SLUG`, kept by `--from-cms --write`) and `segmentConfig` (path-keyed literal `dynamic`, `revalidate`, `dynamicParams`, `fetchCache`, `runtime`, `preferredRegion` exports on generated pages; illegal keys, values and paths are rejected). Bugfix: `enableArticleTypeIndex` is now true only when `articlesSlug` is a non-empty string, so a site with article types and no `articlesSlug` no longer gets a phantom `/articles/` index (regenerate `marketing-flags.ts`). `check-marketing-routes` accepts `route-build-policy.json` entries for pages on `allowHandWrittenPages`. `generate-marketing-routes --write` keeps hand-added `route-build-policy.json` entries for `allowHandWrittenPages` pages, `check-marketing-routes` now fails on an illegal `segmentConfig` instead of swallowing the render error, `enableArticleTypeTagIndex` is documented as intentionally independent of `articlesSlug`, and the README notes that `dynamic: 'force-dynamic'` and `runtime: 'edge'` opt out of static rendering for that route.
8
+
9
+ ## 1.7.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 680a9af: `check-marketing-routes` now fails closed. A missing `src/lib/marketing-routes.json` fails unless a repo that has not migrated adds `src/lib/marketing-routes.opt-out.json` with a non-empty `reason` (migration: add the config with `generate-marketing-routes . --from-cms --write`, or add the opt-out file; an opt-out beside a real config fails). The check scans every `page.ts` / `page.tsx` under `src/app` and also polices `route.ts` under `(cms-routes)` or shadowing a generated URL. `allowHandWrittenPages` entries become `{ path, reason }` (the bare string form is deprecated and warns).
14
+
15
+ `generate-marketing-routes`: per-type `detailPages: false` (index only, served at `indexSlug`) and `nestedSlugs: true` (`/{type}/[...slugs]`) in object-form `articleTypes`, kept across `--from-cms --write`; `excludeArticleTypes`; tag and person types with no slug are skipped with a warning instead of failing; `route-build-policy.json` uses the real param names; `marketing-slugs.ts` marks index-only routes and exports `ARTICLE_DETAIL_TYPE_SLUGS` only when a type opts in. `--force` without `--write` is now a dry run (it used to write). Sites that set none of the new options generate exactly what they did.
16
+
3
17
  ## 1.6.0
4
18
 
5
19
  ### Minor Changes
package/README.md CHANGED
@@ -133,6 +133,30 @@ check-marketing-routes . # fail hand-written (cms-route
133
133
 
134
134
  `generate-marketing-routes` honours the same list. It never writes, replaces or deletes a page on `allowHandWrittenPages`, with or without `--force`. Matching is by URL shape: `page.ts` and `page.tsx` are one page, `[slug]` equals `[article]` or `[person]` at the same position, and a parent never covers its child (`people` does not cover `people/[person]`). An entry may be a rest (`resources/[slug]`), with the file name, or a full `src/app/(cms-routes)/...` path. `--force` replaces only files with the `@generated` header; any other existing page at a generated URL is left and printed as kept. Hand-route cleanup removes only `page.ts` / `page.tsx`, never renderers or helpers beside them. `--from-cms --write` keeps `allowHandWrittenPages`, and the URL shape keys below. `tagTypeRoutes: false` lets `--from-cms` succeed on a space whose tag types have no slug (it skips every tag type). To adopt it on a site with custom listings, allowlist those pages (for example `resources`, `resources/[slug]`, `tag/[slug]`) and run `pnpm generate:routes`.
135
135
 
136
+ ##### Fail-closed checker, opt-out, and allowlist reasons
137
+
138
+ `check-marketing-routes` is filesystem only (no CMS secrets). It fails when:
139
+
140
+ - `src/lib/marketing-routes.json` is **missing**. A repo that has not migrated yet opts out explicitly with `src/lib/marketing-routes.opt-out.json`: `{ "reason": "not migrated, see SE-123" }`. The reason is required; the check then passes with a warning that prints it. An opt-out beside a real `marketing-routes.json` fails (delete it once migrated). **Migration note:** before this version a missing config only warned; a repo with none now fails until it adds the config (`generate-marketing-routes . --from-cms --write`) or the opt-out file.
141
+ - any `page.ts` / `page.tsx` under `src/app` is not generated or allowlisted (the whole tree is scanned, modified files included, not only new ones), or a `route.ts` / `route.tsx` sits under `(cms-routes)` or shadows a generated marketing URL. `api`, `sitemap.xml`, `og` and other fixed handlers are untouched.
142
+ - an `allowHandWrittenPages` object has no `reason`.
143
+
144
+ `allowHandWrittenPages` entries are `{ "path": "preview", "reason": "Contentful preview entry" }`. The bare string form still works but is deprecated: `check-marketing-routes` and `generate-marketing-routes` print a warning for each. A preview page, `resource-list-cards` and other non-CMS pages go here too.
145
+
146
+ ##### Article type options, exclusions, and dry run
147
+
148
+ Object-form `articleTypes` entries take per-type options. `--from-cms --write` rewrites `articleTypes` from the CMS but carries these over for types that still exist, so write them in `marketing-routes.json`:
149
+
150
+ | Key | Meaning | Default |
151
+ |-----|---------|---------|
152
+ | `detailPages: false` | Index-only type. The index is served at `indexSlug` (`{ "slug": "sketch", "indexSlug": "more", "detailPages": false }` is `/more/`) and no `/{slug}/{article}/` or `/{indexSlug}/{article}/` page, policy entry or sitemap detail is generated. `marketing-slugs.ts` marks the route `detailPages: false` and exports `ARTICLE_DETAIL_TYPE_SLUGS` | detail pages on |
153
+ | `nestedSlugs: true` | Detail pages are `/{slug}/[...slugs]` (`/work/{client}/{case}/`, slug `client/case`) instead of one `[article]` segment. `route-build-policy.json` lists the real param name | `[article]` |
154
+ | `excludeArticleTypes: ["draft"]` (top level) | A CMS article type that stays off. Kept across `--from-cms --write` | none |
155
+
156
+ Neither option works with `tagInPath`. A tag type or person type with no slug is skipped with a warning (it used to fail `--from-cms`). A config with none of this generates exactly what it did before.
157
+
158
+ `--force` replaces only `@generated` files and only together with `--write`: without `--write` the generator never writes (a previous version wrote with `--force` alone).
159
+
136
160
  ##### URL shape: index and detail slugs, index switches, custom tag listing
137
161
 
138
162
  A section config (`peopleSlug` / `tagsSlug`) can put the index and the detail pages at different segments. All four keys are optional. A config with none of them generates exactly what it did before.
@@ -158,6 +182,19 @@ An index that is off writes no page (so it 404s) and the matching `enable…Inde
158
182
 
159
183
  That serves `/people/` and `/person/{slug}/`, and `/tag/{slug}/` with no `/tags/`. The generated person and tag pages pass their own served path to the handlers, so the canonical is always the URL that served the page. A config that declares any of the four keys also writes `PERSON_DETAIL_BASE` / `PERSON_DETAIL_SLUG` and `TAG_DETAIL_BASE` / `TAG_DETAIL_SLUG` into `src/generated/marketing-slugs.ts`. Build person and tag links (`section-urls.ts`, `urlCalculators`, sitemap sources) from those constants, not from `PEOPLE_BASE` / `TAGS_BASE`, or internal links point at the index segment while the page lives at the detail segment.
160
184
 
185
+ ##### People custom type slug, segment config, and the article-type index flag
186
+
187
+ | Key | Meaning | Default |
188
+ |-----|---------|---------|
189
+ | `peopleTypeSlug` | CMS custom type slug backing the people section, when it differs from the URL (`/people/` and `/person/{slug}/`, custom type `person`). Written as `PEOPLE_TYPE_SLUG` in `marketing-slugs.ts` and used for `getCustomType`, the person `customType` lookup and the sitemap people backing type. `peopleSlug` / `personSlug` stay the URL segments. `--from-cms --write` keeps it | the value of `peopleSlug` (no constant is written) |
190
+ | `segmentConfig` | `{ "<generated page path>": { "dynamic": "force-static" } }`. Each key is written as `export const key = <literal>;` at the end of that generated page. Allowed keys: `dynamic`, `revalidate`, `dynamicParams`, `fetchCache`, `runtime`, `preferredRegion`, each with a literal value Next.js accepts. An unknown key, a non-literal value, a path that is not a generated page, or a path on `allowHandWrittenPages` is an error. The checker flags a page edited away from it. `--from-cms --write` keeps it | none: no extra exports |
191
+
192
+ `enableArticleTypeIndex` (bugfix, not an opt-in) is `true` only when `articlesSlug` is a non-empty string. It used to be `true` for a site with article types and `articlesSlug: null`, which could add a phantom `/articles/` sitemap entry. Article type index pages at their `indexSlug` are unaffected. `enableArticleTypeTagIndex` is deliberately **not** tied to `articlesSlug`: it stays `tagInPath && (articlesSlug || articleTypes)` because tag-in-path indexes live on article-type routes such as `/resources/events/{tag}/` and need no parent hub. A site with `tagInPath: true`, `articlesSlug: null` and `articleTypes` keeps `enableArticleTypeTagIndex = true` (and `enableArticleTypeIndex = false`), so its tag URLs stay in the sitemap. A site that kept `enableArticleTypeIndex = false` by hand can drop that after regenerating; a site with `articlesSlug` set sees no change.
193
+
194
+ **`segmentConfig` trades away static rendering.** `dynamic: 'force-dynamic'` and `runtime: 'edge'` are accepted by design, as opt-ins. Each one removes static rendering (SSG/ISR, and the R5 `mustBeSsgOrStatic` guarantee for that route) from that generated CMS route: the page renders per request, or on the edge runtime with its limits. Use them only on a page that really needs it. `force-static`, `revalidate` and `dynamicParams` keep the route static. `check-marketing-routes` fails when `segmentConfig` is illegal (unknown key, non-literal value, a path that is not a generated page or is on `allowHandWrittenPages`), the same error `generate-marketing-routes` reports.
195
+
196
+ **Hand-added build policy for allowlisted pages.** `generate-marketing-routes --write` regenerates the generated-route entries of `mustBeSsgOrStatic` but keeps hand-added entries that match an `allowHandWrittenPages` entry by URL shape; other unknown routes are dropped. `check-marketing-routes` accepts a `route-build-policy.json` `mustBeSsgOrStatic` entry whose route matches an `allowHandWrittenPages` entry (by URL shape), so a hand-written page keeps the SSG guard. A route that is neither generated nor allowlisted still fails.
197
+
161
198
  **Keep a custom tag listing or filter.** Pass `renderTagListing` to `createRouteHandlers` in `src/lib/route-handlers.ts`. `generateTagPage` calls it after the tag's own content and renders the result inside the layout, so the generated `tag/[tag]` page keeps the site's filter tabs and article list with no hand-written route and no generator fork:
162
199
 
163
200
  ```tsx
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * Fail hand-written (cms-routes) page.ts files that are not in
4
- * src/lib/marketing-routes.json (or its allowHandWrittenPages list).
3
+ * Fail hand-written page.ts / page.tsx / route.ts files under src/app that are not in
4
+ * src/lib/marketing-routes.json (or its allowHandWrittenPages list). Fails when
5
+ * marketing-routes.json is missing unless src/lib/marketing-routes.opt-out.json
6
+ * holds {"reason": "..."} (repos not yet migrated). Filesystem only: no CMS secrets.
5
7
  *
6
8
  * Usage (core): node scripts/check-marketing-routes.mjs <app-dir>
7
9
  * Usage (customer): check-marketing-routes <app-dir> (@se-studio/project-build bin)
@@ -18,6 +20,9 @@ if (!app) {
18
20
 
19
21
  const result = checkMarketingRoutes(path.resolve(app));
20
22
  console.log(result.detail);
23
+ for (const warning of result.warnings ?? []) {
24
+ console.warn(`warning: ${warning}`);
25
+ }
21
26
  if (!result.ok) {
22
27
  process.exit(1);
23
28
  }
@@ -32,6 +32,13 @@
32
32
  * that config and formats the generated `(cms-routes)` pages with the app's
33
33
  * Biome. `allowedDynamic` is left as it is.
34
34
  *
35
+ * Article type options (object form of `articleTypes`, kept across `--from-cms --write`):
36
+ * `detailPages: false` (index only, served at `indexSlug`), `nestedSlugs: true`
37
+ * (`/{type}/[...slugs]`). `excludeArticleTypes: ["slug"]` keeps a CMS type off.
38
+ * Tag and person types with no slug are skipped with a warning.
39
+ *
40
+ * Without `--write` nothing is written, with or without `--force`.
41
+ *
35
42
  * Usage:
36
43
  * node scripts/generate-marketing-routes.mjs <app-dir> [--from-cms] [--write] [--force]
37
44
  * generate-marketing-routes <app-dir> [--from-cms] [--write] [--force]
@@ -41,15 +48,17 @@ import fs from 'node:fs';
41
48
  import path from 'node:path';
42
49
  import { fileURLToPath } from 'node:url';
43
50
  import {
51
+ articleTypeOptionsFromHand,
44
52
  fetchContentSlugs,
45
53
  mergeCmsEnv,
46
54
  planFromCms,
47
55
  sectionConfigFromPlan,
48
56
  } from './marketing-routes-cms.mjs';
49
- import { readMarketingRoutes, syncGeneratedRoutes } from './marketing-routes.mjs';
57
+ import { parseAllowlist, readMarketingRoutes, syncGeneratedRoutes } from './marketing-routes.mjs';
50
58
 
51
59
  const args = process.argv.slice(2).filter((arg) => !arg.startsWith('--'));
52
- const write = process.argv.includes('--write') || process.argv.includes('--force');
60
+ // --force only widens what --write may replace; on its own it is still a dry run.
61
+ const write = process.argv.includes('--write');
53
62
  const force = process.argv.includes('--force');
54
63
  const fromCms = process.argv.includes('--from-cms');
55
64
  const app = args[0];
@@ -82,6 +91,7 @@ if (fromCms) {
82
91
  articleTypes,
83
92
  tagTypes,
84
93
  peopleSlug: hand.peopleSlug,
94
+ peopleTypeSlug: hand.peopleTypeSlug,
85
95
  tagsSlug: hand.tagsSlug,
86
96
  articlesSlug: hand.articlesSlug,
87
97
  personSlug: hand.personSlug,
@@ -90,11 +100,16 @@ if (fromCms) {
90
100
  enableTagsIndex: hand.enableTagsIndex,
91
101
  tagInPath: hand.tagInPath === true,
92
102
  tagTypeRoutes: hand.tagTypeRoutes !== false,
103
+ excludeArticleTypes: Array.isArray(hand.excludeArticleTypes) ? hand.excludeArticleTypes : [],
104
+ articleTypeOptions: articleTypeOptionsFromHand(hand),
93
105
  });
94
106
  if (!plan.ok) {
95
107
  console.error(plan.problems.join('\n'));
96
108
  process.exit(1);
97
109
  }
110
+ for (const warning of plan.warnings) {
111
+ console.warn(`warning: ${warning}`);
112
+ }
98
113
  const next = sectionConfigFromPlan(hand, plan);
99
114
  const configPath = path.join(appRoot, 'src/lib/marketing-routes.json');
100
115
  if (!write) {
@@ -105,7 +120,17 @@ if (fromCms) {
105
120
  console.log(`Updated ${configPath}`);
106
121
  }
107
122
 
123
+ if (force && !write) {
124
+ console.warn('--force without --write is a dry run: nothing is written. Add --write.');
125
+ }
108
126
  const result = syncGeneratedRoutes(appRoot, { write, force });
127
+ try {
128
+ for (const warning of parseAllowlist(readMarketingRoutes(appRoot)).warnings) {
129
+ console.warn(`warning: ${warning}`);
130
+ }
131
+ } catch {
132
+ // an invalid allowlist is reported by check-marketing-routes
133
+ }
109
134
  for (const note of result.tagSkips) {
110
135
  console.log(note);
111
136
  }
@@ -64,6 +64,16 @@ export function contentfulReadTarget(env) {
64
64
  };
65
65
  }
66
66
 
67
+ /**
68
+ * A type with no slug has no URL. Tag and person types are skipped with a warning
69
+ * rather than failing the whole run.
70
+ *
71
+ * @param {{ slug?: string } | undefined} entry
72
+ */
73
+ function isSlugless(entry) {
74
+ return typeof entry?.slug !== 'string' || entry.slug.length === 0;
75
+ }
76
+
67
77
  /**
68
78
  * @param {string | undefined} slug
69
79
  * @param {string} label
@@ -108,10 +118,12 @@ function pathOrNull(slug, label, problems) {
108
118
  * `tags`. Role words still win when the slug is `people`, `tags`, or `articles`.
109
119
  *
110
120
  * @param {string} slug
111
- * @param {{ person?: string | null, tag?: string | null, article?: string | null }} declared
121
+ * @param {{ person?: string | null, personType?: string | null, tag?: string | null, article?: string | null }} declared
112
122
  */
113
123
  function declaredRole(slug, declared) {
114
- if (declared.person && declared.person === slug) return 'person';
124
+ if (declared.person && (declared.person === slug || declared.personType === slug)) {
125
+ return 'person';
126
+ }
115
127
  if (declared.tag && declared.tag === slug) return 'tag';
116
128
  if (declared.article && declared.article === slug) return 'article';
117
129
  return null;
@@ -119,7 +131,7 @@ function declaredRole(slug, declared) {
119
131
 
120
132
  /**
121
133
  * @param {{ slug?: string, name?: string }} entry
122
- * @param {{ person?: string | null, tag?: string | null, article?: string | null }} declared
134
+ * @param {{ person?: string | null, personType?: string | null, tag?: string | null, article?: string | null }} declared
123
135
  * @returns {{ role: string, slug: string } | { error: string }}
124
136
  */
125
137
  function prefixOf(entry, declared) {
@@ -228,6 +240,7 @@ function claimRest(used, rest, label, problems) {
228
240
  * articleTypes?: { slug?: string, name?: string, indexPageSlug?: string }[],
229
241
  * tagTypes?: { slug?: string, name?: string, show?: boolean }[],
230
242
  * peopleSlug?: string | null,
243
+ * peopleTypeSlug?: string | null,
231
244
  * tagsSlug?: string | null,
232
245
  * articlesSlug?: string | null,
233
246
  * personSlug?: string | null,
@@ -236,13 +249,20 @@ function claimRest(used, rest, label, problems) {
236
249
  * enableTagsIndex?: boolean,
237
250
  * tagInPath?: boolean,
238
251
  * tagTypeRoutes?: boolean,
252
+ * excludeArticleTypes?: string[],
253
+ * articleTypeOptions?: Record<string, { detailPages?: boolean, nestedSlugs?: boolean }>,
239
254
  * }} input
240
255
  */
241
256
  export function planFromCms(input) {
242
257
  /** @type {string[]} */
243
258
  const problems = [];
259
+ /** @type {string[]} */
260
+ const warnings = [];
261
+ const excluded = new Set(input.excludeArticleTypes ?? []);
262
+ const options = input.articleTypeOptions ?? {};
244
263
  const declared = {
245
264
  person: handSlug(input, 'peopleSlug', null),
265
+ personType: handSlug(input, 'peopleTypeSlug', null),
246
266
  tag: handSlug(input, 'tagsSlug', null),
247
267
  article: handSlug(input, 'articlesSlug', null),
248
268
  };
@@ -270,6 +290,10 @@ export function planFromCms(input) {
270
290
  /** @type {string[]} */
271
291
  const personTypes = [];
272
292
  for (const entry of input.personTypes ?? []) {
293
+ if (isSlugless(entry)) {
294
+ warnings.push(`skipped person type "${entry?.name ?? '(unnamed)'}": no slug`);
295
+ continue;
296
+ }
273
297
  const slug = segmentOrNull(entry?.slug, 'person type', problems);
274
298
  if (slug) {
275
299
  personTypes.push(slug);
@@ -282,12 +306,17 @@ export function planFromCms(input) {
282
306
  if (entry?.show === false || !tagTypeRoutes) {
283
307
  continue;
284
308
  }
309
+ if (isSlugless(entry)) {
310
+ warnings.push(`skipped tag type "${entry?.name ?? '(unnamed)'}": no slug`);
311
+ continue;
312
+ }
285
313
  const slug = segmentOrNull(entry?.slug, 'tag type', problems);
286
314
  if (slug) {
287
315
  tagTypes.push(slug);
288
316
  }
289
317
  }
290
318
  const peopleSlug = handSlug(input, 'peopleSlug', prefixes.person, problems);
319
+ const peopleTypeSlug = handSlug(input, 'peopleTypeSlug', null, problems);
291
320
  const tagsSlug = handSlug(input, 'tagsSlug', prefixes.tag, problems);
292
321
  const articlesSlug = handSlug(input, 'articlesSlug', prefixes.article, problems);
293
322
  const personBase =
@@ -297,9 +326,13 @@ export function planFromCms(input) {
297
326
  const peopleIndex = indexFlag(input, 'enablePeopleIndex', peopleSlug, 'peopleSlug', problems);
298
327
  const tagsIndex = indexFlag(input, 'enableTagsIndex', tagsSlug, 'tagsSlug', problems);
299
328
  const categoryPath = input.tagInPath === true && !articlesSlug;
300
- /** @type {{ slug: string, indexSlug: string }[]} */
329
+ /** @type {{ slug: string, indexSlug: string, detailPages?: false, nestedSlugs?: true }[]} */
301
330
  const articleTypes = [];
302
331
  for (const entry of input.articleTypes ?? []) {
332
+ if (typeof entry?.slug === 'string' && excluded.has(entry.slug)) {
333
+ warnings.push(`excluded article type "${entry.slug}" (excludeArticleTypes)`);
334
+ continue;
335
+ }
303
336
  const slug = categoryPath
304
337
  ? pathOrNull(entry?.slug, 'article type', problems)
305
338
  : segmentOrNull(entry?.slug, 'article type', problems);
@@ -319,7 +352,21 @@ export function planFromCms(input) {
319
352
  );
320
353
  continue;
321
354
  }
322
- articleTypes.push({ slug, indexSlug });
355
+ const opt = options[slug] ?? {};
356
+ if (opt.nestedSlugs === true && opt.detailPages === false) {
357
+ problems.push(`${slug}: nestedSlugs has no effect with detailPages: false`);
358
+ continue;
359
+ }
360
+ if (categoryPath && (opt.nestedSlugs === true || opt.detailPages === false)) {
361
+ problems.push(`${slug}: detailPages and nestedSlugs are not supported with tagInPath`);
362
+ continue;
363
+ }
364
+ articleTypes.push({
365
+ slug,
366
+ indexSlug,
367
+ ...(opt.detailPages === false ? { detailPages: false } : {}),
368
+ ...(opt.nestedSlugs === true ? { nestedSlugs: true } : {}),
369
+ });
323
370
  }
324
371
  /** @type {Map<string, string>} */
325
372
  const used = new Map();
@@ -358,21 +405,30 @@ export function planFromCms(input) {
358
405
  const indexRest = articlesSlug ? `${articlesSlug}/${type.indexSlug}` : type.indexSlug;
359
406
  const articleRest = articlesSlug ? `${articlesSlug}/${type.slug}` : type.slug;
360
407
  claimRest(used, indexRest, `${type.slug} index`, problems);
361
- if (articleRest !== indexRest) {
408
+ if (articleRest !== indexRest && type.detailPages !== false) {
362
409
  claimRest(used, articleRest, `${type.slug} articles`, problems);
363
410
  }
364
- claimRest(used, `${articleRest}/[article]`, `${type.slug} article`, problems);
411
+ if (type.detailPages !== false) {
412
+ claimRest(
413
+ used,
414
+ `${articleRest}/${type.nestedSlugs ? '[...slugs]' : '[article]'}`,
415
+ `${type.slug} article`,
416
+ problems,
417
+ );
418
+ }
365
419
  }
366
420
 
367
421
  if (problems.length > 0) {
368
422
  return { ok: false, problems };
369
423
  }
370
- const hasArticles = articleTypes.length > 0 || Boolean(articlesSlug);
424
+ const hasArticles = Boolean(articlesSlug);
371
425
  const hasTags = tagTypes.length > 0 || Boolean(tagBase);
372
426
  const hasPeople = personTypes.length > 0 || Boolean(personBase);
373
427
  return {
374
428
  ok: true,
429
+ warnings,
375
430
  peopleSlug,
431
+ peopleTypeSlug,
376
432
  tagsSlug,
377
433
  articlesSlug,
378
434
  personTypes: [...new Set(personTypes)].sort(),
@@ -424,6 +480,7 @@ export function sectionConfigFromPlan(hand, plan) {
424
480
  tagInPath,
425
481
  peopleSlug: plan.peopleSlug,
426
482
  ...shapeKeys(hand, 'personSlug', 'enablePeopleIndex'),
483
+ ...(plan.peopleTypeSlug ? { peopleTypeSlug: plan.peopleTypeSlug } : {}),
427
484
  tagsSlug: plan.tagsSlug,
428
485
  ...shapeKeys(hand, 'tagSlug', 'enableTagsIndex'),
429
486
  articlesSlug: plan.articlesSlug,
@@ -434,9 +491,15 @@ export function sectionConfigFromPlan(hand, plan) {
434
491
  if (hand.tagTypeRoutes === false) {
435
492
  next.tagTypeRoutes = false;
436
493
  }
494
+ if (Array.isArray(hand.excludeArticleTypes) && hand.excludeArticleTypes.length > 0) {
495
+ next.excludeArticleTypes = hand.excludeArticleTypes;
496
+ }
437
497
  if (Array.isArray(hand.allowHandWrittenPages) && hand.allowHandWrittenPages.length > 0) {
438
498
  next.allowHandWrittenPages = hand.allowHandWrittenPages;
439
499
  }
500
+ if (hand.segmentConfig && typeof hand.segmentConfig === 'object') {
501
+ next.segmentConfig = hand.segmentConfig;
502
+ }
440
503
  return next;
441
504
  }
442
505
 
@@ -496,3 +559,27 @@ export async function fetchContentSlugs(env, contentType, fields = ['slug', 'nam
496
559
  }
497
560
  return entries;
498
561
  }
562
+
563
+ /**
564
+ * Per-type options already in the hand-written config. `--from-cms` rewrites
565
+ * `articleTypes` from the CMS, so options live here and are carried over.
566
+ *
567
+ * @param {Record<string, unknown>} hand
568
+ * @returns {Record<string, { detailPages?: boolean, nestedSlugs?: boolean }>}
569
+ */
570
+ export function articleTypeOptionsFromHand(hand) {
571
+ /** @type {Record<string, { detailPages?: boolean, nestedSlugs?: boolean }>} */
572
+ const options = {};
573
+ for (const type of Array.isArray(hand.articleTypes) ? hand.articleTypes : []) {
574
+ if (!type || typeof type !== 'object' || typeof type.slug !== 'string') {
575
+ continue;
576
+ }
577
+ const entry = {};
578
+ if (type.detailPages === false) entry.detailPages = false;
579
+ if (type.nestedSlugs === true) entry.nestedSlugs = true;
580
+ if (Object.keys(entry).length > 0) {
581
+ options[type.slug] = entry;
582
+ }
583
+ }
584
+ return options;
585
+ }
@@ -55,6 +55,22 @@ export function isSectionConfig(config) {
55
55
  /** Keys that opt a section config in to separate index and detail segments. */
56
56
  const SHAPE_KEYS = ['personSlug', 'tagSlug', 'enablePeopleIndex', 'enableTagsIndex'];
57
57
 
58
+ /**
59
+ * CMS custom type slug backing the people section. `peopleSlug` is the URL segment and
60
+ * defaults the type slug; `peopleTypeSlug` is set only when the custom type is named
61
+ * differently (URL `/people/`, custom type `person`). Never changes a URL.
62
+ *
63
+ * @param {Record<string, unknown>} config
64
+ * @returns {string} '' when there is no people section
65
+ */
66
+ export function peopleTypeSlug(config) {
67
+ const value = config.peopleTypeSlug;
68
+ if (value === undefined || value === null) {
69
+ return typeof config.peopleSlug === 'string' ? config.peopleSlug : '';
70
+ }
71
+ return requireSegment(value, 'peopleTypeSlug');
72
+ }
73
+
58
74
  /**
59
75
  * URL shape of the people and tag sections. `peopleSlug` / `tagsSlug` name the index
60
76
  * and the type prefix. `personSlug` / `tagSlug` name the singular detail segment and
@@ -102,6 +118,7 @@ export function sectionShape(config) {
102
118
  tagBase: detail('tagSlug', tags),
103
119
  peopleIndex: index('enablePeopleIndex', people, 'peopleSlug'),
104
120
  tagsIndex: index('enableTagsIndex', tags, 'tagsSlug'),
121
+ peopleType: peopleTypeSlug(config),
105
122
  declared: SHAPE_KEYS.some((key) => config[key] !== undefined),
106
123
  };
107
124
  }
@@ -118,8 +135,12 @@ export function sectionFlags(config) {
118
135
  const articles = typeof config.articlesSlug === 'string';
119
136
  const articleTypes = Array.isArray(config.articleTypes) && config.articleTypes.length > 0;
120
137
  const tagInPath = config.tagInPath === true;
138
+ // enableArticleTypeIndex gates only the articlesSlug hub (/articles/ or /resources/ as a section
139
+ // index). enableArticleTypeTagIndex is deliberately NOT tied to it: tag-in-path indexes live on
140
+ // article-type routes (/resources/events/{tag}/) and need no parent hub. Live sites (Pedestal,
141
+ // Headwater) have tagInPath, articlesSlug null and articleTypes, and must keep the flag true.
121
142
  return {
122
- enableArticleTypeIndex: articles || articleTypes,
143
+ enableArticleTypeIndex: articles && config.articlesSlug.length > 0,
123
144
  enableArticleTypeTagIndex: tagInPath && (articles || articleTypes),
124
145
  enableTag: tags || tagTypes,
125
146
  enableTagsIndex: shape.tagsIndex,
@@ -269,7 +290,8 @@ export function routeRestFromRel(rel) {
269
290
  * marketing-routes.json lists `(cms-routes)` rests (route groups dropped, for
270
291
  * example `"[tag]/[...slugs]"`) that may exist as hand-written pages. An entry
271
292
  * also allows a page outside `(cms-routes)` with the same rest (`"resource-list-cards"`
272
- * or `"src/app/resource-list-cards/page.tsx"`). Not a way to add a marketing URL.
293
+ * or `"src/app/resource-list-cards/page.tsx"`). Every entry is `{ path, reason }`; a bare
294
+ * string is deprecated (warned, not failed). Not a way to add a marketing URL.
273
295
  * To keep a custom tag listing or filter, use the `renderTagListing` route hook
274
296
  * instead of hand-writing the page.
275
297
  *
@@ -277,14 +299,55 @@ export function routeRestFromRel(rel) {
277
299
  * @returns {Set<string>}
278
300
  */
279
301
  export function handWrittenAllowlist(config) {
302
+ return new Set(parseAllowlist(config).entries.map((entry) => entry.rest));
303
+ }
304
+
305
+ /**
306
+ * Entries are `{ "path": "preview", "reason": "why this stays hand-written" }`. A bare
307
+ * string is the deprecated form: still honoured, but `warnings` names it. An object
308
+ * without a non-empty `reason` (or a `path`) is a hard error.
309
+ *
310
+ * @param {unknown} config
311
+ * @returns {{ entries: { rest: string, reason: string | null }[], warnings: string[] }}
312
+ */
313
+ export function parseAllowlist(config) {
280
314
  const raw = config && typeof config === 'object' ? config.allowHandWrittenPages : undefined;
281
315
  if (raw === undefined) {
282
- return new Set();
316
+ return { entries: [], warnings: [] };
317
+ }
318
+ if (!Array.isArray(raw)) {
319
+ throw new Error(
320
+ 'marketing-routes.json allowHandWrittenPages must be an array of { path, reason } objects',
321
+ );
283
322
  }
284
- if (!Array.isArray(raw) || raw.some((rest) => typeof rest !== 'string' || rest.length === 0)) {
285
- throw new Error('marketing-routes.json allowHandWrittenPages must be an array of non-empty strings');
323
+ /** @type {{ rest: string, reason: string | null }[]} */
324
+ const entries = [];
325
+ /** @type {string[]} */
326
+ const warnings = [];
327
+ for (const item of raw) {
328
+ if (typeof item === 'string') {
329
+ if (item.length === 0) {
330
+ throw new Error('marketing-routes.json allowHandWrittenPages has an empty entry');
331
+ }
332
+ entries.push({ rest: cleanAllowEntry(item), reason: null });
333
+ warnings.push(
334
+ `allowHandWrittenPages entry "${item}" is a bare string (deprecated): use { "path": "${item}", "reason": "..." }`,
335
+ );
336
+ continue;
337
+ }
338
+ const entryPath = item && typeof item === 'object' ? item.path : undefined;
339
+ const reason = item && typeof item === 'object' ? item.reason : undefined;
340
+ if (typeof entryPath !== 'string' || entryPath.length === 0) {
341
+ throw new Error('marketing-routes.json allowHandWrittenPages entries need a non-empty "path"');
342
+ }
343
+ if (typeof reason !== 'string' || reason.trim().length === 0) {
344
+ throw new Error(
345
+ `marketing-routes.json allowHandWrittenPages entry "${entryPath}" needs a non-empty "reason"`,
346
+ );
347
+ }
348
+ entries.push({ rest: cleanAllowEntry(entryPath), reason: reason.trim() });
286
349
  }
287
- return new Set(raw.map(cleanAllowEntry));
350
+ return { entries, warnings };
288
351
  }
289
352
 
290
353
  /**
@@ -366,6 +429,50 @@ export function isAllowlisted(allow, rest) {
366
429
  return false;
367
430
  }
368
431
 
432
+ /** Where a repo that has not migrated records why it has no marketing-routes.json. */
433
+ export const OPT_OUT_REL = 'src/lib/marketing-routes.opt-out.json';
434
+ const CONFIG_REL = 'src/lib/marketing-routes.json';
435
+
436
+ /**
437
+ * `route.ts` / `route.tsx` handlers under `src/app`. A handler under `(cms-routes)` is
438
+ * a marketing URL. One elsewhere only counts when its URL shape equals a generated
439
+ * marketing route (it would shadow a CMS page); api, sitemap, og and other fixed
440
+ * handlers never match a bracket route.
441
+ *
442
+ * @param {string} appRoot
443
+ * @returns {{ inside: string[], outside: { rel: string, rest: string }[] }}
444
+ */
445
+ export function listRouteHandlers(appRoot) {
446
+ /** @type {string[]} */
447
+ const inside = [];
448
+ /** @type {{ rel: string, rest: string }[]} */
449
+ const outside = [];
450
+ const appDir = path.join(appRoot, 'src/app');
451
+ if (!fs.existsSync(appDir)) {
452
+ return { inside, outside };
453
+ }
454
+ walk(appDir, (file) => {
455
+ const base = path.basename(file);
456
+ if (base !== 'route.ts' && base !== 'route.tsx') {
457
+ return;
458
+ }
459
+ const rel = path.relative(appRoot, file).split(path.sep).join('/');
460
+ if (rel.includes('/(cms-dev)/')) {
461
+ return;
462
+ }
463
+ const rest = routeRestFromRel(rel.replace(/\/route\.tsx?$/, '/page.ts'));
464
+ if (rest !== null) {
465
+ inside.push(rel);
466
+ return;
467
+ }
468
+ outside.push({
469
+ rel,
470
+ rest: appRestFromRel(rel.replace(/\/route\.tsx?$/, '/page.ts')),
471
+ });
472
+ });
473
+ return { inside, outside };
474
+ }
475
+
369
476
  /**
370
477
  * @param {string} appRoot
371
478
  */
@@ -377,11 +484,41 @@ export function checkMarketingRoutes(appRoot) {
377
484
  const message = error instanceof Error ? error.message : String(error);
378
485
  return { ok: false, severity: 'error', detail: `marketing-routes.json: ${message}` };
379
486
  }
487
+ const optOutAbs = path.join(appRoot, OPT_OUT_REL);
380
488
  if (!config) {
489
+ if (!fs.existsSync(optOutAbs)) {
490
+ return {
491
+ ok: false,
492
+ severity: 'error',
493
+ detail: `no ${CONFIG_REL}: run generate-marketing-routes --from-cms --write, or (repos not yet migrated only) add ${OPT_OUT_REL} with {"reason": "..."}`,
494
+ };
495
+ }
496
+ let reason = '';
497
+ try {
498
+ const parsed = JSON.parse(fs.readFileSync(optOutAbs, 'utf8'));
499
+ reason = typeof parsed?.reason === 'string' ? parsed.reason.trim() : '';
500
+ } catch (error) {
501
+ const message = error instanceof Error ? error.message : String(error);
502
+ return { ok: false, severity: 'error', detail: `${OPT_OUT_REL}: ${message}` };
503
+ }
504
+ if (!reason) {
505
+ return {
506
+ ok: false,
507
+ severity: 'error',
508
+ detail: `${OPT_OUT_REL} needs a non-empty "reason" (why this repo has no marketing-routes.json yet)`,
509
+ };
510
+ }
381
511
  return {
382
512
  ok: true,
383
513
  severity: 'warn',
384
- detail: 'no src/lib/marketing-routes.json — extra page check skipped',
514
+ detail: `marketing routes check skipped by ${OPT_OUT_REL}: ${reason}`,
515
+ };
516
+ }
517
+ if (fs.existsSync(optOutAbs)) {
518
+ return {
519
+ ok: false,
520
+ severity: 'error',
521
+ detail: `${OPT_OUT_REL} exists beside ${CONFIG_REL}: delete the opt-out, the repo is migrated`,
385
522
  };
386
523
  }
387
524
  let allowed;
@@ -392,8 +529,10 @@ export function checkMarketingRoutes(appRoot) {
392
529
  return { ok: false, severity: 'error', detail: message };
393
530
  }
394
531
  let handWritten;
532
+ let warnings;
395
533
  try {
396
534
  handWritten = handWrittenAllowlist(config);
535
+ warnings = parseAllowlist(config).warnings;
397
536
  } catch (error) {
398
537
  const message = error instanceof Error ? error.message : String(error);
399
538
  return { ok: false, severity: 'error', detail: message };
@@ -401,26 +540,44 @@ export function checkMarketingRoutes(appRoot) {
401
540
  const found = listMarketingPages(appRoot);
402
541
  const extras = found.pages.filter((rest) => !allowed.has(rest) && !isAllowlisted(handWritten, rest));
403
542
  const outside = found.outside.filter((rel) => !isAllowlisted(handWritten, appRestFromRel(rel)));
543
+ const handlers = listRouteHandlers(appRoot);
544
+ const allowedShapes = new Set([...allowed].map(restShape));
545
+ const handlerProblems = [
546
+ ...handlers.inside.filter((rel) => {
547
+ const rest = routeRestFromRel(rel.replace(/\/route\.tsx?$/, '/page.ts')) ?? '';
548
+ return !isAllowlisted(handWritten, rest);
549
+ }),
550
+ ...handlers.outside
551
+ .filter(
552
+ (item) =>
553
+ allowedShapes.has(restShape(item.rest)) && !isAllowlisted(handWritten, item.rest),
554
+ )
555
+ .map((item) => item.rel),
556
+ ];
404
557
  const drift = generatedDrift(appRoot, config);
405
558
  /** @type {string[]} */
406
559
  const problems = [
407
560
  ...outside,
408
561
  ...extras.map((rest) => `(cms-routes)/${rest ? `${rest}/` : ''}page`),
562
+ ...handlerProblems,
409
563
  ...drift,
410
564
  ...supportDrift(appRoot, config),
411
- ...policyProblems(appRoot, allowed),
565
+ ...policyProblems(appRoot, allowed, handWritten),
412
566
  ...proxyMarkdownProblems(appRoot),
413
567
  ];
568
+ const note = warnings.length > 0 ? ` [warning: ${warnings.join('; ')}]` : '';
414
569
  if (problems.length > 0) {
415
570
  return {
416
571
  ok: false,
417
572
  severity: 'error',
418
- detail: `page files outside marketing-routes.json: ${problems.join('; ')}`,
573
+ detail: `page files outside marketing-routes.json: ${problems.join('; ')}${note}`,
574
+ warnings,
419
575
  };
420
576
  }
421
577
  return {
422
578
  ok: true,
423
- detail: `${found.pages.length} cms page files match marketing-routes.json`,
579
+ detail: `${found.pages.length} cms page files match marketing-routes.json${note}`,
580
+ warnings,
424
581
  };
425
582
  }
426
583
 
@@ -434,6 +591,87 @@ export function checkMarketingRoutes(appRoot) {
434
591
  * @returns {Map<string, string>} rest → file contents
435
592
  */
436
593
  export function renderGeneratedRoutes(config) {
594
+ const files = renderRoutesBase(config);
595
+ applySegmentConfig(config, files);
596
+ return files;
597
+ }
598
+
599
+ /** Next.js route segment config keys a generated page may export, with their literal check. */
600
+ const SEGMENT_CONFIG_KEYS = {
601
+ dynamic: (v) => ['auto', 'force-dynamic', 'error', 'force-static'].includes(v),
602
+ revalidate: (v) => v === false || (Number.isInteger(v) && v >= 0),
603
+ dynamicParams: (v) => typeof v === 'boolean',
604
+ fetchCache: (v) =>
605
+ [
606
+ 'auto',
607
+ 'default-cache',
608
+ 'only-cache',
609
+ 'force-cache',
610
+ 'force-no-store',
611
+ 'default-no-store',
612
+ 'only-no-store',
613
+ ].includes(v),
614
+ runtime: (v) => v === 'nodejs' || v === 'edge',
615
+ preferredRegion: (v) =>
616
+ typeof v === 'string'
617
+ ? /^[a-z0-9-]+$/.test(v)
618
+ : Array.isArray(v) && v.length > 0 && v.every((r) => typeof r === 'string' && /^[a-z0-9-]+$/.test(r)),
619
+ };
620
+
621
+ /**
622
+ * `segmentConfig` is `{ "<generated page rest>": { "dynamic": "force-static" } }`. Each
623
+ * known key is written as `export const key = <literal>;` at the end of that generated
624
+ * page. Unknown keys, non-literal values and paths that are not a generated page throw.
625
+ *
626
+ * @param {unknown} config
627
+ * @param {Map<string, string>} files rest → file contents, updated in place
628
+ */
629
+ function applySegmentConfig(config, files) {
630
+ const raw = config && typeof config === 'object' ? config.segmentConfig : undefined;
631
+ if (raw === undefined || raw === null) {
632
+ return;
633
+ }
634
+ if (typeof raw !== 'object' || Array.isArray(raw)) {
635
+ throw new Error('marketing-routes.json segmentConfig must be an object keyed by page path');
636
+ }
637
+ const allow = handWrittenAllowlist(config);
638
+ for (const [key, entry] of Object.entries(raw)) {
639
+ const rest = key.replace(/^\/+|\/+$/g, '');
640
+ if (!files.has(rest)) {
641
+ throw new Error(`segmentConfig path "${key}" is not a generated marketing page`);
642
+ }
643
+ if (isAllowlisted(allow, rest)) {
644
+ throw new Error(
645
+ `segmentConfig path "${key}" is in allowHandWrittenPages: a hand-written page exports its own config`,
646
+ );
647
+ }
648
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
649
+ throw new Error(`segmentConfig "${key}" must be an object of segment config keys`);
650
+ }
651
+ const lines = [];
652
+ for (const [name, value] of Object.entries(entry)) {
653
+ const valid = Object.hasOwn(SEGMENT_CONFIG_KEYS, name) ? SEGMENT_CONFIG_KEYS[name] : null;
654
+ if (!valid) {
655
+ throw new Error(
656
+ `segmentConfig "${key}": "${name}" is not an allowed key (${Object.keys(SEGMENT_CONFIG_KEYS).join(', ')})`,
657
+ );
658
+ }
659
+ if (!valid(value)) {
660
+ throw new Error(`segmentConfig "${key}": illegal value for ${name}: ${JSON.stringify(value)}`);
661
+ }
662
+ lines.push(`export const ${name} = ${JSON.stringify(value).replace(/"/g, "'")};`);
663
+ }
664
+ if (lines.length > 0) {
665
+ files.set(rest, `${files.get(rest)}\n${lines.join('\n')}\n`);
666
+ }
667
+ }
668
+ }
669
+
670
+ /**
671
+ * @param {unknown} config
672
+ * @returns {Map<string, string>}
673
+ */
674
+ function renderRoutesBase(config) {
437
675
  if (!config || typeof config !== 'object') {
438
676
  throw new Error('marketing-routes.json must be an object');
439
677
  }
@@ -535,7 +773,7 @@ function slugList(values) {
535
773
 
536
774
  /**
537
775
  * @param {Record<string, unknown>} config
538
- * @returns {{ slug: string, indexPath: string, articlePath: string }[]}
776
+ * @returns {{ slug: string, indexPath: string, articlePath: string, detailPages?: false }[]}
539
777
  */
540
778
  function articleRouteRecords(config) {
541
779
  const articles = typeof config.articlesSlug === 'string' ? config.articlesSlug : '';
@@ -551,7 +789,12 @@ function articleRouteRecords(config) {
551
789
  }
552
790
  const indexPath = `/${underPrefix(articles, route.indexSlug)}/`;
553
791
  const articlePath = `/${underPrefix(articles, route.slug)}/`;
554
- return { slug: route.slug, indexPath, articlePath };
792
+ return {
793
+ slug: route.slug,
794
+ indexPath,
795
+ articlePath,
796
+ ...(route.detailPages ? {} : { detailPages: false }),
797
+ };
555
798
  });
556
799
  }
557
800
 
@@ -573,11 +816,25 @@ export function renderMarketingSlugs(config) {
573
816
  : `[\n${routes
574
817
  .map(
575
818
  (route) =>
576
- ` { slug: '${route.slug}', indexPath: '${route.indexPath}', articlePath: '${route.articlePath}' },`,
819
+ ` { slug: '${route.slug}', indexPath: '${route.indexPath}', articlePath: '${route.articlePath}'${route.detailPages === false ? ', detailPages: false' : ''} },`,
577
820
  )
578
821
  .join('\n')}\n] as const`;
579
822
  const base = (slug) => (slug ? `'/${slug}'` : "''");
823
+ const indexOnly = routes.some((route) => route.detailPages === false);
824
+ const detailSlugLine = indexOnly
825
+ ? `/** Article types that have /{type}/{article}/ pages. Sitemap sources use this, not ARTICLE_TYPE_SLUGS. */
826
+ export const ARTICLE_DETAIL_TYPE_SLUGS = ${slugList(
827
+ routes.filter((route) => route.detailPages !== false).map((route) => route.slug),
828
+ )};
829
+ `
830
+ : '';
580
831
  const shape = sectionShape(config);
832
+ const typeLine =
833
+ config.peopleTypeSlug === undefined || config.peopleTypeSlug === null
834
+ ? ''
835
+ : `/** CMS custom type slug for people lookups. PEOPLE_SLUG stays the URL segment. */
836
+ export const PEOPLE_TYPE_SLUG = '${shape.peopleType}';
837
+ `;
581
838
  const detailLines = shape.declared
582
839
  ? `export const PERSON_DETAIL_SLUG = '${shape.personBase}';
583
840
  export const PERSON_DETAIL_BASE = ${base(shape.personBase)};
@@ -588,14 +845,14 @@ export const TAG_DETAIL_BASE = ${base(shape.tagBase)};
588
845
  return `${header()}
589
846
  export const PEOPLE_SLUG = '${people}';
590
847
  export const PEOPLE_BASE = ${base(people)};
591
- export const TAGS_SLUG = '${tags}';
848
+ ${typeLine}export const TAGS_SLUG = '${tags}';
592
849
  export const TAGS_BASE = ${base(tags)};
593
850
  export const ARTICLES_SLUG = '${articles}';
594
851
  export const ARTICLES_BASE = ${base(articles)};
595
852
  ${detailLines}export const PERSON_TYPE_SLUGS = ${slugList(personTypes)};
596
853
  export const TAG_TYPE_SLUGS = ${slugList(tagTypes)};
597
854
  export const ARTICLE_TYPE_SLUGS = ${slugList(articleSlugs)};
598
- export const ARTICLE_TYPE_ROUTES = ${routeLiteral};
855
+ ${detailSlugLine}export const ARTICLE_TYPE_ROUTES = ${routeLiteral};
599
856
  `;
600
857
  }
601
858
 
@@ -730,8 +987,10 @@ function generatedDrift(appRoot, config) {
730
987
  let files;
731
988
  try {
732
989
  files = renderGeneratedRoutes(config);
733
- } catch {
734
- return drift;
990
+ } catch (error) {
991
+ // An illegal segmentConfig (or other render error) must fail the checker, as it fails generate.
992
+ const message = error instanceof Error ? error.message : String(error);
993
+ return [`generated routes cannot be rendered: ${message}`];
735
994
  }
736
995
  const requireComplete = fs.existsSync(path.join(appRoot, FLAGS_REL));
737
996
  for (const [rest, expected] of files) {
@@ -927,7 +1186,10 @@ export function mustBeSsgOrStaticRoutes(config) {
927
1186
  } else if (Array.isArray(config.articleTypes)) {
928
1187
  for (const type of config.articleTypes) {
929
1188
  const route = articleTypeRoute(type, config);
930
- push(`${underPrefix(articles, route.slug)}/[article]`);
1189
+ const detail = articleDetailRest(underPrefix(articles, route.slug), route);
1190
+ if (detail) {
1191
+ push(detail);
1192
+ }
931
1193
  }
932
1194
  }
933
1195
  const shape = isSectionConfig(config) ? sectionShape(config) : null;
@@ -975,6 +1237,11 @@ export function mustBeSsgOrStaticRoutes(config) {
975
1237
  return routes;
976
1238
  }
977
1239
 
1240
+ /** `/llms.txt`, `/site-info.md`: a dotted last segment that is not a `[...catchAll]`. */
1241
+ function isTextRoute(route) {
1242
+ return /\/[^/[\]]+\.[A-Za-z0-9]+$/.test(route);
1243
+ }
1244
+
978
1245
  /**
979
1246
  * @param {string} appRoot
980
1247
  * @param {unknown} config
@@ -985,7 +1252,23 @@ function syncRouteBuildPolicy(appRoot, config) {
985
1252
  return;
986
1253
  }
987
1254
  const policy = JSON.parse(fs.readFileSync(policyPath, 'utf8'));
988
- policy.mustBeSsgOrStatic = mustBeSsgOrStaticRoutes(config);
1255
+ const generated = mustBeSsgOrStaticRoutes(config);
1256
+ // Keep hand-added entries for allowHandWrittenPages (same URL-shape match the checker uses).
1257
+ // Unknown, non-allowlisted, non-generated routes are dropped, never invented.
1258
+ const handWritten = handWrittenAllowlist(config);
1259
+ const kept = (Array.isArray(policy.mustBeSsgOrStatic) ? policy.mustBeSsgOrStatic : []).filter(
1260
+ (route) =>
1261
+ typeof route === 'string' &&
1262
+ route.startsWith('/') &&
1263
+ !isTextRoute(route) &&
1264
+ !generated.includes(route) &&
1265
+ isAllowlisted(handWritten, route.slice(1)),
1266
+ );
1267
+ policy.mustBeSsgOrStatic = [
1268
+ ...generated.filter((route) => !isTextRoute(route)),
1269
+ ...kept,
1270
+ ...generated.filter(isTextRoute),
1271
+ ];
989
1272
  fs.writeFileSync(policyPath, `${JSON.stringify(policy, null, 2)}\n`);
990
1273
  console.log(`Updated ${path.relative(appRoot, policyPath)}`);
991
1274
  }
@@ -1063,13 +1346,16 @@ function formatGeneratedPages(appRoot) {
1063
1346
  }
1064
1347
 
1065
1348
  /**
1066
- * Bracket CMS routes in route-build-policy.json must be the generated tree.
1349
+ * Bracket CMS routes in route-build-policy.json must be the generated tree. A route the
1350
+ * site hand-wrote and listed in `allowHandWrittenPages` may also be listed, so it keeps
1351
+ * the SSG guard.
1067
1352
  *
1068
1353
  * @param {string} appRoot
1069
1354
  * @param {Set<string>} allowed
1355
+ * @param {Set<string>} [handWritten] from handWrittenAllowlist
1070
1356
  * @returns {string[]}
1071
1357
  */
1072
- function policyProblems(appRoot, allowed) {
1358
+ function policyProblems(appRoot, allowed, handWritten = new Set()) {
1073
1359
  const policyPath = path.join(appRoot, 'route-build-policy.json');
1074
1360
  if (!fs.existsSync(policyPath)) {
1075
1361
  return [];
@@ -1098,7 +1384,7 @@ function policyProblems(appRoot, allowed) {
1098
1384
  continue;
1099
1385
  }
1100
1386
  const rest = route.slice(1);
1101
- if (!allowed.has(rest)) {
1387
+ if (!allowed.has(rest) && !isAllowlisted(handWritten, rest)) {
1102
1388
  problems.push(`route-build-policy.json lists ${route} outside marketing-routes.json`);
1103
1389
  }
1104
1390
  }
@@ -1147,9 +1433,15 @@ function categoryPath(config) {
1147
1433
  }
1148
1434
 
1149
1435
  /**
1436
+ * Per-type options (object form of `articleTypes`):
1437
+ * - `detailPages: false` — index only. The index is served at `indexSlug`; no
1438
+ * `/{slug}/{article}/` or `/{indexSlug}/{article}/` page is generated.
1439
+ * - `nestedSlugs: true` — detail pages are `/{slug}/[...slugs]` (an article slug
1440
+ * such as `acme/launch`) instead of the single segment `/{slug}/[article]`.
1441
+ *
1150
1442
  * @param {unknown} type
1151
1443
  * @param {Record<string, unknown>} [config]
1152
- * @returns {{ slug: string, indexSlug: string }}
1444
+ * @returns {{ slug: string, indexSlug: string, detailPages: boolean, nestedSlugs: boolean }}
1153
1445
  */
1154
1446
  function articleTypeRoute(type, config = {}) {
1155
1447
  const category = categoryPath(config);
@@ -1157,7 +1449,7 @@ function articleTypeRoute(type, config = {}) {
1157
1449
  const slug = category
1158
1450
  ? requireRoutePath(type, 'articleTypes')
1159
1451
  : requireSegment(type, 'articleTypes');
1160
- return { slug, indexSlug: slug };
1452
+ return { slug, indexSlug: slug, detailPages: true, nestedSlugs: false };
1161
1453
  }
1162
1454
  const slug = category
1163
1455
  ? requireRoutePath(type?.slug, 'articleTypes.slug')
@@ -1169,12 +1461,49 @@ function articleTypeRoute(type, config = {}) {
1169
1461
  `${slug} indexSlug must equal the article type slug when the category is in the path`,
1170
1462
  );
1171
1463
  }
1464
+ /**
1465
+ * @param {string} key
1466
+ */
1467
+ const optional = (key) => {
1468
+ const value = type?.[key];
1469
+ if (value !== undefined && typeof value !== 'boolean') {
1470
+ throw new Error(`articleTypes.${key} for "${slug}" must be a boolean`);
1471
+ }
1472
+ return value;
1473
+ };
1474
+ const detailPages = optional('detailPages') !== false;
1475
+ const nestedSlugs = optional('nestedSlugs') === true;
1476
+ if ((category || config.tagInPath === true) && (!detailPages || nestedSlugs)) {
1477
+ throw new Error(
1478
+ `articleTypes "${slug}": detailPages and nestedSlugs are not supported with tagInPath`,
1479
+ );
1480
+ }
1481
+ if (!detailPages && nestedSlugs) {
1482
+ throw new Error(`articleTypes "${slug}": nestedSlugs has no effect with detailPages: false`);
1483
+ }
1172
1484
  return {
1173
1485
  slug,
1174
1486
  indexSlug: category ? slug : requireSegment(rawIndex, 'articleTypes.indexSlug'),
1487
+ detailPages,
1488
+ nestedSlugs,
1175
1489
  };
1176
1490
  }
1177
1491
 
1492
+ /**
1493
+ * The detail route of a plain article type, with the real param name
1494
+ * (`[article]` or `[...slugs]`), or null for an index-only type.
1495
+ *
1496
+ * @param {string} articleRest `{articles}/{slug}`
1497
+ * @param {{ detailPages: boolean, nestedSlugs: boolean }} route
1498
+ * @returns {string | null}
1499
+ */
1500
+ export function articleDetailRest(articleRest, route) {
1501
+ if (!route.detailPages) {
1502
+ return null;
1503
+ }
1504
+ return `${articleRest}/${route.nestedSlugs ? '[...slugs]' : '[article]'}`;
1505
+ }
1506
+
1178
1507
  /**
1179
1508
  * @param {string} prefix
1180
1509
  * @param {string} segment
@@ -1240,7 +1569,10 @@ function addSectionRests(allowed, config) {
1240
1569
  const indexRest = underPrefix(articles, route.indexSlug);
1241
1570
  const articleRest = underPrefix(articles, route.slug);
1242
1571
  allowed.add(indexRest);
1243
- allowed.add(`${articleRest}/[article]`);
1572
+ const detail = articleDetailRest(articleRest, route);
1573
+ if (detail) {
1574
+ allowed.add(detail);
1575
+ }
1244
1576
  }
1245
1577
  }
1246
1578
 
@@ -1309,7 +1641,15 @@ function renderSectionRoutes(config, files) {
1309
1641
  const indexRest = underPrefix(articles, route.indexSlug);
1310
1642
  const articleRest = underPrefix(articles, route.slug);
1311
1643
  files.set(indexRest, concreteArticleTypeIndex(indexRest, route.slug));
1312
- files.set(`${articleRest}/[article]`, concreteArticlePage(articleRest, route.slug));
1644
+ const detail = articleDetailRest(articleRest, route);
1645
+ if (detail) {
1646
+ files.set(
1647
+ detail,
1648
+ route.nestedSlugs
1649
+ ? concreteNestedArticlePage(articleRest, route.slug)
1650
+ : concreteArticlePage(articleRest, route.slug),
1651
+ );
1652
+ }
1313
1653
  }
1314
1654
  }
1315
1655
 
@@ -1560,6 +1900,61 @@ ${page}
1560
1900
  `;
1561
1901
  }
1562
1902
 
1903
+ /**
1904
+ * Nested article slugs: `/{rest}/{client}/{case}/` as `[...slugs]`.
1905
+ *
1906
+ * @param {string} rest directory of the article, without `[...slugs]`
1907
+ * @param {string} typeSlug
1908
+ */
1909
+ function concreteNestedArticlePage(rest, typeSlug) {
1910
+ const props = `PageProps<'/${rest}/[...slugs]'>`;
1911
+ const extract = openFn('async function extractDetails', [`props: ${props}`]);
1912
+ const metadata = openFn('export async function generateMetadata', [
1913
+ `props: ${props}`,
1914
+ 'parent: ResolvingMetadata',
1915
+ ]);
1916
+ const page = openFn('export default async function ', [`props: ${props}`]);
1917
+ return `${header()}import { joinCmsPathSegments } from '@se-studio/core-ui';
1918
+ import { notFoundIfImpossibleCmsSlug } from '@se-studio/core-ui/server';
1919
+ import type { ResolvingMetadata } from 'next';
1920
+ import { notFound } from 'next/navigation';
1921
+ import { generateArticleMetadata, generateArticlePage } from '@/lib/route-handlers';
1922
+ import { ARTICLE_DETAIL_ROUTE_CONFIG } from '@/lib/routeConfig';
1923
+
1924
+ const ARTICLE_TYPE = '${typeSlug}';
1925
+
1926
+ export function generateStaticParams() {
1927
+ return [];
1928
+ }
1929
+
1930
+ ${extract}
1931
+ const params = await props.params;
1932
+ const articleSlug = joinCmsPathSegments(params.slugs);
1933
+ if (!articleSlug) {
1934
+ notFound();
1935
+ }
1936
+ notFoundIfImpossibleCmsSlug(articleSlug);
1937
+ return { articleSlug, path: \`/${rest}/\${articleSlug}/\` };
1938
+ }
1939
+
1940
+ ${metadata}
1941
+ const { articleSlug, path } = await extractDetails(props);
1942
+ return await generateArticleMetadata(
1943
+ ARTICLE_TYPE,
1944
+ articleSlug,
1945
+ path,
1946
+ ARTICLE_DETAIL_ROUTE_CONFIG,
1947
+ parent,
1948
+ );
1949
+ }
1950
+
1951
+ ${page}
1952
+ const { articleSlug, path } = await extractDetails(props);
1953
+ return await generateArticlePage(ARTICLE_TYPE, articleSlug, path, ARTICLE_DETAIL_ROUTE_CONFIG);
1954
+ }
1955
+ `;
1956
+ }
1957
+
1563
1958
  /**
1564
1959
  * @param {string} segment
1565
1960
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@se-studio/project-build",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "Build tools and management scripts for SE Studio projects",
5
5
  "repository": {
6
6
  "type": "git",