@se-studio/project-build 1.5.0 → 1.6.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,18 @@
1
1
  # @se-studio/project-build
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - dce254a: `generate-marketing-routes` and `check-marketing-routes` express index versus detail URL shapes, so a site such as Highlander (`/people/` index with `/person/{slug}/` detail, `/tag/{slug}/` with no `/tags/`) no longer needs a hand-written route or a canonical that disagrees with the served URL.
8
+
9
+ - New optional keys in a section `marketing-routes.json`: `personSlug` and `tagSlug` (singular detail segment, default the index slug), `enablePeopleIndex` and `enableTagsIndex` (default: on when the index slug is set; `true` needs the index slug). An index that is off writes no page and the flag is `false`; the detail pages stay. A config with none of these keys generates the same files as before. A config that declares any of them also writes `PERSON_DETAIL_BASE`, `PERSON_DETAIL_SLUG`, `TAG_DETAIL_BASE` and `TAG_DETAIL_SLUG` into `src/generated/marketing-slugs.ts`; build person and tag links from them. Existing section configs that already carry `enablePeopleIndex` / `enableTagsIndex` (previously ignored) are now honoured.
10
+ - The generated person and tag detail pages pass their served path to the handlers (the tag page no longer reads the site's tag url calculator when the shape is declared), so the canonical is always the served URL.
11
+ - `allowHandWrittenPages` also allows a known non-CMS page: `resource-list-cards` or `src/app/resource-list-cards/page.tsx`. `preview` allows `(cms-routes)/preview`. Matching is exact; a child page is not covered.
12
+ - `--from-cms --write` keeps the four shape keys the way it keeps `allowHandWrittenPages`, and validates them. `tagTypeRoutes: false` skips tag types that have no slug.
13
+ - `@se-studio/core-ui`: new optional `renderTagListing` on `createRouteHandlers`. `generateTagPage` renders its result after the tag content, so a generated tag page keeps a site's custom listing or filter (category tabs plus article list) with no hand-written route and no generator fork. A tag with no `contents` still renders when the hook is set. Additive; sites that do not pass it are unchanged.
14
+ - Docs and skills (`@se-studio/skills`) describe the keys, the hook and the allowlist.
15
+
3
16
  ## 1.5.0
4
17
 
5
18
  ### Minor Changes
package/README.md CHANGED
@@ -131,7 +131,51 @@ check-marketing-routes . # fail hand-written (cms-route
131
131
 
132
132
  `check-marketing-routes` exits 1 for a page not in `src/lib/marketing-routes.json` or its optional `allowHandWrittenPages` array (rests under `(cms-routes)`, route groups dropped). Tabs, filters and listings come from CMS tags and types, not code.
133
133
 
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`. To adopt it on a site with custom listings, allowlist those pages (for example `resources`, `resources/[slug]`, `tag/[slug]`) and run `pnpm generate:routes`.
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
+
136
+ ##### URL shape: index and detail slugs, index switches, custom tag listing
137
+
138
+ 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.
139
+
140
+ | Key | Meaning | Default |
141
+ |-----|---------|---------|
142
+ | `peopleSlug` / `tagsSlug` | Index segment, and the prefix for person types and tag types | none |
143
+ | `personSlug` / `tagSlug` | Singular detail segment: `/{personSlug}/{person}/`, `/{tagSlug}/{tag}/` | the index slug |
144
+ | `enablePeopleIndex` / `enableTagsIndex` | Whether `/{peopleSlug}/` and `/{tagsSlug}/` exist. `true` needs the index slug | `true` when the index slug is set |
145
+
146
+ An index that is off writes no page (so it 404s) and the matching `enable…Index` flag is `false`; the detail pages stay. With no index slug at all, set only `personSlug` / `tagSlug`. A person type or tag type still sits under the index slug (`/people/{type}/`).
147
+
148
+ ```json
149
+ {
150
+ "peopleSlug": "people",
151
+ "personSlug": "person",
152
+ "enablePeopleIndex": true,
153
+ "tagsSlug": "tags",
154
+ "tagSlug": "tag",
155
+ "enableTagsIndex": false
156
+ }
157
+ ```
158
+
159
+ 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
+
161
+ **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
+
163
+ ```tsx
164
+ createRouteHandlers({
165
+ // ...
166
+ renderTagListing: async ({ tag, tagSlug, path, locale }) => (
167
+ <>
168
+ <ResourceCategoryFilter activeSlug={tagSlug} />
169
+ <ResourceList tagSlug={tagSlug} />
170
+ </>
171
+ ),
172
+ });
173
+ ```
174
+
175
+ The input is the same object `prepareTagPage` gets. Return `null` for a tag that needs no listing. When the hook is set, a tag with no CMS `contents` still renders. The hook does its own data fetching; errors it collects are not added to the layout's error list.
176
+
177
+ **Allowlist for non-CMS pages.** An `allowHandWrittenPages` entry also covers a page outside `(cms-routes)` with that URL: `"resource-list-cards"` or `"src/app/resource-list-cards/page.tsx"` allows `src/app/resource-list-cards/page.tsx`, and `"preview"` allows `src/app/(cms-routes)/preview/page.tsx`. Matching is exact: an entry never covers a child page.
178
+
135
179
 
136
180
  #### `setailwind`
137
181
  Tailwind CSS v4 build system with file watching.
@@ -18,6 +18,10 @@
18
18
  * Files are written into the `(cms-routes)` tree that already serves the
19
19
  * app (`(default)`, a locale copy, or an inner group such as `(with-chrome)`).
20
20
  *
21
+ * A section config may set `personSlug` / `tagSlug` (singular detail segment, default the
22
+ * index slug) and `enablePeopleIndex` / `enableTagsIndex` (default: on when the index slug
23
+ * is set). `--from-cms --write` keeps them, as it keeps `allowHandWrittenPages`.
24
+ *
21
25
  * `--from-cms` reads custom types, person types, article types, and tag types,
22
26
  * then rewrites the section fields of marketing-routes.json. A custom type is
23
27
  * an optional person, tag, or article prefix. DRAFT_ONLY=true uses the preview
@@ -80,6 +84,10 @@ if (fromCms) {
80
84
  peopleSlug: hand.peopleSlug,
81
85
  tagsSlug: hand.tagsSlug,
82
86
  articlesSlug: hand.articlesSlug,
87
+ personSlug: hand.personSlug,
88
+ tagSlug: hand.tagSlug,
89
+ enablePeopleIndex: hand.enablePeopleIndex,
90
+ enableTagsIndex: hand.enableTagsIndex,
83
91
  tagInPath: hand.tagInPath === true,
84
92
  tagTypeRoutes: hand.tagTypeRoutes !== false,
85
93
  });
@@ -181,6 +181,30 @@ function handSlug(input, key, inferred, problems = null) {
181
181
  return segmentOrNull(value, key, problems);
182
182
  }
183
183
 
184
+ /**
185
+ * An explicit index switch, or "the index slug is set". True needs the slug.
186
+ *
187
+ * @param {Record<string, unknown>} input
188
+ * @param {string} key
189
+ * @param {string | null} slug
190
+ * @param {string} slugKey
191
+ * @param {string[]} problems
192
+ * @returns {boolean}
193
+ */
194
+ function indexFlag(input, key, slug, slugKey, problems) {
195
+ const value = input[key];
196
+ if (value === undefined) return Boolean(slug);
197
+ if (typeof value !== 'boolean') {
198
+ problems.push(`${key} must be a boolean`);
199
+ return false;
200
+ }
201
+ if (value && !slug) {
202
+ problems.push(`${key} is true but ${slugKey} is not set`);
203
+ return false;
204
+ }
205
+ return value;
206
+ }
207
+
184
208
  /**
185
209
  * @param {Map<string, string>} used
186
210
  * @param {string} rest
@@ -188,12 +212,13 @@ function handSlug(input, key, inferred, problems = null) {
188
212
  * @param {string[]} problems
189
213
  */
190
214
  function claimRest(used, rest, label, problems) {
191
- const previous = used.get(rest);
215
+ const key = rest.replace(/\[(?!\.)[^\]]+\]/g, '[]');
216
+ const previous = used.get(key);
192
217
  if (previous) {
193
218
  problems.push(`route ${rest} is used by ${previous} and ${label}`);
194
219
  return;
195
220
  }
196
- used.set(rest, label);
221
+ used.set(key, label);
197
222
  }
198
223
 
199
224
  /**
@@ -205,6 +230,10 @@ function claimRest(used, rest, label, problems) {
205
230
  * peopleSlug?: string | null,
206
231
  * tagsSlug?: string | null,
207
232
  * articlesSlug?: string | null,
233
+ * personSlug?: string | null,
234
+ * tagSlug?: string | null,
235
+ * enablePeopleIndex?: boolean,
236
+ * enableTagsIndex?: boolean,
208
237
  * tagInPath?: boolean,
209
238
  * tagTypeRoutes?: boolean,
210
239
  * }} input
@@ -261,6 +290,12 @@ export function planFromCms(input) {
261
290
  const peopleSlug = handSlug(input, 'peopleSlug', prefixes.person, problems);
262
291
  const tagsSlug = handSlug(input, 'tagsSlug', prefixes.tag, problems);
263
292
  const articlesSlug = handSlug(input, 'articlesSlug', prefixes.article, problems);
293
+ const personBase =
294
+ input.personSlug == null ? peopleSlug : handSlug(input, 'personSlug', peopleSlug, problems);
295
+ const tagBase =
296
+ input.tagSlug == null ? tagsSlug : handSlug(input, 'tagSlug', tagsSlug, problems);
297
+ const peopleIndex = indexFlag(input, 'enablePeopleIndex', peopleSlug, 'peopleSlug', problems);
298
+ const tagsIndex = indexFlag(input, 'enableTagsIndex', tagsSlug, 'tagsSlug', problems);
264
299
  const categoryPath = input.tagInPath === true && !articlesSlug;
265
300
  /** @type {{ slug: string, indexSlug: string }[]} */
266
301
  const articleTypes = [];
@@ -288,18 +323,23 @@ export function planFromCms(input) {
288
323
  }
289
324
  /** @type {Map<string, string>} */
290
325
  const used = new Map();
291
- if (peopleSlug) {
326
+ if (peopleIndex) {
292
327
  claimRest(used, peopleSlug, 'person prefix', problems);
293
- claimRest(used, `${peopleSlug}/[person]`, 'untyped person', problems);
328
+ }
329
+ if (personBase) {
330
+ claimRest(used, `${personBase}/[person]`, 'untyped person', problems);
294
331
  }
295
332
  for (const type of personTypes) {
296
333
  const rest = peopleSlug ? `${peopleSlug}/${type}` : type;
297
334
  claimRest(used, rest, `person type ${type}`, problems);
298
335
  claimRest(used, `${rest}/[person]`, `person type ${type} person`, problems);
299
336
  }
300
- if (tagsSlug) {
337
+ if (tagsIndex) {
301
338
  claimRest(used, tagsSlug, 'tag prefix', problems);
302
339
  }
340
+ if (tagBase) {
341
+ claimRest(used, `${tagBase}/[tag]`, 'tag', problems);
342
+ }
303
343
  for (const type of tagTypes) {
304
344
  const rest = tagsSlug ? `${tagsSlug}/${type}` : type;
305
345
  claimRest(used, rest, `tag type ${type}`, problems);
@@ -328,8 +368,8 @@ export function planFromCms(input) {
328
368
  return { ok: false, problems };
329
369
  }
330
370
  const hasArticles = articleTypes.length > 0 || Boolean(articlesSlug);
331
- const hasTags = tagTypes.length > 0 || Boolean(tagsSlug);
332
- const hasPeople = personTypes.length > 0 || Boolean(peopleSlug);
371
+ const hasTags = tagTypes.length > 0 || Boolean(tagBase);
372
+ const hasPeople = personTypes.length > 0 || Boolean(personBase);
333
373
  return {
334
374
  ok: true,
335
375
  peopleSlug,
@@ -342,14 +382,31 @@ export function planFromCms(input) {
342
382
  enableArticleTypeIndex: hasArticles,
343
383
  enableArticleTypeTagIndex: false,
344
384
  enableTag: hasTags,
345
- enableTagsIndex: Boolean(tagsSlug),
385
+ enableTagsIndex: tagsIndex,
346
386
  enablePerson: hasPeople,
347
- enablePeopleIndex: Boolean(peopleSlug),
387
+ enablePeopleIndex: peopleIndex,
348
388
  enablePrimaryTagPartOfSlug: false,
349
389
  },
350
390
  };
351
391
  }
352
392
 
393
+ /**
394
+ * URL shape keys are hand-written, never inferred from the CMS, so they pass through.
395
+ *
396
+ * @param {Record<string, unknown>} hand
397
+ * @param {string[]} keys
398
+ */
399
+ function shapeKeys(hand, ...keys) {
400
+ /** @type {Record<string, unknown>} */
401
+ const kept = {};
402
+ for (const key of keys) {
403
+ if (hand[key] !== undefined && hand[key] !== null) {
404
+ kept[key] = hand[key];
405
+ }
406
+ }
407
+ return kept;
408
+ }
409
+
353
410
  /**
354
411
  * Keep hand-written app switches. Section paths and flags come from the plan.
355
412
  *
@@ -366,7 +423,9 @@ export function sectionConfigFromPlan(hand, plan) {
366
423
  pageTest: hand.pageTest === true,
367
424
  tagInPath,
368
425
  peopleSlug: plan.peopleSlug,
426
+ ...shapeKeys(hand, 'personSlug', 'enablePeopleIndex'),
369
427
  tagsSlug: plan.tagsSlug,
428
+ ...shapeKeys(hand, 'tagSlug', 'enableTagsIndex'),
370
429
  articlesSlug: plan.articlesSlug,
371
430
  personTypes: plan.personTypes,
372
431
  tagTypes: plan.tagTypes,
@@ -52,13 +52,68 @@ export function isSectionConfig(config) {
52
52
  );
53
53
  }
54
54
 
55
+ /** Keys that opt a section config in to separate index and detail segments. */
56
+ const SHAPE_KEYS = ['personSlug', 'tagSlug', 'enablePeopleIndex', 'enableTagsIndex'];
57
+
58
+ /**
59
+ * URL shape of the people and tag sections. `peopleSlug` / `tagsSlug` name the index
60
+ * and the type prefix. `personSlug` / `tagSlug` name the singular detail segment and
61
+ * default to the index slug. `enablePeopleIndex` / `enableTagsIndex` default to
62
+ * "the index slug is set" and may switch an index off while its detail pages stay.
63
+ *
64
+ * @param {Record<string, unknown>} config
65
+ */
66
+ export function sectionShape(config) {
67
+ const people = typeof config.peopleSlug === 'string' ? config.peopleSlug : '';
68
+ const tags = typeof config.tagsSlug === 'string' ? config.tagsSlug : '';
69
+ /**
70
+ * @param {string} key
71
+ * @param {string} fallback
72
+ */
73
+ const detail = (key, fallback) => {
74
+ const value = config[key];
75
+ if (value === undefined || value === null) {
76
+ return fallback;
77
+ }
78
+ return requireSegment(value, key);
79
+ };
80
+ /**
81
+ * @param {string} key
82
+ * @param {string} indexSlug
83
+ * @param {string} indexKey
84
+ */
85
+ const index = (key, indexSlug, indexKey) => {
86
+ const value = config[key];
87
+ if (value === undefined) {
88
+ return indexSlug.length > 0;
89
+ }
90
+ if (typeof value !== 'boolean') {
91
+ throw new Error(`${key} must be a boolean`);
92
+ }
93
+ if (value && indexSlug.length === 0) {
94
+ throw new Error(`${key} is true but ${indexKey} is not set`);
95
+ }
96
+ return value;
97
+ };
98
+ return {
99
+ people,
100
+ tags,
101
+ personBase: detail('personSlug', people),
102
+ tagBase: detail('tagSlug', tags),
103
+ peopleIndex: index('enablePeopleIndex', people, 'peopleSlug'),
104
+ tagsIndex: index('enableTagsIndex', tags, 'tagsSlug'),
105
+ declared: SHAPE_KEYS.some((key) => config[key] !== undefined),
106
+ };
107
+ }
108
+
55
109
  /**
56
110
  * @param {Record<string, unknown>} config
57
111
  */
58
112
  export function sectionFlags(config) {
59
- const people = typeof config.peopleSlug === 'string' && config.peopleSlug.length > 0;
113
+ const shape = sectionShape(config);
114
+ const people = shape.personBase.length > 0;
60
115
  const personTypes = Array.isArray(config.personTypes) && config.personTypes.length > 0;
61
- const tags = typeof config.tagsSlug === 'string' && config.tagsSlug.length > 0;
116
+ const tags = shape.tagBase.length > 0;
62
117
  const tagTypes = Array.isArray(config.tagTypes) && config.tagTypes.length > 0;
63
118
  const articles = typeof config.articlesSlug === 'string';
64
119
  const articleTypes = Array.isArray(config.articleTypes) && config.articleTypes.length > 0;
@@ -67,9 +122,9 @@ export function sectionFlags(config) {
67
122
  enableArticleTypeIndex: articles || articleTypes,
68
123
  enableArticleTypeTagIndex: tagInPath && (articles || articleTypes),
69
124
  enableTag: tags || tagTypes,
70
- enableTagsIndex: tags,
125
+ enableTagsIndex: shape.tagsIndex,
71
126
  enablePerson: people || personTypes,
72
- enablePeopleIndex: people,
127
+ enablePeopleIndex: shape.peopleIndex,
73
128
  enablePrimaryTagPartOfSlug: tagInPath,
74
129
  };
75
130
  }
@@ -212,8 +267,11 @@ export function routeRestFromRel(rel) {
212
267
  /**
213
268
  * Explicit, reviewable exceptions: `allowHandWrittenPages` in
214
269
  * marketing-routes.json lists `(cms-routes)` rests (route groups dropped, for
215
- * example `"[tag]/[...slugs]"`) that may exist as hand-written pages. Not a way
216
- * to add a marketing URL; tabs, filters and listings come from CMS tags and types.
270
+ * example `"[tag]/[...slugs]"`) that may exist as hand-written pages. An entry
271
+ * 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.
273
+ * To keep a custom tag listing or filter, use the `renderTagListing` route hook
274
+ * instead of hand-writing the page.
217
275
  *
218
276
  * @param {unknown} config
219
277
  * @returns {Set<string>}
@@ -237,7 +295,13 @@ export function handWrittenAllowlist(config) {
237
295
  */
238
296
  function cleanAllowEntry(entry) {
239
297
  const fromPath = routeRestFromRel(entry.replace(/^\/+/, ''));
240
- const rest = fromPath ?? entry.replace(/\/page\.tsx?$/, '').replace(/^page\.tsx?$/, '');
298
+ const rest =
299
+ fromPath ??
300
+ entry
301
+ .replace(/^\/+/, '')
302
+ .replace(/^src\/app\//, '')
303
+ .replace(/\/page\.tsx?$/, '')
304
+ .replace(/^page\.tsx?$/, '');
241
305
  return rest
242
306
  .replace(/^\/+|\/+$/g, '')
243
307
  .split('/')
@@ -245,6 +309,22 @@ function cleanAllowEntry(entry) {
245
309
  .join('/');
246
310
  }
247
311
 
312
+ /**
313
+ * URL rest of a page outside `(cms-routes)`, route groups dropped. `src/app/search/page.tsx`
314
+ * is `search`. Lets `allowHandWrittenPages` name a known non-CMS page.
315
+ *
316
+ * @param {string} rel posix path from the app root
317
+ */
318
+ function appRestFromRel(rel) {
319
+ return rel
320
+ .replace(/^src\/app\//, '')
321
+ .replace(/\/page\.tsx?$/, '')
322
+ .replace(/^page\.tsx?$/, '')
323
+ .split('/')
324
+ .filter((segment) => segment.length > 0 && !isRouteGroup(segment))
325
+ .join('/');
326
+ }
327
+
248
328
  /**
249
329
  * Shape of a rest for URL collisions: Next rejects two dynamic segments with
250
330
  * different names at one position, so `tag/[slug]` and `tag/[tag]` are one URL.
@@ -320,10 +400,11 @@ export function checkMarketingRoutes(appRoot) {
320
400
  }
321
401
  const found = listMarketingPages(appRoot);
322
402
  const extras = found.pages.filter((rest) => !allowed.has(rest) && !isAllowlisted(handWritten, rest));
403
+ const outside = found.outside.filter((rel) => !isAllowlisted(handWritten, appRestFromRel(rel)));
323
404
  const drift = generatedDrift(appRoot, config);
324
405
  /** @type {string[]} */
325
406
  const problems = [
326
- ...found.outside,
407
+ ...outside,
327
408
  ...extras.map((rest) => `(cms-routes)/${rest ? `${rest}/` : ''}page`),
328
409
  ...drift,
329
410
  ...supportDrift(appRoot, config),
@@ -496,6 +577,14 @@ export function renderMarketingSlugs(config) {
496
577
  )
497
578
  .join('\n')}\n] as const`;
498
579
  const base = (slug) => (slug ? `'/${slug}'` : "''");
580
+ const shape = sectionShape(config);
581
+ const detailLines = shape.declared
582
+ ? `export const PERSON_DETAIL_SLUG = '${shape.personBase}';
583
+ export const PERSON_DETAIL_BASE = ${base(shape.personBase)};
584
+ export const TAG_DETAIL_SLUG = '${shape.tagBase}';
585
+ export const TAG_DETAIL_BASE = ${base(shape.tagBase)};
586
+ `
587
+ : '';
499
588
  return `${header()}
500
589
  export const PEOPLE_SLUG = '${people}';
501
590
  export const PEOPLE_BASE = ${base(people)};
@@ -503,7 +592,7 @@ export const TAGS_SLUG = '${tags}';
503
592
  export const TAGS_BASE = ${base(tags)};
504
593
  export const ARTICLES_SLUG = '${articles}';
505
594
  export const ARTICLES_BASE = ${base(articles)};
506
- export const PERSON_TYPE_SLUGS = ${slugList(personTypes)};
595
+ ${detailLines}export const PERSON_TYPE_SLUGS = ${slugList(personTypes)};
507
596
  export const TAG_TYPE_SLUGS = ${slugList(tagTypes)};
508
597
  export const ARTICLE_TYPE_SLUGS = ${slugList(articleSlugs)};
509
598
  export const ARTICLE_TYPE_ROUTES = ${routeLiteral};
@@ -841,14 +930,17 @@ export function mustBeSsgOrStaticRoutes(config) {
841
930
  push(`${underPrefix(articles, route.slug)}/[article]`);
842
931
  }
843
932
  }
844
- if (people) {
845
- push(`${people}/[person]`);
933
+ const shape = isSectionConfig(config) ? sectionShape(config) : null;
934
+ const personBase = shape ? shape.personBase : people;
935
+ const tagBase = shape ? shape.tagBase : tags;
936
+ if (personBase) {
937
+ push(`${personBase}/[person]`);
846
938
  }
847
939
  for (const type of config.personTypes ?? []) {
848
940
  push(`${underPrefix(people, String(type))}/[person]`);
849
941
  }
850
- if (tags) {
851
- push(`${tags}/[tag]`);
942
+ if (tagBase) {
943
+ push(`${tagBase}/[tag]`);
852
944
  }
853
945
  for (const type of config.tagTypes ?? []) {
854
946
  push(`${underPrefix(tags, String(type))}/[tag]`);
@@ -1095,9 +1187,12 @@ function addSectionRests(allowed, config) {
1095
1187
  const people = typeof config.peopleSlug === 'string' ? config.peopleSlug : '';
1096
1188
  const tags = typeof config.tagsSlug === 'string' ? config.tagsSlug : '';
1097
1189
  const articles = typeof config.articlesSlug === 'string' ? config.articlesSlug : '';
1098
- if (people) {
1190
+ const shape = sectionShape(config);
1191
+ if (shape.peopleIndex) {
1099
1192
  allowed.add(people);
1100
- allowed.add(`${people}/[person]`);
1193
+ }
1194
+ if (shape.personBase) {
1195
+ allowed.add(`${shape.personBase}/[person]`);
1101
1196
  }
1102
1197
  for (const type of config.personTypes ?? []) {
1103
1198
  const segment = requireSegment(type, 'personTypes');
@@ -1105,9 +1200,11 @@ function addSectionRests(allowed, config) {
1105
1200
  allowed.add(rest);
1106
1201
  allowed.add(`${rest}/[person]`);
1107
1202
  }
1108
- if (tags) {
1203
+ if (shape.tagsIndex) {
1109
1204
  allowed.add(tags);
1110
- allowed.add(`${tags}/[tag]`);
1205
+ }
1206
+ if (shape.tagBase) {
1207
+ allowed.add(`${shape.tagBase}/[tag]`);
1111
1208
  }
1112
1209
  for (const type of config.tagTypes ?? []) {
1113
1210
  const segment = requireSegment(type, 'tagTypes');
@@ -1155,10 +1252,13 @@ function renderSectionRoutes(config, files) {
1155
1252
  const people = typeof config.peopleSlug === 'string' ? config.peopleSlug : '';
1156
1253
  const tags = typeof config.tagsSlug === 'string' ? config.tagsSlug : '';
1157
1254
  const articles = typeof config.articlesSlug === 'string' ? config.articlesSlug : '';
1158
- if (people) {
1255
+ const shape = sectionShape(config);
1256
+ if (shape.peopleIndex) {
1159
1257
  const segment = requireSegment(people, 'peopleSlug');
1160
1258
  files.set(segment, peopleIndexPage(segment));
1161
- files.set(`${segment}/[person]`, untypedPersonPage(segment));
1259
+ }
1260
+ if (shape.personBase) {
1261
+ files.set(`${shape.personBase}/[person]`, untypedPersonPage(shape.personBase));
1162
1262
  }
1163
1263
  for (const type of config.personTypes ?? []) {
1164
1264
  const segment = requireSegment(type, 'personTypes');
@@ -1166,10 +1266,12 @@ function renderSectionRoutes(config, files) {
1166
1266
  files.set(rest, topPersonTypeIndex(rest, segment));
1167
1267
  files.set(`${rest}/[person]`, topPersonTypePerson(rest, segment));
1168
1268
  }
1169
- if (tags) {
1269
+ if (shape.tagsIndex) {
1170
1270
  const segment = requireSegment(tags, 'tagsSlug');
1171
1271
  files.set(segment, sectionTagsIndex(segment));
1172
- files.set(`${segment}/[tag]`, sectionTagPage(segment));
1272
+ }
1273
+ if (shape.tagBase) {
1274
+ files.set(`${shape.tagBase}/[tag]`, sectionTagPage(shape.tagBase, shape.declared));
1173
1275
  }
1174
1276
  for (const type of config.tagTypes ?? []) {
1175
1277
  const segment = requireSegment(type, 'tagTypes');
@@ -1488,9 +1590,14 @@ ${page}
1488
1590
  }
1489
1591
 
1490
1592
  /**
1593
+ * Tag detail page. A config that declares the URL shape passes the served path
1594
+ * as a literal, so the canonical cannot drift from the route. Without it the
1595
+ * path comes from the site's tag url calculator.
1596
+ *
1491
1597
  * @param {string} segment
1598
+ * @param {boolean} [literalPath]
1492
1599
  */
1493
- function sectionTagPage(segment) {
1600
+ function sectionTagPage(segment, literalPath = false) {
1494
1601
  const props = `PageProps<'/${segment}/[tag]'>`;
1495
1602
  const extract = openFn('async function extractDetails', [`props: ${props}`]);
1496
1603
  const metadata = openFn('export async function generateMetadata', [
@@ -1498,9 +1605,14 @@ function sectionTagPage(segment) {
1498
1605
  'parent: ResolvingMetadata',
1499
1606
  ]);
1500
1607
  const page = openFn('export default async function ', [`props: ${props}`]);
1608
+ const calculatorImport = literalPath
1609
+ ? ''
1610
+ : "import { converterContext } from '@/lib/converter-context';\n";
1611
+ const pathExpr = literalPath
1612
+ ? `\`/${segment}/\${tag}/\``
1613
+ : 'converterContext.urlCalculators.tag(tag)';
1501
1614
  return `${header()}import type { ResolvingMetadata } from 'next';
1502
- import { converterContext } from '@/lib/converter-context';
1503
- import { generateTagMetadata, generateTagPage } from '@/lib/route-handlers';
1615
+ ${calculatorImport}import { generateTagMetadata, generateTagPage } from '@/lib/route-handlers';
1504
1616
  import { TAG_LISTING_ROUTE_CONFIG } from '@/lib/routeConfig';
1505
1617
 
1506
1618
  export function generateStaticParams() {
@@ -1510,7 +1622,7 @@ export function generateStaticParams() {
1510
1622
  ${extract}
1511
1623
  const params = await props.params;
1512
1624
  const { tag } = params;
1513
- return { tagSlug: tag, path: converterContext.urlCalculators.tag(tag) };
1625
+ return { tagSlug: tag, path: ${pathExpr} };
1514
1626
  }
1515
1627
 
1516
1628
  ${metadata}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@se-studio/project-build",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Build tools and management scripts for SE Studio projects",
5
5
  "repository": {
6
6
  "type": "git",