@se-studio/project-build 1.5.0 → 1.7.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 +21 -0
- package/README.md +69 -1
- package/dist/check-marketing-routes.mjs +7 -2
- package/dist/generate-marketing-routes.mjs +34 -2
- package/dist/marketing-routes-cms.mjs +149 -13
- package/dist/marketing-routes.mjs +414 -41
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @se-studio/project-build
|
|
2
2
|
|
|
3
|
+
## 1.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 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).
|
|
8
|
+
|
|
9
|
+
`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.
|
|
10
|
+
|
|
11
|
+
## 1.6.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- 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.
|
|
16
|
+
|
|
17
|
+
- 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.
|
|
18
|
+
- 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.
|
|
19
|
+
- `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.
|
|
20
|
+
- `--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.
|
|
21
|
+
- `@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.
|
|
22
|
+
- Docs and skills (`@se-studio/skills`) describe the keys, the hook and the allowlist.
|
|
23
|
+
|
|
3
24
|
## 1.5.0
|
|
4
25
|
|
|
5
26
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -131,7 +131,75 @@ 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
|
|
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
|
+
##### 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
|
+
|
|
160
|
+
##### URL shape: index and detail slugs, index switches, custom tag listing
|
|
161
|
+
|
|
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.
|
|
163
|
+
|
|
164
|
+
| Key | Meaning | Default |
|
|
165
|
+
|-----|---------|---------|
|
|
166
|
+
| `peopleSlug` / `tagsSlug` | Index segment, and the prefix for person types and tag types | none |
|
|
167
|
+
| `personSlug` / `tagSlug` | Singular detail segment: `/{personSlug}/{person}/`, `/{tagSlug}/{tag}/` | the index slug |
|
|
168
|
+
| `enablePeopleIndex` / `enableTagsIndex` | Whether `/{peopleSlug}/` and `/{tagsSlug}/` exist. `true` needs the index slug | `true` when the index slug is set |
|
|
169
|
+
|
|
170
|
+
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}/`).
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"peopleSlug": "people",
|
|
175
|
+
"personSlug": "person",
|
|
176
|
+
"enablePeopleIndex": true,
|
|
177
|
+
"tagsSlug": "tags",
|
|
178
|
+
"tagSlug": "tag",
|
|
179
|
+
"enableTagsIndex": false
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
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.
|
|
184
|
+
|
|
185
|
+
**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:
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
createRouteHandlers({
|
|
189
|
+
// ...
|
|
190
|
+
renderTagListing: async ({ tag, tagSlug, path, locale }) => (
|
|
191
|
+
<>
|
|
192
|
+
<ResourceCategoryFilter activeSlug={tagSlug} />
|
|
193
|
+
<ResourceList tagSlug={tagSlug} />
|
|
194
|
+
</>
|
|
195
|
+
),
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
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.
|
|
200
|
+
|
|
201
|
+
**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.
|
|
202
|
+
|
|
135
203
|
|
|
136
204
|
#### `setailwind`
|
|
137
205
|
Tailwind CSS v4 build system with file watching.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Fail hand-written
|
|
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
|
}
|
|
@@ -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
|
|
@@ -28,6 +32,13 @@
|
|
|
28
32
|
* that config and formats the generated `(cms-routes)` pages with the app's
|
|
29
33
|
* Biome. `allowedDynamic` is left as it is.
|
|
30
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
|
+
*
|
|
31
42
|
* Usage:
|
|
32
43
|
* node scripts/generate-marketing-routes.mjs <app-dir> [--from-cms] [--write] [--force]
|
|
33
44
|
* generate-marketing-routes <app-dir> [--from-cms] [--write] [--force]
|
|
@@ -37,15 +48,17 @@ import fs from 'node:fs';
|
|
|
37
48
|
import path from 'node:path';
|
|
38
49
|
import { fileURLToPath } from 'node:url';
|
|
39
50
|
import {
|
|
51
|
+
articleTypeOptionsFromHand,
|
|
40
52
|
fetchContentSlugs,
|
|
41
53
|
mergeCmsEnv,
|
|
42
54
|
planFromCms,
|
|
43
55
|
sectionConfigFromPlan,
|
|
44
56
|
} from './marketing-routes-cms.mjs';
|
|
45
|
-
import { readMarketingRoutes, syncGeneratedRoutes } from './marketing-routes.mjs';
|
|
57
|
+
import { parseAllowlist, readMarketingRoutes, syncGeneratedRoutes } from './marketing-routes.mjs';
|
|
46
58
|
|
|
47
59
|
const args = process.argv.slice(2).filter((arg) => !arg.startsWith('--'));
|
|
48
|
-
|
|
60
|
+
// --force only widens what --write may replace; on its own it is still a dry run.
|
|
61
|
+
const write = process.argv.includes('--write');
|
|
49
62
|
const force = process.argv.includes('--force');
|
|
50
63
|
const fromCms = process.argv.includes('--from-cms');
|
|
51
64
|
const app = args[0];
|
|
@@ -80,13 +93,22 @@ if (fromCms) {
|
|
|
80
93
|
peopleSlug: hand.peopleSlug,
|
|
81
94
|
tagsSlug: hand.tagsSlug,
|
|
82
95
|
articlesSlug: hand.articlesSlug,
|
|
96
|
+
personSlug: hand.personSlug,
|
|
97
|
+
tagSlug: hand.tagSlug,
|
|
98
|
+
enablePeopleIndex: hand.enablePeopleIndex,
|
|
99
|
+
enableTagsIndex: hand.enableTagsIndex,
|
|
83
100
|
tagInPath: hand.tagInPath === true,
|
|
84
101
|
tagTypeRoutes: hand.tagTypeRoutes !== false,
|
|
102
|
+
excludeArticleTypes: Array.isArray(hand.excludeArticleTypes) ? hand.excludeArticleTypes : [],
|
|
103
|
+
articleTypeOptions: articleTypeOptionsFromHand(hand),
|
|
85
104
|
});
|
|
86
105
|
if (!plan.ok) {
|
|
87
106
|
console.error(plan.problems.join('\n'));
|
|
88
107
|
process.exit(1);
|
|
89
108
|
}
|
|
109
|
+
for (const warning of plan.warnings) {
|
|
110
|
+
console.warn(`warning: ${warning}`);
|
|
111
|
+
}
|
|
90
112
|
const next = sectionConfigFromPlan(hand, plan);
|
|
91
113
|
const configPath = path.join(appRoot, 'src/lib/marketing-routes.json');
|
|
92
114
|
if (!write) {
|
|
@@ -97,7 +119,17 @@ if (fromCms) {
|
|
|
97
119
|
console.log(`Updated ${configPath}`);
|
|
98
120
|
}
|
|
99
121
|
|
|
122
|
+
if (force && !write) {
|
|
123
|
+
console.warn('--force without --write is a dry run: nothing is written. Add --write.');
|
|
124
|
+
}
|
|
100
125
|
const result = syncGeneratedRoutes(appRoot, { write, force });
|
|
126
|
+
try {
|
|
127
|
+
for (const warning of parseAllowlist(readMarketingRoutes(appRoot)).warnings) {
|
|
128
|
+
console.warn(`warning: ${warning}`);
|
|
129
|
+
}
|
|
130
|
+
} catch {
|
|
131
|
+
// an invalid allowlist is reported by check-marketing-routes
|
|
132
|
+
}
|
|
101
133
|
for (const note of result.tagSkips) {
|
|
102
134
|
console.log(note);
|
|
103
135
|
}
|
|
@@ -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
|
|
@@ -181,6 +191,30 @@ function handSlug(input, key, inferred, problems = null) {
|
|
|
181
191
|
return segmentOrNull(value, key, problems);
|
|
182
192
|
}
|
|
183
193
|
|
|
194
|
+
/**
|
|
195
|
+
* An explicit index switch, or "the index slug is set". True needs the slug.
|
|
196
|
+
*
|
|
197
|
+
* @param {Record<string, unknown>} input
|
|
198
|
+
* @param {string} key
|
|
199
|
+
* @param {string | null} slug
|
|
200
|
+
* @param {string} slugKey
|
|
201
|
+
* @param {string[]} problems
|
|
202
|
+
* @returns {boolean}
|
|
203
|
+
*/
|
|
204
|
+
function indexFlag(input, key, slug, slugKey, problems) {
|
|
205
|
+
const value = input[key];
|
|
206
|
+
if (value === undefined) return Boolean(slug);
|
|
207
|
+
if (typeof value !== 'boolean') {
|
|
208
|
+
problems.push(`${key} must be a boolean`);
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
if (value && !slug) {
|
|
212
|
+
problems.push(`${key} is true but ${slugKey} is not set`);
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
return value;
|
|
216
|
+
}
|
|
217
|
+
|
|
184
218
|
/**
|
|
185
219
|
* @param {Map<string, string>} used
|
|
186
220
|
* @param {string} rest
|
|
@@ -188,12 +222,13 @@ function handSlug(input, key, inferred, problems = null) {
|
|
|
188
222
|
* @param {string[]} problems
|
|
189
223
|
*/
|
|
190
224
|
function claimRest(used, rest, label, problems) {
|
|
191
|
-
const
|
|
225
|
+
const key = rest.replace(/\[(?!\.)[^\]]+\]/g, '[]');
|
|
226
|
+
const previous = used.get(key);
|
|
192
227
|
if (previous) {
|
|
193
228
|
problems.push(`route ${rest} is used by ${previous} and ${label}`);
|
|
194
229
|
return;
|
|
195
230
|
}
|
|
196
|
-
used.set(
|
|
231
|
+
used.set(key, label);
|
|
197
232
|
}
|
|
198
233
|
|
|
199
234
|
/**
|
|
@@ -205,13 +240,23 @@ function claimRest(used, rest, label, problems) {
|
|
|
205
240
|
* peopleSlug?: string | null,
|
|
206
241
|
* tagsSlug?: string | null,
|
|
207
242
|
* articlesSlug?: string | null,
|
|
243
|
+
* personSlug?: string | null,
|
|
244
|
+
* tagSlug?: string | null,
|
|
245
|
+
* enablePeopleIndex?: boolean,
|
|
246
|
+
* enableTagsIndex?: boolean,
|
|
208
247
|
* tagInPath?: boolean,
|
|
209
248
|
* tagTypeRoutes?: boolean,
|
|
249
|
+
* excludeArticleTypes?: string[],
|
|
250
|
+
* articleTypeOptions?: Record<string, { detailPages?: boolean, nestedSlugs?: boolean }>,
|
|
210
251
|
* }} input
|
|
211
252
|
*/
|
|
212
253
|
export function planFromCms(input) {
|
|
213
254
|
/** @type {string[]} */
|
|
214
255
|
const problems = [];
|
|
256
|
+
/** @type {string[]} */
|
|
257
|
+
const warnings = [];
|
|
258
|
+
const excluded = new Set(input.excludeArticleTypes ?? []);
|
|
259
|
+
const options = input.articleTypeOptions ?? {};
|
|
215
260
|
const declared = {
|
|
216
261
|
person: handSlug(input, 'peopleSlug', null),
|
|
217
262
|
tag: handSlug(input, 'tagsSlug', null),
|
|
@@ -241,6 +286,10 @@ export function planFromCms(input) {
|
|
|
241
286
|
/** @type {string[]} */
|
|
242
287
|
const personTypes = [];
|
|
243
288
|
for (const entry of input.personTypes ?? []) {
|
|
289
|
+
if (isSlugless(entry)) {
|
|
290
|
+
warnings.push(`skipped person type "${entry?.name ?? '(unnamed)'}": no slug`);
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
244
293
|
const slug = segmentOrNull(entry?.slug, 'person type', problems);
|
|
245
294
|
if (slug) {
|
|
246
295
|
personTypes.push(slug);
|
|
@@ -253,6 +302,10 @@ export function planFromCms(input) {
|
|
|
253
302
|
if (entry?.show === false || !tagTypeRoutes) {
|
|
254
303
|
continue;
|
|
255
304
|
}
|
|
305
|
+
if (isSlugless(entry)) {
|
|
306
|
+
warnings.push(`skipped tag type "${entry?.name ?? '(unnamed)'}": no slug`);
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
256
309
|
const slug = segmentOrNull(entry?.slug, 'tag type', problems);
|
|
257
310
|
if (slug) {
|
|
258
311
|
tagTypes.push(slug);
|
|
@@ -261,10 +314,20 @@ export function planFromCms(input) {
|
|
|
261
314
|
const peopleSlug = handSlug(input, 'peopleSlug', prefixes.person, problems);
|
|
262
315
|
const tagsSlug = handSlug(input, 'tagsSlug', prefixes.tag, problems);
|
|
263
316
|
const articlesSlug = handSlug(input, 'articlesSlug', prefixes.article, problems);
|
|
317
|
+
const personBase =
|
|
318
|
+
input.personSlug == null ? peopleSlug : handSlug(input, 'personSlug', peopleSlug, problems);
|
|
319
|
+
const tagBase =
|
|
320
|
+
input.tagSlug == null ? tagsSlug : handSlug(input, 'tagSlug', tagsSlug, problems);
|
|
321
|
+
const peopleIndex = indexFlag(input, 'enablePeopleIndex', peopleSlug, 'peopleSlug', problems);
|
|
322
|
+
const tagsIndex = indexFlag(input, 'enableTagsIndex', tagsSlug, 'tagsSlug', problems);
|
|
264
323
|
const categoryPath = input.tagInPath === true && !articlesSlug;
|
|
265
|
-
/** @type {{ slug: string, indexSlug: string }[]} */
|
|
324
|
+
/** @type {{ slug: string, indexSlug: string, detailPages?: false, nestedSlugs?: true }[]} */
|
|
266
325
|
const articleTypes = [];
|
|
267
326
|
for (const entry of input.articleTypes ?? []) {
|
|
327
|
+
if (typeof entry?.slug === 'string' && excluded.has(entry.slug)) {
|
|
328
|
+
warnings.push(`excluded article type "${entry.slug}" (excludeArticleTypes)`);
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
268
331
|
const slug = categoryPath
|
|
269
332
|
? pathOrNull(entry?.slug, 'article type', problems)
|
|
270
333
|
: segmentOrNull(entry?.slug, 'article type', problems);
|
|
@@ -284,22 +347,41 @@ export function planFromCms(input) {
|
|
|
284
347
|
);
|
|
285
348
|
continue;
|
|
286
349
|
}
|
|
287
|
-
|
|
350
|
+
const opt = options[slug] ?? {};
|
|
351
|
+
if (opt.nestedSlugs === true && opt.detailPages === false) {
|
|
352
|
+
problems.push(`${slug}: nestedSlugs has no effect with detailPages: false`);
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
if (categoryPath && (opt.nestedSlugs === true || opt.detailPages === false)) {
|
|
356
|
+
problems.push(`${slug}: detailPages and nestedSlugs are not supported with tagInPath`);
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
articleTypes.push({
|
|
360
|
+
slug,
|
|
361
|
+
indexSlug,
|
|
362
|
+
...(opt.detailPages === false ? { detailPages: false } : {}),
|
|
363
|
+
...(opt.nestedSlugs === true ? { nestedSlugs: true } : {}),
|
|
364
|
+
});
|
|
288
365
|
}
|
|
289
366
|
/** @type {Map<string, string>} */
|
|
290
367
|
const used = new Map();
|
|
291
|
-
if (
|
|
368
|
+
if (peopleIndex) {
|
|
292
369
|
claimRest(used, peopleSlug, 'person prefix', problems);
|
|
293
|
-
|
|
370
|
+
}
|
|
371
|
+
if (personBase) {
|
|
372
|
+
claimRest(used, `${personBase}/[person]`, 'untyped person', problems);
|
|
294
373
|
}
|
|
295
374
|
for (const type of personTypes) {
|
|
296
375
|
const rest = peopleSlug ? `${peopleSlug}/${type}` : type;
|
|
297
376
|
claimRest(used, rest, `person type ${type}`, problems);
|
|
298
377
|
claimRest(used, `${rest}/[person]`, `person type ${type} person`, problems);
|
|
299
378
|
}
|
|
300
|
-
if (
|
|
379
|
+
if (tagsIndex) {
|
|
301
380
|
claimRest(used, tagsSlug, 'tag prefix', problems);
|
|
302
381
|
}
|
|
382
|
+
if (tagBase) {
|
|
383
|
+
claimRest(used, `${tagBase}/[tag]`, 'tag', problems);
|
|
384
|
+
}
|
|
303
385
|
for (const type of tagTypes) {
|
|
304
386
|
const rest = tagsSlug ? `${tagsSlug}/${type}` : type;
|
|
305
387
|
claimRest(used, rest, `tag type ${type}`, problems);
|
|
@@ -318,20 +400,28 @@ export function planFromCms(input) {
|
|
|
318
400
|
const indexRest = articlesSlug ? `${articlesSlug}/${type.indexSlug}` : type.indexSlug;
|
|
319
401
|
const articleRest = articlesSlug ? `${articlesSlug}/${type.slug}` : type.slug;
|
|
320
402
|
claimRest(used, indexRest, `${type.slug} index`, problems);
|
|
321
|
-
if (articleRest !== indexRest) {
|
|
403
|
+
if (articleRest !== indexRest && type.detailPages !== false) {
|
|
322
404
|
claimRest(used, articleRest, `${type.slug} articles`, problems);
|
|
323
405
|
}
|
|
324
|
-
|
|
406
|
+
if (type.detailPages !== false) {
|
|
407
|
+
claimRest(
|
|
408
|
+
used,
|
|
409
|
+
`${articleRest}/${type.nestedSlugs ? '[...slugs]' : '[article]'}`,
|
|
410
|
+
`${type.slug} article`,
|
|
411
|
+
problems,
|
|
412
|
+
);
|
|
413
|
+
}
|
|
325
414
|
}
|
|
326
415
|
|
|
327
416
|
if (problems.length > 0) {
|
|
328
417
|
return { ok: false, problems };
|
|
329
418
|
}
|
|
330
419
|
const hasArticles = articleTypes.length > 0 || Boolean(articlesSlug);
|
|
331
|
-
const hasTags = tagTypes.length > 0 || Boolean(
|
|
332
|
-
const hasPeople = personTypes.length > 0 || Boolean(
|
|
420
|
+
const hasTags = tagTypes.length > 0 || Boolean(tagBase);
|
|
421
|
+
const hasPeople = personTypes.length > 0 || Boolean(personBase);
|
|
333
422
|
return {
|
|
334
423
|
ok: true,
|
|
424
|
+
warnings,
|
|
335
425
|
peopleSlug,
|
|
336
426
|
tagsSlug,
|
|
337
427
|
articlesSlug,
|
|
@@ -342,14 +432,31 @@ export function planFromCms(input) {
|
|
|
342
432
|
enableArticleTypeIndex: hasArticles,
|
|
343
433
|
enableArticleTypeTagIndex: false,
|
|
344
434
|
enableTag: hasTags,
|
|
345
|
-
enableTagsIndex:
|
|
435
|
+
enableTagsIndex: tagsIndex,
|
|
346
436
|
enablePerson: hasPeople,
|
|
347
|
-
enablePeopleIndex:
|
|
437
|
+
enablePeopleIndex: peopleIndex,
|
|
348
438
|
enablePrimaryTagPartOfSlug: false,
|
|
349
439
|
},
|
|
350
440
|
};
|
|
351
441
|
}
|
|
352
442
|
|
|
443
|
+
/**
|
|
444
|
+
* URL shape keys are hand-written, never inferred from the CMS, so they pass through.
|
|
445
|
+
*
|
|
446
|
+
* @param {Record<string, unknown>} hand
|
|
447
|
+
* @param {string[]} keys
|
|
448
|
+
*/
|
|
449
|
+
function shapeKeys(hand, ...keys) {
|
|
450
|
+
/** @type {Record<string, unknown>} */
|
|
451
|
+
const kept = {};
|
|
452
|
+
for (const key of keys) {
|
|
453
|
+
if (hand[key] !== undefined && hand[key] !== null) {
|
|
454
|
+
kept[key] = hand[key];
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return kept;
|
|
458
|
+
}
|
|
459
|
+
|
|
353
460
|
/**
|
|
354
461
|
* Keep hand-written app switches. Section paths and flags come from the plan.
|
|
355
462
|
*
|
|
@@ -366,7 +473,9 @@ export function sectionConfigFromPlan(hand, plan) {
|
|
|
366
473
|
pageTest: hand.pageTest === true,
|
|
367
474
|
tagInPath,
|
|
368
475
|
peopleSlug: plan.peopleSlug,
|
|
476
|
+
...shapeKeys(hand, 'personSlug', 'enablePeopleIndex'),
|
|
369
477
|
tagsSlug: plan.tagsSlug,
|
|
478
|
+
...shapeKeys(hand, 'tagSlug', 'enableTagsIndex'),
|
|
370
479
|
articlesSlug: plan.articlesSlug,
|
|
371
480
|
personTypes: plan.personTypes,
|
|
372
481
|
tagTypes: plan.tagTypes,
|
|
@@ -375,6 +484,9 @@ export function sectionConfigFromPlan(hand, plan) {
|
|
|
375
484
|
if (hand.tagTypeRoutes === false) {
|
|
376
485
|
next.tagTypeRoutes = false;
|
|
377
486
|
}
|
|
487
|
+
if (Array.isArray(hand.excludeArticleTypes) && hand.excludeArticleTypes.length > 0) {
|
|
488
|
+
next.excludeArticleTypes = hand.excludeArticleTypes;
|
|
489
|
+
}
|
|
378
490
|
if (Array.isArray(hand.allowHandWrittenPages) && hand.allowHandWrittenPages.length > 0) {
|
|
379
491
|
next.allowHandWrittenPages = hand.allowHandWrittenPages;
|
|
380
492
|
}
|
|
@@ -437,3 +549,27 @@ export async function fetchContentSlugs(env, contentType, fields = ['slug', 'nam
|
|
|
437
549
|
}
|
|
438
550
|
return entries;
|
|
439
551
|
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Per-type options already in the hand-written config. `--from-cms` rewrites
|
|
555
|
+
* `articleTypes` from the CMS, so options live here and are carried over.
|
|
556
|
+
*
|
|
557
|
+
* @param {Record<string, unknown>} hand
|
|
558
|
+
* @returns {Record<string, { detailPages?: boolean, nestedSlugs?: boolean }>}
|
|
559
|
+
*/
|
|
560
|
+
export function articleTypeOptionsFromHand(hand) {
|
|
561
|
+
/** @type {Record<string, { detailPages?: boolean, nestedSlugs?: boolean }>} */
|
|
562
|
+
const options = {};
|
|
563
|
+
for (const type of Array.isArray(hand.articleTypes) ? hand.articleTypes : []) {
|
|
564
|
+
if (!type || typeof type !== 'object' || typeof type.slug !== 'string') {
|
|
565
|
+
continue;
|
|
566
|
+
}
|
|
567
|
+
const entry = {};
|
|
568
|
+
if (type.detailPages === false) entry.detailPages = false;
|
|
569
|
+
if (type.nestedSlugs === true) entry.nestedSlugs = true;
|
|
570
|
+
if (Object.keys(entry).length > 0) {
|
|
571
|
+
options[type.slug] = entry;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return options;
|
|
575
|
+
}
|
|
@@ -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
|
|
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 =
|
|
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:
|
|
125
|
+
enableTagsIndex: shape.tagsIndex,
|
|
71
126
|
enablePerson: people || personTypes,
|
|
72
|
-
enablePeopleIndex:
|
|
127
|
+
enablePeopleIndex: shape.peopleIndex,
|
|
73
128
|
enablePrimaryTagPartOfSlug: tagInPath,
|
|
74
129
|
};
|
|
75
130
|
}
|
|
@@ -212,21 +267,66 @@ 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.
|
|
216
|
-
*
|
|
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"`). Every entry is `{ path, reason }`; a bare
|
|
273
|
+
* string is deprecated (warned, not failed). Not a way to add a marketing URL.
|
|
274
|
+
* To keep a custom tag listing or filter, use the `renderTagListing` route hook
|
|
275
|
+
* instead of hand-writing the page.
|
|
217
276
|
*
|
|
218
277
|
* @param {unknown} config
|
|
219
278
|
* @returns {Set<string>}
|
|
220
279
|
*/
|
|
221
280
|
export function handWrittenAllowlist(config) {
|
|
281
|
+
return new Set(parseAllowlist(config).entries.map((entry) => entry.rest));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Entries are `{ "path": "preview", "reason": "why this stays hand-written" }`. A bare
|
|
286
|
+
* string is the deprecated form: still honoured, but `warnings` names it. An object
|
|
287
|
+
* without a non-empty `reason` (or a `path`) is a hard error.
|
|
288
|
+
*
|
|
289
|
+
* @param {unknown} config
|
|
290
|
+
* @returns {{ entries: { rest: string, reason: string | null }[], warnings: string[] }}
|
|
291
|
+
*/
|
|
292
|
+
export function parseAllowlist(config) {
|
|
222
293
|
const raw = config && typeof config === 'object' ? config.allowHandWrittenPages : undefined;
|
|
223
294
|
if (raw === undefined) {
|
|
224
|
-
return
|
|
295
|
+
return { entries: [], warnings: [] };
|
|
296
|
+
}
|
|
297
|
+
if (!Array.isArray(raw)) {
|
|
298
|
+
throw new Error(
|
|
299
|
+
'marketing-routes.json allowHandWrittenPages must be an array of { path, reason } objects',
|
|
300
|
+
);
|
|
225
301
|
}
|
|
226
|
-
|
|
227
|
-
|
|
302
|
+
/** @type {{ rest: string, reason: string | null }[]} */
|
|
303
|
+
const entries = [];
|
|
304
|
+
/** @type {string[]} */
|
|
305
|
+
const warnings = [];
|
|
306
|
+
for (const item of raw) {
|
|
307
|
+
if (typeof item === 'string') {
|
|
308
|
+
if (item.length === 0) {
|
|
309
|
+
throw new Error('marketing-routes.json allowHandWrittenPages has an empty entry');
|
|
310
|
+
}
|
|
311
|
+
entries.push({ rest: cleanAllowEntry(item), reason: null });
|
|
312
|
+
warnings.push(
|
|
313
|
+
`allowHandWrittenPages entry "${item}" is a bare string (deprecated): use { "path": "${item}", "reason": "..." }`,
|
|
314
|
+
);
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const entryPath = item && typeof item === 'object' ? item.path : undefined;
|
|
318
|
+
const reason = item && typeof item === 'object' ? item.reason : undefined;
|
|
319
|
+
if (typeof entryPath !== 'string' || entryPath.length === 0) {
|
|
320
|
+
throw new Error('marketing-routes.json allowHandWrittenPages entries need a non-empty "path"');
|
|
321
|
+
}
|
|
322
|
+
if (typeof reason !== 'string' || reason.trim().length === 0) {
|
|
323
|
+
throw new Error(
|
|
324
|
+
`marketing-routes.json allowHandWrittenPages entry "${entryPath}" needs a non-empty "reason"`,
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
entries.push({ rest: cleanAllowEntry(entryPath), reason: reason.trim() });
|
|
228
328
|
}
|
|
229
|
-
return
|
|
329
|
+
return { entries, warnings };
|
|
230
330
|
}
|
|
231
331
|
|
|
232
332
|
/**
|
|
@@ -237,7 +337,13 @@ export function handWrittenAllowlist(config) {
|
|
|
237
337
|
*/
|
|
238
338
|
function cleanAllowEntry(entry) {
|
|
239
339
|
const fromPath = routeRestFromRel(entry.replace(/^\/+/, ''));
|
|
240
|
-
const rest =
|
|
340
|
+
const rest =
|
|
341
|
+
fromPath ??
|
|
342
|
+
entry
|
|
343
|
+
.replace(/^\/+/, '')
|
|
344
|
+
.replace(/^src\/app\//, '')
|
|
345
|
+
.replace(/\/page\.tsx?$/, '')
|
|
346
|
+
.replace(/^page\.tsx?$/, '');
|
|
241
347
|
return rest
|
|
242
348
|
.replace(/^\/+|\/+$/g, '')
|
|
243
349
|
.split('/')
|
|
@@ -245,6 +351,22 @@ function cleanAllowEntry(entry) {
|
|
|
245
351
|
.join('/');
|
|
246
352
|
}
|
|
247
353
|
|
|
354
|
+
/**
|
|
355
|
+
* URL rest of a page outside `(cms-routes)`, route groups dropped. `src/app/search/page.tsx`
|
|
356
|
+
* is `search`. Lets `allowHandWrittenPages` name a known non-CMS page.
|
|
357
|
+
*
|
|
358
|
+
* @param {string} rel posix path from the app root
|
|
359
|
+
*/
|
|
360
|
+
function appRestFromRel(rel) {
|
|
361
|
+
return rel
|
|
362
|
+
.replace(/^src\/app\//, '')
|
|
363
|
+
.replace(/\/page\.tsx?$/, '')
|
|
364
|
+
.replace(/^page\.tsx?$/, '')
|
|
365
|
+
.split('/')
|
|
366
|
+
.filter((segment) => segment.length > 0 && !isRouteGroup(segment))
|
|
367
|
+
.join('/');
|
|
368
|
+
}
|
|
369
|
+
|
|
248
370
|
/**
|
|
249
371
|
* Shape of a rest for URL collisions: Next rejects two dynamic segments with
|
|
250
372
|
* different names at one position, so `tag/[slug]` and `tag/[tag]` are one URL.
|
|
@@ -286,6 +408,50 @@ export function isAllowlisted(allow, rest) {
|
|
|
286
408
|
return false;
|
|
287
409
|
}
|
|
288
410
|
|
|
411
|
+
/** Where a repo that has not migrated records why it has no marketing-routes.json. */
|
|
412
|
+
export const OPT_OUT_REL = 'src/lib/marketing-routes.opt-out.json';
|
|
413
|
+
const CONFIG_REL = 'src/lib/marketing-routes.json';
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* `route.ts` / `route.tsx` handlers under `src/app`. A handler under `(cms-routes)` is
|
|
417
|
+
* a marketing URL. One elsewhere only counts when its URL shape equals a generated
|
|
418
|
+
* marketing route (it would shadow a CMS page); api, sitemap, og and other fixed
|
|
419
|
+
* handlers never match a bracket route.
|
|
420
|
+
*
|
|
421
|
+
* @param {string} appRoot
|
|
422
|
+
* @returns {{ inside: string[], outside: { rel: string, rest: string }[] }}
|
|
423
|
+
*/
|
|
424
|
+
export function listRouteHandlers(appRoot) {
|
|
425
|
+
/** @type {string[]} */
|
|
426
|
+
const inside = [];
|
|
427
|
+
/** @type {{ rel: string, rest: string }[]} */
|
|
428
|
+
const outside = [];
|
|
429
|
+
const appDir = path.join(appRoot, 'src/app');
|
|
430
|
+
if (!fs.existsSync(appDir)) {
|
|
431
|
+
return { inside, outside };
|
|
432
|
+
}
|
|
433
|
+
walk(appDir, (file) => {
|
|
434
|
+
const base = path.basename(file);
|
|
435
|
+
if (base !== 'route.ts' && base !== 'route.tsx') {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
const rel = path.relative(appRoot, file).split(path.sep).join('/');
|
|
439
|
+
if (rel.includes('/(cms-dev)/')) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const rest = routeRestFromRel(rel.replace(/\/route\.tsx?$/, '/page.ts'));
|
|
443
|
+
if (rest !== null) {
|
|
444
|
+
inside.push(rel);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
outside.push({
|
|
448
|
+
rel,
|
|
449
|
+
rest: appRestFromRel(rel.replace(/\/route\.tsx?$/, '/page.ts')),
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
return { inside, outside };
|
|
453
|
+
}
|
|
454
|
+
|
|
289
455
|
/**
|
|
290
456
|
* @param {string} appRoot
|
|
291
457
|
*/
|
|
@@ -297,11 +463,41 @@ export function checkMarketingRoutes(appRoot) {
|
|
|
297
463
|
const message = error instanceof Error ? error.message : String(error);
|
|
298
464
|
return { ok: false, severity: 'error', detail: `marketing-routes.json: ${message}` };
|
|
299
465
|
}
|
|
466
|
+
const optOutAbs = path.join(appRoot, OPT_OUT_REL);
|
|
300
467
|
if (!config) {
|
|
468
|
+
if (!fs.existsSync(optOutAbs)) {
|
|
469
|
+
return {
|
|
470
|
+
ok: false,
|
|
471
|
+
severity: 'error',
|
|
472
|
+
detail: `no ${CONFIG_REL}: run generate-marketing-routes --from-cms --write, or (repos not yet migrated only) add ${OPT_OUT_REL} with {"reason": "..."}`,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
let reason = '';
|
|
476
|
+
try {
|
|
477
|
+
const parsed = JSON.parse(fs.readFileSync(optOutAbs, 'utf8'));
|
|
478
|
+
reason = typeof parsed?.reason === 'string' ? parsed.reason.trim() : '';
|
|
479
|
+
} catch (error) {
|
|
480
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
481
|
+
return { ok: false, severity: 'error', detail: `${OPT_OUT_REL}: ${message}` };
|
|
482
|
+
}
|
|
483
|
+
if (!reason) {
|
|
484
|
+
return {
|
|
485
|
+
ok: false,
|
|
486
|
+
severity: 'error',
|
|
487
|
+
detail: `${OPT_OUT_REL} needs a non-empty "reason" (why this repo has no marketing-routes.json yet)`,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
301
490
|
return {
|
|
302
491
|
ok: true,
|
|
303
492
|
severity: 'warn',
|
|
304
|
-
detail:
|
|
493
|
+
detail: `marketing routes check skipped by ${OPT_OUT_REL}: ${reason}`,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
if (fs.existsSync(optOutAbs)) {
|
|
497
|
+
return {
|
|
498
|
+
ok: false,
|
|
499
|
+
severity: 'error',
|
|
500
|
+
detail: `${OPT_OUT_REL} exists beside ${CONFIG_REL}: delete the opt-out, the repo is migrated`,
|
|
305
501
|
};
|
|
306
502
|
}
|
|
307
503
|
let allowed;
|
|
@@ -312,34 +508,55 @@ export function checkMarketingRoutes(appRoot) {
|
|
|
312
508
|
return { ok: false, severity: 'error', detail: message };
|
|
313
509
|
}
|
|
314
510
|
let handWritten;
|
|
511
|
+
let warnings;
|
|
315
512
|
try {
|
|
316
513
|
handWritten = handWrittenAllowlist(config);
|
|
514
|
+
warnings = parseAllowlist(config).warnings;
|
|
317
515
|
} catch (error) {
|
|
318
516
|
const message = error instanceof Error ? error.message : String(error);
|
|
319
517
|
return { ok: false, severity: 'error', detail: message };
|
|
320
518
|
}
|
|
321
519
|
const found = listMarketingPages(appRoot);
|
|
322
520
|
const extras = found.pages.filter((rest) => !allowed.has(rest) && !isAllowlisted(handWritten, rest));
|
|
521
|
+
const outside = found.outside.filter((rel) => !isAllowlisted(handWritten, appRestFromRel(rel)));
|
|
522
|
+
const handlers = listRouteHandlers(appRoot);
|
|
523
|
+
const allowedShapes = new Set([...allowed].map(restShape));
|
|
524
|
+
const handlerProblems = [
|
|
525
|
+
...handlers.inside.filter((rel) => {
|
|
526
|
+
const rest = routeRestFromRel(rel.replace(/\/route\.tsx?$/, '/page.ts')) ?? '';
|
|
527
|
+
return !isAllowlisted(handWritten, rest);
|
|
528
|
+
}),
|
|
529
|
+
...handlers.outside
|
|
530
|
+
.filter(
|
|
531
|
+
(item) =>
|
|
532
|
+
allowedShapes.has(restShape(item.rest)) && !isAllowlisted(handWritten, item.rest),
|
|
533
|
+
)
|
|
534
|
+
.map((item) => item.rel),
|
|
535
|
+
];
|
|
323
536
|
const drift = generatedDrift(appRoot, config);
|
|
324
537
|
/** @type {string[]} */
|
|
325
538
|
const problems = [
|
|
326
|
-
...
|
|
539
|
+
...outside,
|
|
327
540
|
...extras.map((rest) => `(cms-routes)/${rest ? `${rest}/` : ''}page`),
|
|
541
|
+
...handlerProblems,
|
|
328
542
|
...drift,
|
|
329
543
|
...supportDrift(appRoot, config),
|
|
330
544
|
...policyProblems(appRoot, allowed),
|
|
331
545
|
...proxyMarkdownProblems(appRoot),
|
|
332
546
|
];
|
|
547
|
+
const note = warnings.length > 0 ? ` [warning: ${warnings.join('; ')}]` : '';
|
|
333
548
|
if (problems.length > 0) {
|
|
334
549
|
return {
|
|
335
550
|
ok: false,
|
|
336
551
|
severity: 'error',
|
|
337
|
-
detail: `page files outside marketing-routes.json: ${problems.join('; ')}`,
|
|
552
|
+
detail: `page files outside marketing-routes.json: ${problems.join('; ')}${note}`,
|
|
553
|
+
warnings,
|
|
338
554
|
};
|
|
339
555
|
}
|
|
340
556
|
return {
|
|
341
557
|
ok: true,
|
|
342
|
-
detail: `${found.pages.length} cms page files match marketing-routes.json`,
|
|
558
|
+
detail: `${found.pages.length} cms page files match marketing-routes.json${note}`,
|
|
559
|
+
warnings,
|
|
343
560
|
};
|
|
344
561
|
}
|
|
345
562
|
|
|
@@ -454,7 +671,7 @@ function slugList(values) {
|
|
|
454
671
|
|
|
455
672
|
/**
|
|
456
673
|
* @param {Record<string, unknown>} config
|
|
457
|
-
* @returns {{ slug: string, indexPath: string, articlePath: string }[]}
|
|
674
|
+
* @returns {{ slug: string, indexPath: string, articlePath: string, detailPages?: false }[]}
|
|
458
675
|
*/
|
|
459
676
|
function articleRouteRecords(config) {
|
|
460
677
|
const articles = typeof config.articlesSlug === 'string' ? config.articlesSlug : '';
|
|
@@ -470,7 +687,12 @@ function articleRouteRecords(config) {
|
|
|
470
687
|
}
|
|
471
688
|
const indexPath = `/${underPrefix(articles, route.indexSlug)}/`;
|
|
472
689
|
const articlePath = `/${underPrefix(articles, route.slug)}/`;
|
|
473
|
-
return {
|
|
690
|
+
return {
|
|
691
|
+
slug: route.slug,
|
|
692
|
+
indexPath,
|
|
693
|
+
articlePath,
|
|
694
|
+
...(route.detailPages ? {} : { detailPages: false }),
|
|
695
|
+
};
|
|
474
696
|
});
|
|
475
697
|
}
|
|
476
698
|
|
|
@@ -492,10 +714,26 @@ export function renderMarketingSlugs(config) {
|
|
|
492
714
|
: `[\n${routes
|
|
493
715
|
.map(
|
|
494
716
|
(route) =>
|
|
495
|
-
` { slug: '${route.slug}', indexPath: '${route.indexPath}', articlePath: '${route.articlePath}' },`,
|
|
717
|
+
` { slug: '${route.slug}', indexPath: '${route.indexPath}', articlePath: '${route.articlePath}'${route.detailPages === false ? ', detailPages: false' : ''} },`,
|
|
496
718
|
)
|
|
497
719
|
.join('\n')}\n] as const`;
|
|
498
720
|
const base = (slug) => (slug ? `'/${slug}'` : "''");
|
|
721
|
+
const indexOnly = routes.some((route) => route.detailPages === false);
|
|
722
|
+
const detailSlugLine = indexOnly
|
|
723
|
+
? `/** Article types that have /{type}/{article}/ pages. Sitemap sources use this, not ARTICLE_TYPE_SLUGS. */
|
|
724
|
+
export const ARTICLE_DETAIL_TYPE_SLUGS = ${slugList(
|
|
725
|
+
routes.filter((route) => route.detailPages !== false).map((route) => route.slug),
|
|
726
|
+
)};
|
|
727
|
+
`
|
|
728
|
+
: '';
|
|
729
|
+
const shape = sectionShape(config);
|
|
730
|
+
const detailLines = shape.declared
|
|
731
|
+
? `export const PERSON_DETAIL_SLUG = '${shape.personBase}';
|
|
732
|
+
export const PERSON_DETAIL_BASE = ${base(shape.personBase)};
|
|
733
|
+
export const TAG_DETAIL_SLUG = '${shape.tagBase}';
|
|
734
|
+
export const TAG_DETAIL_BASE = ${base(shape.tagBase)};
|
|
735
|
+
`
|
|
736
|
+
: '';
|
|
499
737
|
return `${header()}
|
|
500
738
|
export const PEOPLE_SLUG = '${people}';
|
|
501
739
|
export const PEOPLE_BASE = ${base(people)};
|
|
@@ -503,10 +741,10 @@ export const TAGS_SLUG = '${tags}';
|
|
|
503
741
|
export const TAGS_BASE = ${base(tags)};
|
|
504
742
|
export const ARTICLES_SLUG = '${articles}';
|
|
505
743
|
export const ARTICLES_BASE = ${base(articles)};
|
|
506
|
-
export const PERSON_TYPE_SLUGS = ${slugList(personTypes)};
|
|
744
|
+
${detailLines}export const PERSON_TYPE_SLUGS = ${slugList(personTypes)};
|
|
507
745
|
export const TAG_TYPE_SLUGS = ${slugList(tagTypes)};
|
|
508
746
|
export const ARTICLE_TYPE_SLUGS = ${slugList(articleSlugs)};
|
|
509
|
-
export const ARTICLE_TYPE_ROUTES = ${routeLiteral};
|
|
747
|
+
${detailSlugLine}export const ARTICLE_TYPE_ROUTES = ${routeLiteral};
|
|
510
748
|
`;
|
|
511
749
|
}
|
|
512
750
|
|
|
@@ -838,17 +1076,23 @@ export function mustBeSsgOrStaticRoutes(config) {
|
|
|
838
1076
|
} else if (Array.isArray(config.articleTypes)) {
|
|
839
1077
|
for (const type of config.articleTypes) {
|
|
840
1078
|
const route = articleTypeRoute(type, config);
|
|
841
|
-
|
|
1079
|
+
const detail = articleDetailRest(underPrefix(articles, route.slug), route);
|
|
1080
|
+
if (detail) {
|
|
1081
|
+
push(detail);
|
|
1082
|
+
}
|
|
842
1083
|
}
|
|
843
1084
|
}
|
|
844
|
-
|
|
845
|
-
|
|
1085
|
+
const shape = isSectionConfig(config) ? sectionShape(config) : null;
|
|
1086
|
+
const personBase = shape ? shape.personBase : people;
|
|
1087
|
+
const tagBase = shape ? shape.tagBase : tags;
|
|
1088
|
+
if (personBase) {
|
|
1089
|
+
push(`${personBase}/[person]`);
|
|
846
1090
|
}
|
|
847
1091
|
for (const type of config.personTypes ?? []) {
|
|
848
1092
|
push(`${underPrefix(people, String(type))}/[person]`);
|
|
849
1093
|
}
|
|
850
|
-
if (
|
|
851
|
-
push(`${
|
|
1094
|
+
if (tagBase) {
|
|
1095
|
+
push(`${tagBase}/[tag]`);
|
|
852
1096
|
}
|
|
853
1097
|
for (const type of config.tagTypes ?? []) {
|
|
854
1098
|
push(`${underPrefix(tags, String(type))}/[tag]`);
|
|
@@ -1055,9 +1299,15 @@ function categoryPath(config) {
|
|
|
1055
1299
|
}
|
|
1056
1300
|
|
|
1057
1301
|
/**
|
|
1302
|
+
* Per-type options (object form of `articleTypes`):
|
|
1303
|
+
* - `detailPages: false` — index only. The index is served at `indexSlug`; no
|
|
1304
|
+
* `/{slug}/{article}/` or `/{indexSlug}/{article}/` page is generated.
|
|
1305
|
+
* - `nestedSlugs: true` — detail pages are `/{slug}/[...slugs]` (an article slug
|
|
1306
|
+
* such as `acme/launch`) instead of the single segment `/{slug}/[article]`.
|
|
1307
|
+
*
|
|
1058
1308
|
* @param {unknown} type
|
|
1059
1309
|
* @param {Record<string, unknown>} [config]
|
|
1060
|
-
* @returns {{ slug: string, indexSlug: string }}
|
|
1310
|
+
* @returns {{ slug: string, indexSlug: string, detailPages: boolean, nestedSlugs: boolean }}
|
|
1061
1311
|
*/
|
|
1062
1312
|
function articleTypeRoute(type, config = {}) {
|
|
1063
1313
|
const category = categoryPath(config);
|
|
@@ -1065,7 +1315,7 @@ function articleTypeRoute(type, config = {}) {
|
|
|
1065
1315
|
const slug = category
|
|
1066
1316
|
? requireRoutePath(type, 'articleTypes')
|
|
1067
1317
|
: requireSegment(type, 'articleTypes');
|
|
1068
|
-
return { slug, indexSlug: slug };
|
|
1318
|
+
return { slug, indexSlug: slug, detailPages: true, nestedSlugs: false };
|
|
1069
1319
|
}
|
|
1070
1320
|
const slug = category
|
|
1071
1321
|
? requireRoutePath(type?.slug, 'articleTypes.slug')
|
|
@@ -1077,12 +1327,49 @@ function articleTypeRoute(type, config = {}) {
|
|
|
1077
1327
|
`${slug} indexSlug must equal the article type slug when the category is in the path`,
|
|
1078
1328
|
);
|
|
1079
1329
|
}
|
|
1330
|
+
/**
|
|
1331
|
+
* @param {string} key
|
|
1332
|
+
*/
|
|
1333
|
+
const optional = (key) => {
|
|
1334
|
+
const value = type?.[key];
|
|
1335
|
+
if (value !== undefined && typeof value !== 'boolean') {
|
|
1336
|
+
throw new Error(`articleTypes.${key} for "${slug}" must be a boolean`);
|
|
1337
|
+
}
|
|
1338
|
+
return value;
|
|
1339
|
+
};
|
|
1340
|
+
const detailPages = optional('detailPages') !== false;
|
|
1341
|
+
const nestedSlugs = optional('nestedSlugs') === true;
|
|
1342
|
+
if ((category || config.tagInPath === true) && (!detailPages || nestedSlugs)) {
|
|
1343
|
+
throw new Error(
|
|
1344
|
+
`articleTypes "${slug}": detailPages and nestedSlugs are not supported with tagInPath`,
|
|
1345
|
+
);
|
|
1346
|
+
}
|
|
1347
|
+
if (!detailPages && nestedSlugs) {
|
|
1348
|
+
throw new Error(`articleTypes "${slug}": nestedSlugs has no effect with detailPages: false`);
|
|
1349
|
+
}
|
|
1080
1350
|
return {
|
|
1081
1351
|
slug,
|
|
1082
1352
|
indexSlug: category ? slug : requireSegment(rawIndex, 'articleTypes.indexSlug'),
|
|
1353
|
+
detailPages,
|
|
1354
|
+
nestedSlugs,
|
|
1083
1355
|
};
|
|
1084
1356
|
}
|
|
1085
1357
|
|
|
1358
|
+
/**
|
|
1359
|
+
* The detail route of a plain article type, with the real param name
|
|
1360
|
+
* (`[article]` or `[...slugs]`), or null for an index-only type.
|
|
1361
|
+
*
|
|
1362
|
+
* @param {string} articleRest `{articles}/{slug}`
|
|
1363
|
+
* @param {{ detailPages: boolean, nestedSlugs: boolean }} route
|
|
1364
|
+
* @returns {string | null}
|
|
1365
|
+
*/
|
|
1366
|
+
export function articleDetailRest(articleRest, route) {
|
|
1367
|
+
if (!route.detailPages) {
|
|
1368
|
+
return null;
|
|
1369
|
+
}
|
|
1370
|
+
return `${articleRest}/${route.nestedSlugs ? '[...slugs]' : '[article]'}`;
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1086
1373
|
/**
|
|
1087
1374
|
* @param {string} prefix
|
|
1088
1375
|
* @param {string} segment
|
|
@@ -1095,9 +1382,12 @@ function addSectionRests(allowed, config) {
|
|
|
1095
1382
|
const people = typeof config.peopleSlug === 'string' ? config.peopleSlug : '';
|
|
1096
1383
|
const tags = typeof config.tagsSlug === 'string' ? config.tagsSlug : '';
|
|
1097
1384
|
const articles = typeof config.articlesSlug === 'string' ? config.articlesSlug : '';
|
|
1098
|
-
|
|
1385
|
+
const shape = sectionShape(config);
|
|
1386
|
+
if (shape.peopleIndex) {
|
|
1099
1387
|
allowed.add(people);
|
|
1100
|
-
|
|
1388
|
+
}
|
|
1389
|
+
if (shape.personBase) {
|
|
1390
|
+
allowed.add(`${shape.personBase}/[person]`);
|
|
1101
1391
|
}
|
|
1102
1392
|
for (const type of config.personTypes ?? []) {
|
|
1103
1393
|
const segment = requireSegment(type, 'personTypes');
|
|
@@ -1105,9 +1395,11 @@ function addSectionRests(allowed, config) {
|
|
|
1105
1395
|
allowed.add(rest);
|
|
1106
1396
|
allowed.add(`${rest}/[person]`);
|
|
1107
1397
|
}
|
|
1108
|
-
if (
|
|
1398
|
+
if (shape.tagsIndex) {
|
|
1109
1399
|
allowed.add(tags);
|
|
1110
|
-
|
|
1400
|
+
}
|
|
1401
|
+
if (shape.tagBase) {
|
|
1402
|
+
allowed.add(`${shape.tagBase}/[tag]`);
|
|
1111
1403
|
}
|
|
1112
1404
|
for (const type of config.tagTypes ?? []) {
|
|
1113
1405
|
const segment = requireSegment(type, 'tagTypes');
|
|
@@ -1143,7 +1435,10 @@ function addSectionRests(allowed, config) {
|
|
|
1143
1435
|
const indexRest = underPrefix(articles, route.indexSlug);
|
|
1144
1436
|
const articleRest = underPrefix(articles, route.slug);
|
|
1145
1437
|
allowed.add(indexRest);
|
|
1146
|
-
|
|
1438
|
+
const detail = articleDetailRest(articleRest, route);
|
|
1439
|
+
if (detail) {
|
|
1440
|
+
allowed.add(detail);
|
|
1441
|
+
}
|
|
1147
1442
|
}
|
|
1148
1443
|
}
|
|
1149
1444
|
|
|
@@ -1155,10 +1450,13 @@ function renderSectionRoutes(config, files) {
|
|
|
1155
1450
|
const people = typeof config.peopleSlug === 'string' ? config.peopleSlug : '';
|
|
1156
1451
|
const tags = typeof config.tagsSlug === 'string' ? config.tagsSlug : '';
|
|
1157
1452
|
const articles = typeof config.articlesSlug === 'string' ? config.articlesSlug : '';
|
|
1158
|
-
|
|
1453
|
+
const shape = sectionShape(config);
|
|
1454
|
+
if (shape.peopleIndex) {
|
|
1159
1455
|
const segment = requireSegment(people, 'peopleSlug');
|
|
1160
1456
|
files.set(segment, peopleIndexPage(segment));
|
|
1161
|
-
|
|
1457
|
+
}
|
|
1458
|
+
if (shape.personBase) {
|
|
1459
|
+
files.set(`${shape.personBase}/[person]`, untypedPersonPage(shape.personBase));
|
|
1162
1460
|
}
|
|
1163
1461
|
for (const type of config.personTypes ?? []) {
|
|
1164
1462
|
const segment = requireSegment(type, 'personTypes');
|
|
@@ -1166,10 +1464,12 @@ function renderSectionRoutes(config, files) {
|
|
|
1166
1464
|
files.set(rest, topPersonTypeIndex(rest, segment));
|
|
1167
1465
|
files.set(`${rest}/[person]`, topPersonTypePerson(rest, segment));
|
|
1168
1466
|
}
|
|
1169
|
-
if (
|
|
1467
|
+
if (shape.tagsIndex) {
|
|
1170
1468
|
const segment = requireSegment(tags, 'tagsSlug');
|
|
1171
1469
|
files.set(segment, sectionTagsIndex(segment));
|
|
1172
|
-
|
|
1470
|
+
}
|
|
1471
|
+
if (shape.tagBase) {
|
|
1472
|
+
files.set(`${shape.tagBase}/[tag]`, sectionTagPage(shape.tagBase, shape.declared));
|
|
1173
1473
|
}
|
|
1174
1474
|
for (const type of config.tagTypes ?? []) {
|
|
1175
1475
|
const segment = requireSegment(type, 'tagTypes');
|
|
@@ -1207,7 +1507,15 @@ function renderSectionRoutes(config, files) {
|
|
|
1207
1507
|
const indexRest = underPrefix(articles, route.indexSlug);
|
|
1208
1508
|
const articleRest = underPrefix(articles, route.slug);
|
|
1209
1509
|
files.set(indexRest, concreteArticleTypeIndex(indexRest, route.slug));
|
|
1210
|
-
|
|
1510
|
+
const detail = articleDetailRest(articleRest, route);
|
|
1511
|
+
if (detail) {
|
|
1512
|
+
files.set(
|
|
1513
|
+
detail,
|
|
1514
|
+
route.nestedSlugs
|
|
1515
|
+
? concreteNestedArticlePage(articleRest, route.slug)
|
|
1516
|
+
: concreteArticlePage(articleRest, route.slug),
|
|
1517
|
+
);
|
|
1518
|
+
}
|
|
1211
1519
|
}
|
|
1212
1520
|
}
|
|
1213
1521
|
|
|
@@ -1458,6 +1766,61 @@ ${page}
|
|
|
1458
1766
|
`;
|
|
1459
1767
|
}
|
|
1460
1768
|
|
|
1769
|
+
/**
|
|
1770
|
+
* Nested article slugs: `/{rest}/{client}/{case}/` as `[...slugs]`.
|
|
1771
|
+
*
|
|
1772
|
+
* @param {string} rest directory of the article, without `[...slugs]`
|
|
1773
|
+
* @param {string} typeSlug
|
|
1774
|
+
*/
|
|
1775
|
+
function concreteNestedArticlePage(rest, typeSlug) {
|
|
1776
|
+
const props = `PageProps<'/${rest}/[...slugs]'>`;
|
|
1777
|
+
const extract = openFn('async function extractDetails', [`props: ${props}`]);
|
|
1778
|
+
const metadata = openFn('export async function generateMetadata', [
|
|
1779
|
+
`props: ${props}`,
|
|
1780
|
+
'parent: ResolvingMetadata',
|
|
1781
|
+
]);
|
|
1782
|
+
const page = openFn('export default async function ', [`props: ${props}`]);
|
|
1783
|
+
return `${header()}import { joinCmsPathSegments } from '@se-studio/core-ui';
|
|
1784
|
+
import { notFoundIfImpossibleCmsSlug } from '@se-studio/core-ui/server';
|
|
1785
|
+
import type { ResolvingMetadata } from 'next';
|
|
1786
|
+
import { notFound } from 'next/navigation';
|
|
1787
|
+
import { generateArticleMetadata, generateArticlePage } from '@/lib/route-handlers';
|
|
1788
|
+
import { ARTICLE_DETAIL_ROUTE_CONFIG } from '@/lib/routeConfig';
|
|
1789
|
+
|
|
1790
|
+
const ARTICLE_TYPE = '${typeSlug}';
|
|
1791
|
+
|
|
1792
|
+
export function generateStaticParams() {
|
|
1793
|
+
return [];
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
${extract}
|
|
1797
|
+
const params = await props.params;
|
|
1798
|
+
const articleSlug = joinCmsPathSegments(params.slugs);
|
|
1799
|
+
if (!articleSlug) {
|
|
1800
|
+
notFound();
|
|
1801
|
+
}
|
|
1802
|
+
notFoundIfImpossibleCmsSlug(articleSlug);
|
|
1803
|
+
return { articleSlug, path: \`/${rest}/\${articleSlug}/\` };
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
${metadata}
|
|
1807
|
+
const { articleSlug, path } = await extractDetails(props);
|
|
1808
|
+
return await generateArticleMetadata(
|
|
1809
|
+
ARTICLE_TYPE,
|
|
1810
|
+
articleSlug,
|
|
1811
|
+
path,
|
|
1812
|
+
ARTICLE_DETAIL_ROUTE_CONFIG,
|
|
1813
|
+
parent,
|
|
1814
|
+
);
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
${page}
|
|
1818
|
+
const { articleSlug, path } = await extractDetails(props);
|
|
1819
|
+
return await generateArticlePage(ARTICLE_TYPE, articleSlug, path, ARTICLE_DETAIL_ROUTE_CONFIG);
|
|
1820
|
+
}
|
|
1821
|
+
`;
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1461
1824
|
/**
|
|
1462
1825
|
* @param {string} segment
|
|
1463
1826
|
*/
|
|
@@ -1488,9 +1851,14 @@ ${page}
|
|
|
1488
1851
|
}
|
|
1489
1852
|
|
|
1490
1853
|
/**
|
|
1854
|
+
* Tag detail page. A config that declares the URL shape passes the served path
|
|
1855
|
+
* as a literal, so the canonical cannot drift from the route. Without it the
|
|
1856
|
+
* path comes from the site's tag url calculator.
|
|
1857
|
+
*
|
|
1491
1858
|
* @param {string} segment
|
|
1859
|
+
* @param {boolean} [literalPath]
|
|
1492
1860
|
*/
|
|
1493
|
-
function sectionTagPage(segment) {
|
|
1861
|
+
function sectionTagPage(segment, literalPath = false) {
|
|
1494
1862
|
const props = `PageProps<'/${segment}/[tag]'>`;
|
|
1495
1863
|
const extract = openFn('async function extractDetails', [`props: ${props}`]);
|
|
1496
1864
|
const metadata = openFn('export async function generateMetadata', [
|
|
@@ -1498,9 +1866,14 @@ function sectionTagPage(segment) {
|
|
|
1498
1866
|
'parent: ResolvingMetadata',
|
|
1499
1867
|
]);
|
|
1500
1868
|
const page = openFn('export default async function ', [`props: ${props}`]);
|
|
1869
|
+
const calculatorImport = literalPath
|
|
1870
|
+
? ''
|
|
1871
|
+
: "import { converterContext } from '@/lib/converter-context';\n";
|
|
1872
|
+
const pathExpr = literalPath
|
|
1873
|
+
? `\`/${segment}/\${tag}/\``
|
|
1874
|
+
: 'converterContext.urlCalculators.tag(tag)';
|
|
1501
1875
|
return `${header()}import type { ResolvingMetadata } from 'next';
|
|
1502
|
-
import {
|
|
1503
|
-
import { generateTagMetadata, generateTagPage } from '@/lib/route-handlers';
|
|
1876
|
+
${calculatorImport}import { generateTagMetadata, generateTagPage } from '@/lib/route-handlers';
|
|
1504
1877
|
import { TAG_LISTING_ROUTE_CONFIG } from '@/lib/routeConfig';
|
|
1505
1878
|
|
|
1506
1879
|
export function generateStaticParams() {
|
|
@@ -1510,7 +1883,7 @@ export function generateStaticParams() {
|
|
|
1510
1883
|
${extract}
|
|
1511
1884
|
const params = await props.params;
|
|
1512
1885
|
const { tag } = params;
|
|
1513
|
-
return { tagSlug: tag, path:
|
|
1886
|
+
return { tagSlug: tag, path: ${pathExpr} };
|
|
1514
1887
|
}
|
|
1515
1888
|
|
|
1516
1889
|
${metadata}
|