create-ailk 0.39.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/dist/add-route.js +15 -0
  2. package/dist/body-heading.d.ts +2 -1
  3. package/dist/body-heading.js +31 -3
  4. package/dist/module-architecture.js +0 -3
  5. package/dist/remove-module.js +13 -4
  6. package/dist/routes.d.ts +7 -0
  7. package/dist/routes.js +1 -1
  8. package/dist/site-roster.js +7 -1
  9. package/dist/surfaces.d.ts +2 -0
  10. package/dist/surfaces.js +59 -172
  11. package/package.json +3 -3
  12. package/templates/apps/web/CLAUDE.md +7 -1
  13. package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +3 -2
  14. package/templates/apps/web/__tests__/__mocks__/next-intl.ts +3 -2
  15. package/templates/apps/web/app/[locale]/layout.tsx +1 -1
  16. package/templates/apps/web/i18n/request.ts +5 -1
  17. package/templates/apps/web/jest.config.cjs +6 -0
  18. package/templates/apps/web/lib/__tests__/deck-page.test.ts +9 -0
  19. package/templates/apps/web/lib/__tests__/in-page-magnet-self-request.test.ts +1 -1
  20. package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +2 -2
  21. package/templates/apps/web/lib/__tests__/pricing-page.test.ts +1 -1
  22. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +17 -4
  23. package/templates/apps/web/lib/in-page-magnet.ts +2 -2
  24. package/templates/apps/web/lib/pricing-page.ts +3 -3
  25. package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-email.ts +1 -1
  26. package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-lines.ts +1 -1
  27. package/templates/apps/web/lib/site-header.ts +1 -1
  28. package/templates/apps/web/messages/en.json +0 -119
  29. package/templates/apps/web/next.config.mjs +7 -0
  30. package/templates/apps/web/package.json +1 -0
  31. package/templates/apps/web/site-pages.config.tsx +85 -0
  32. package/templates/tools/body-heading.ts +30 -3
  33. package/versions.json +50 -49
  34. package/templates/apps/web/app/[locale]/(authed)/leads/__tests__/page.test.tsx +0 -205
  35. package/templates/apps/web/app/[locale]/(authed)/leads/components/LeadsTable.tsx +0 -137
  36. package/templates/apps/web/app/[locale]/(authed)/leads/page.tsx +0 -122
  37. package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ForbiddenState.tsx +0 -24
  38. package/templates/apps/web/app/[locale]/(authed)/waitlist/format.ts +0 -111
  39. package/templates/apps/web/app/[locale]/[slug]/[detail]/__tests__/page.test.tsx +0 -402
  40. package/templates/apps/web/app/[locale]/[slug]/[detail]/page.tsx +0 -143
  41. package/templates/apps/web/app/[locale]/[slug]/__tests__/page.test.tsx +0 -148
  42. package/templates/apps/web/app/[locale]/[slug]/page.tsx +0 -109
  43. package/templates/apps/web/app/[locale]/about/[slug]/page.tsx +0 -46
  44. package/templates/apps/web/app/[locale]/about/__tests__/about-routes.test.tsx +0 -353
  45. package/templates/apps/web/app/[locale]/about/page.tsx +0 -122
  46. package/templates/apps/web/app/[locale]/alternatives/__tests__/page.test.tsx +0 -161
  47. package/templates/apps/web/app/[locale]/alternatives/page.tsx +0 -112
  48. package/templates/apps/web/app/[locale]/careers/[slug]/[action]/page.tsx +0 -244
  49. package/templates/apps/web/app/[locale]/careers/[slug]/apply.actions.ts +0 -325
  50. package/templates/apps/web/app/[locale]/careers/[slug]/job-application-form.ts +0 -120
  51. package/templates/apps/web/app/[locale]/careers/[slug]/page.tsx +0 -73
  52. package/templates/apps/web/app/[locale]/careers/__tests__/apply.actions.test.ts +0 -497
  53. package/templates/apps/web/app/[locale]/careers/__tests__/careers-hub.test.tsx +0 -172
  54. package/templates/apps/web/app/[locale]/careers/__tests__/careers-set.test.tsx +0 -153
  55. package/templates/apps/web/app/[locale]/careers/__tests__/job-application-form.test.ts +0 -141
  56. package/templates/apps/web/app/[locale]/careers/__tests__/job-apply-page.test.tsx +0 -546
  57. package/templates/apps/web/app/[locale]/careers/__tests__/page-renderer-migration.test.tsx +0 -189
  58. package/templates/apps/web/app/[locale]/careers/page.tsx +0 -165
  59. package/templates/apps/web/app/[locale]/case-studies/[slug]/page.tsx +0 -49
  60. package/templates/apps/web/app/[locale]/case-studies/__tests__/hub-children.test.tsx +0 -65
  61. package/templates/apps/web/app/[locale]/case-studies/__tests__/page-renderer-migration.test.tsx +0 -125
  62. package/templates/apps/web/app/[locale]/case-studies/page.tsx +0 -49
  63. package/templates/apps/web/app/[locale]/clients/__tests__/page-renderer-migration.test.tsx +0 -85
  64. package/templates/apps/web/app/[locale]/clients/page.tsx +0 -47
  65. package/templates/apps/web/app/[locale]/contact/ConversationalIntakeWrapper.tsx +0 -249
  66. package/templates/apps/web/app/[locale]/contact/__tests__/ConversationalIntakeWrapper.test.tsx +0 -400
  67. package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-magnet.test.ts +0 -138
  68. package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-text.test.ts +0 -49
  69. package/templates/apps/web/app/[locale]/contact/__tests__/contact-magnet-page.test.tsx +0 -494
  70. package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +0 -1122
  71. package/templates/apps/web/app/[locale]/contact/__tests__/intake-analytics.test.ts +0 -51
  72. package/templates/apps/web/app/[locale]/contact/__tests__/page-renderer-migration.test.tsx +0 -319
  73. package/templates/apps/web/app/[locale]/contact/contact-form-magnet.ts +0 -77
  74. package/templates/apps/web/app/[locale]/contact/contact-form-text.ts +0 -52
  75. package/templates/apps/web/app/[locale]/contact/contact.actions.ts +0 -403
  76. package/templates/apps/web/app/[locale]/contact/intake-analytics.ts +0 -49
  77. package/templates/apps/web/app/[locale]/contact/intake-script.ts +0 -92
  78. package/templates/apps/web/app/[locale]/contact/page.tsx +0 -267
  79. package/templates/apps/web/app/[locale]/courses/[slug]/page.tsx +0 -50
  80. package/templates/apps/web/app/[locale]/courses/__tests__/hub-children.test.tsx +0 -32
  81. package/templates/apps/web/app/[locale]/courses/__tests__/page-renderer-migration.test.tsx +0 -123
  82. package/templates/apps/web/app/[locale]/courses/page.tsx +0 -49
  83. package/templates/apps/web/app/[locale]/events/[slug]/page.tsx +0 -57
  84. package/templates/apps/web/app/[locale]/events/__tests__/hub-children.test.tsx +0 -32
  85. package/templates/apps/web/app/[locale]/events/__tests__/page-renderer-migration.test.tsx +0 -164
  86. package/templates/apps/web/app/[locale]/events/__tests__/program-event.test.tsx +0 -120
  87. package/templates/apps/web/app/[locale]/events/page.tsx +0 -60
  88. package/templates/apps/web/app/[locale]/faq/page.tsx +0 -54
  89. package/templates/apps/web/app/[locale]/features/[slug]/page.tsx +0 -54
  90. package/templates/apps/web/app/[locale]/features/__tests__/hub-children.test.tsx +0 -32
  91. package/templates/apps/web/app/[locale]/features/page.tsx +0 -50
  92. package/templates/apps/web/app/[locale]/for/[slug]/page.tsx +0 -54
  93. package/templates/apps/web/app/[locale]/for/__tests__/hub-children.test.tsx +0 -32
  94. package/templates/apps/web/app/[locale]/for/__tests__/page-renderer-migration.test.tsx +0 -90
  95. package/templates/apps/web/app/[locale]/for/page.tsx +0 -51
  96. package/templates/apps/web/app/[locale]/glossary/page.tsx +0 -53
  97. package/templates/apps/web/app/[locale]/how-to/[slug]/page.tsx +0 -50
  98. package/templates/apps/web/app/[locale]/how-to/__tests__/page-renderer-migration.test.tsx +0 -78
  99. package/templates/apps/web/app/[locale]/how-to/page.tsx +0 -50
  100. package/templates/apps/web/app/[locale]/integrations/[slug]/page.tsx +0 -54
  101. package/templates/apps/web/app/[locale]/integrations/__tests__/hub-children.test.tsx +0 -38
  102. package/templates/apps/web/app/[locale]/integrations/__tests__/page-renderer-migration.test.tsx +0 -141
  103. package/templates/apps/web/app/[locale]/integrations/page.tsx +0 -49
  104. package/templates/apps/web/app/[locale]/launch-service/page.tsx +0 -44
  105. package/templates/apps/web/app/[locale]/newsletter/__tests__/page.test.tsx +0 -236
  106. package/templates/apps/web/app/[locale]/newsletter/page.tsx +0 -179
  107. package/templates/apps/web/app/[locale]/page.tsx +0 -147
  108. package/templates/apps/web/app/[locale]/partners/[slug]/page.tsx +0 -45
  109. package/templates/apps/web/app/[locale]/partners/__tests__/hub-children.test.tsx +0 -32
  110. package/templates/apps/web/app/[locale]/partners/__tests__/page-renderer-migration.test.tsx +0 -125
  111. package/templates/apps/web/app/[locale]/partners/page.tsx +0 -49
  112. package/templates/apps/web/app/[locale]/portfolio/[slug]/page.tsx +0 -46
  113. package/templates/apps/web/app/[locale]/portfolio/__tests__/hub-children.test.tsx +0 -38
  114. package/templates/apps/web/app/[locale]/portfolio/page.tsx +0 -50
  115. package/templates/apps/web/app/[locale]/pricing/[slug]/__tests__/page.test.tsx +0 -324
  116. package/templates/apps/web/app/[locale]/pricing/[slug]/page.tsx +0 -87
  117. package/templates/apps/web/app/[locale]/pricing/__tests__/__snapshots__/unconnected.test.tsx.snap +0 -7
  118. package/templates/apps/web/app/[locale]/pricing/__tests__/offerings.test.tsx +0 -605
  119. package/templates/apps/web/app/[locale]/pricing/__tests__/page.test.tsx +0 -219
  120. package/templates/apps/web/app/[locale]/pricing/__tests__/pricing-pages.test.tsx +0 -215
  121. package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +0 -282
  122. package/templates/apps/web/app/[locale]/pricing/page.tsx +0 -120
  123. package/templates/apps/web/app/[locale]/privacy/page.tsx +0 -40
  124. package/templates/apps/web/app/[locale]/products/[slug]/page.tsx +0 -50
  125. package/templates/apps/web/app/[locale]/products/__tests__/hub-children.test.tsx +0 -32
  126. package/templates/apps/web/app/[locale]/products/__tests__/page-renderer-migration.test.tsx +0 -141
  127. package/templates/apps/web/app/[locale]/products/page.tsx +0 -49
  128. package/templates/apps/web/app/[locale]/projects/[slug]/page.tsx +0 -37
  129. package/templates/apps/web/app/[locale]/projects/__tests__/hub-children.test.tsx +0 -32
  130. package/templates/apps/web/app/[locale]/projects/__tests__/page-renderer-migration.test.tsx +0 -157
  131. package/templates/apps/web/app/[locale]/projects/page.tsx +0 -49
  132. package/templates/apps/web/app/[locale]/purchase-policy/page.tsx +0 -49
  133. package/templates/apps/web/app/[locale]/resources/[slug]/page.tsx +0 -54
  134. package/templates/apps/web/app/[locale]/resources/__tests__/hub-children.test.tsx +0 -38
  135. package/templates/apps/web/app/[locale]/resources/__tests__/page-renderer-migration.test.tsx +0 -151
  136. package/templates/apps/web/app/[locale]/resources/page.tsx +0 -49
  137. package/templates/apps/web/app/[locale]/services/[slug]/[child]/page.tsx +0 -68
  138. package/templates/apps/web/app/[locale]/services/[slug]/page.tsx +0 -88
  139. package/templates/apps/web/app/[locale]/services/__tests__/hub-children.test.tsx +0 -158
  140. package/templates/apps/web/app/[locale]/services/__tests__/page-renderer-migration.test.tsx +0 -187
  141. package/templates/apps/web/app/[locale]/services/__tests__/service-detail-sections.test.tsx +0 -224
  142. package/templates/apps/web/app/[locale]/services/__tests__/service-families.test.tsx +0 -368
  143. package/templates/apps/web/app/[locale]/services/page.tsx +0 -71
  144. package/templates/apps/web/app/[locale]/software/[slug]/page.tsx +0 -49
  145. package/templates/apps/web/app/[locale]/software/__tests__/page-renderer-migration.test.tsx +0 -81
  146. package/templates/apps/web/app/[locale]/software/page.tsx +0 -49
  147. package/templates/apps/web/app/[locale]/team/[slug]/page.tsx +0 -45
  148. package/templates/apps/web/app/[locale]/team/__tests__/hub-children.test.tsx +0 -32
  149. package/templates/apps/web/app/[locale]/team/__tests__/team-routes.test.tsx +0 -161
  150. package/templates/apps/web/app/[locale]/team/page.tsx +0 -50
  151. package/templates/apps/web/app/[locale]/tech-articles/[slug]/page.tsx +0 -54
  152. package/templates/apps/web/app/[locale]/tech-articles/__tests__/page-renderer-migration.test.tsx +0 -82
  153. package/templates/apps/web/app/[locale]/tech-articles/page.tsx +0 -49
  154. package/templates/apps/web/app/[locale]/templates/[slug]/__tests__/page.test.tsx +0 -203
  155. package/templates/apps/web/app/[locale]/templates/[slug]/page.tsx +0 -81
  156. package/templates/apps/web/app/[locale]/templates/__tests__/page.test.tsx +0 -237
  157. package/templates/apps/web/app/[locale]/templates/page.tsx +0 -114
  158. package/templates/apps/web/app/[locale]/terms/page.tsx +0 -40
  159. package/templates/apps/web/app/[locale]/testimonials/__tests__/page-renderer-migration.test.tsx +0 -85
  160. package/templates/apps/web/app/[locale]/testimonials/page.tsx +0 -51
  161. package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/page.test.tsx +0 -136
  162. package/templates/apps/web/app/[locale]/thanks/[slug]/page.tsx +0 -39
  163. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +0 -226
  164. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +0 -217
  165. package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +0 -106
  166. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +0 -94
  167. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe.actions.ts +0 -55
  168. package/templates/apps/web/app/[locale]/vs/[slug]/__tests__/page.test.tsx +0 -100
  169. package/templates/apps/web/app/[locale]/vs/[slug]/page.tsx +0 -60
  170. package/templates/apps/web/app/[locale]/whitepapers/[slug]/page.tsx +0 -54
  171. package/templates/apps/web/app/[locale]/whitepapers/__tests__/page-renderer-migration.test.tsx +0 -82
  172. package/templates/apps/web/app/[locale]/whitepapers/page.tsx +0 -49
  173. package/templates/apps/web/app/[locale]/working-agreement/__tests__/page.test.tsx +0 -63
  174. package/templates/apps/web/app/[locale]/working-agreement/page.tsx +0 -41
  175. package/templates/apps/web/lib/__tests__/hub-children.fixtures.ts +0 -279
  176. package/templates/apps/web/lib/__tests__/route-family.test.ts +0 -57
  177. package/templates/apps/web/lib/__tests__/service-listing.test.ts +0 -111
  178. package/templates/apps/web/lib/__tests__/template-listing.test.ts +0 -158
  179. package/templates/apps/web/lib/hub-children.tsx +0 -351
  180. package/templates/apps/web/lib/meet-placeholder.ts +0 -5
  181. package/templates/apps/web/lib/posting-title.ts +0 -39
  182. package/templates/apps/web/lib/route-family.ts +0 -69
  183. package/templates/apps/web/lib/service-listing.ts +0 -89
  184. package/templates/apps/web/lib/template-listing.ts +0 -169
  185. package/templates/apps/web/src/lib/__tests__/lead-write.test.ts +0 -187
  186. package/templates/apps/web/src/lib/lead-write.ts +0 -90
  187. /package/templates/apps/web/{app/[locale]/contact → lib}/__tests__/site-contact-lines.test.ts +0 -0
@@ -1,351 +0,0 @@
1
- /**
2
- * Hub child cards (#10121) — the /alternatives (#6878 D9) and /templates
3
- * (#10051 D7) shape, shared by the content hubs that list one child page
4
- * type each (/for, /case-studies, /team, …).
5
- *
6
- * The hub adds a generated card per child page of its type that the hub's
7
- * own sections do not already link: into the authored card grid that already
8
- * lists its children when there is one, else as one new `items` section
9
- * before any trailing closing CTA (#7745 D4). `renderPage` builds the CollectionPage
10
- * ItemList JSON-LD from the same sections, so the visible cards and the
11
- * ItemList always list the same pages. A child the hub already links keeps
12
- * its hand-written card and gets no second one, so a hub whose MDX already
13
- * links every child renders exactly as before.
14
- *
15
- * A prose hub (`bodyMode: "mdx-body"`) never reaches renderPage's
16
- * SectionRenderer, so its generated section renders after the MDX body
17
- * through renderPage's `trailing` slot.
18
- *
19
- * Base tree: no paid import, no `oss: false`.
20
- */
21
- import type {
22
- getMdxSlugs as defaultGetMdxSlugs,
23
- getMdxSource as defaultGetMdxSource,
24
- getPageSections as defaultGetPageSections,
25
- renderPage,
26
- SchemaOrgType,
27
- } from "@working-theory/page-renderer";
28
- import {
29
- getMdxSlugs as loadMdxSlugs,
30
- getMdxSource as loadMdxSource,
31
- getPageSections as loadPageSections,
32
- } from "@working-theory/page-renderer";
33
- import { localeHref } from "@working-theory/ui";
34
- import { SectionRenderer } from "@working-theory/ui/sections";
35
- import { notFound, permanentRedirect } from "next/navigation";
36
-
37
- import {
38
- type DetailPage,
39
- insertBeforeClosingCtas,
40
- listDetailPages,
41
- } from "./route-family";
42
-
43
- type Section = Awaited<ReturnType<typeof defaultGetPageSections>>[number];
44
-
45
- /** One hub: its list page, its child type, and how its body renders. */
46
- export interface HubConfig {
47
- /** The list page type, e.g. `UseCasesList`. */
48
- listType: SchemaOrgType;
49
- /** The hub's slug, translations namespace and route segment, e.g. `for`. */
50
- slug: string;
51
- /** The child page type, e.g. `UseCase`. */
52
- childType: SchemaOrgType;
53
- /** The card link label. */
54
- linkLabel: string;
55
- /** The generated section's id. */
56
- sectionId: string;
57
- /**
58
- * The hub's existing body rule: `sections` always, `mdx-body` always, or
59
- * `composed` — sections when the frontmatter carries `sections[]`, the MDX
60
- * body otherwise.
61
- */
62
- body: "sections" | "mdx-body" | "composed";
63
- /** Which child pages the hub lists (default: all). */
64
- includeChild?: (page: DetailPage) => boolean;
65
- /**
66
- * One listed page's card (default: title, description and a link to
67
- * `/<slug>/<child>` labelled `linkLabel`).
68
- */
69
- card?: (page: DetailPage) => HubCard;
70
- /** A last pass over the hub's final sections (default: none). */
71
- mapSections?: (sections: Section[]) => Section[];
72
- }
73
-
74
- /** One generated card. */
75
- export interface HubCard {
76
- title: string;
77
- description?: string | undefined;
78
- link?: { label: string; href: string } | undefined;
79
- }
80
-
81
- /** A hub route's injectable loaders (tests pass their own). */
82
- export interface HubLoaders {
83
- getMdxSource?: typeof defaultGetMdxSource;
84
- getPageSections?: typeof defaultGetPageSections;
85
- getMdxSlugs?: typeof defaultGetMdxSlugs;
86
- }
87
-
88
- /**
89
- * A link's path for matching: an absolute http(s) URL's pathname, the query
90
- * and hash dropped, a leading `/` ensured and trailing `/`s trimmed.
91
- */
92
- function linkPath(href: string): string | null {
93
- let path = href.trim();
94
- if (/^https?:\/\//i.test(path)) {
95
- try {
96
- path = new URL(path).pathname;
97
- } catch {
98
- return null;
99
- }
100
- }
101
- path = path.split(/[?#]/)[0] ?? "";
102
- if (!path.startsWith("/")) path = `/${path}`;
103
- let end = path.length;
104
- while (end > 0 && path[end - 1] === "/") end -= 1;
105
- return path.slice(0, end);
106
- }
107
-
108
- /** A BCP-47-shaped first path segment: `en`, `pt-BR`, `zh-Hant`. */
109
- const LOCALE_SEGMENT = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})?$/;
110
-
111
- /** The path without one leading locale segment (`/en/for/a` → `/for/a`). */
112
- function withoutLocale(path: string): string {
113
- const end = path.indexOf("/", 1);
114
- if (end === -1) return path;
115
- return LOCALE_SEGMENT.test(path.slice(1, end)) ? path.slice(end) : path;
116
- }
117
-
118
- /** Whether a link path names `target`, with or without a locale prefix. */
119
- function linksTo(path: string, target: string): boolean {
120
- return path === target || withoutLocale(path) === target;
121
- }
122
-
123
- /**
124
- * Every link path an MDX body carries: markdown link targets and `href`
125
- * attributes, the forms a prose hub links its pages with.
126
- */
127
- export function bodyLinkPaths(body: string): string[] {
128
- const hrefs = [
129
- ...body.matchAll(/\]\(\s*<?([^)\s>]+)/g),
130
- ...body.matchAll(/\bhref\s*=\s*\{?\s*["']([^"']+)["']/g),
131
- ].map((match) => match[1] ?? "");
132
- return hrefs
133
- .map(linkPath)
134
- .filter((path): path is string => path !== null);
135
- }
136
-
137
- /**
138
- * Every link path the sections carry: any `href` or `url` string at any
139
- * depth, so an `items` card link, a `team` member's `url` and a CTA all count.
140
- */
141
- export function linkedPaths(sections: readonly unknown[]): string[] {
142
- const paths: string[] = [];
143
- const walk = (value: unknown): void => {
144
- if (Array.isArray(value)) {
145
- value.forEach(walk);
146
- return;
147
- }
148
- if (value === null || typeof value !== "object") return;
149
- for (const [key, child] of Object.entries(value)) {
150
- if ((key === "href" || key === "url") && typeof child === "string") {
151
- const path = linkPath(child);
152
- if (path !== null) paths.push(path);
153
- } else {
154
- walk(child);
155
- }
156
- }
157
- };
158
- walk(sections);
159
- return paths;
160
- }
161
-
162
- /**
163
- * The generated section: one card per child page the hub's rendered content
164
- * does not already link (`linked`, from `linkedPaths` or `bodyLinkPaths`; a
165
- * locale prefix or an absolute URL still counts as a link), or `null` when
166
- * there is none.
167
- */
168
- export function childCardsSection(
169
- linked: readonly string[],
170
- pages: readonly DetailPage[],
171
- config: Pick<HubConfig, "slug" | "linkLabel" | "sectionId" | "card">,
172
- ): Section | null {
173
- // A child counts as linked at its route path or at its card's own href (a
174
- // hub whose public base differs from its route, #10043).
175
- const items = pages.flatMap((page) => {
176
- const card = config.card?.(page) ?? defaultCard(page, config);
177
- const targets = [`/${config.slug}/${page.slug}`];
178
- if (card.link !== undefined) targets.push(card.link.href);
179
- const linkedAlready = linked.some((path) =>
180
- targets.some((t) => linksTo(path, t)),
181
- );
182
- return linkedAlready ? [] : [card];
183
- });
184
- if (items.length === 0) return null;
185
- return { type: "items", id: config.sectionId, data: { items } } as Section;
186
- }
187
-
188
- function defaultCard(
189
- { slug, frontmatter }: DetailPage,
190
- config: Pick<HubConfig, "slug" | "linkLabel">,
191
- ): HubCard {
192
- const fm = frontmatter as { title?: string; description?: string };
193
- return {
194
- title: fm.title ?? slug,
195
- description: fm.description ?? "",
196
- link: { label: config.linkLabel, href: `/${config.slug}/${slug}` },
197
- };
198
- }
199
-
200
- type CardItem = { link?: { href?: string; variant?: string } };
201
-
202
- /**
203
- * Place the generated cards. When an authored `items` section already lists
204
- * children of this hub (a card linking `/<hub>/…`), the cards continue that
205
- * grid, taking its card link variant, so the hub shows one list. Otherwise
206
- * the generated section goes before the closing CTAs (#7745 D4).
207
- */
208
- export function placeChildCards(
209
- declared: Section[],
210
- generated: Section,
211
- hubSlug: string,
212
- ): Section[] {
213
- const prefix = `/${hubSlug}/`;
214
- const listsChildren = (section: Section): boolean =>
215
- section.type === "items" &&
216
- ((section.data as { items?: CardItem[] }).items ?? []).some((item) => {
217
- const href = item.link?.href;
218
- const path = href === undefined ? null : linkPath(href);
219
- // Raw first: a short hub slug (`for`) itself looks like a locale.
220
- return (
221
- path !== null &&
222
- (path.startsWith(prefix) || withoutLocale(path).startsWith(prefix))
223
- );
224
- });
225
- let at = declared.length - 1;
226
- while (at >= 0 && !listsChildren(declared[at] as Section)) at -= 1;
227
- if (at === -1) return insertBeforeClosingCtas(declared, generated);
228
-
229
- const host = declared[at] as Section & { data: { items: CardItem[] } };
230
- const variant = host.data.items.find((item) => item.link?.variant)?.link
231
- ?.variant;
232
- const added = (generated.data as { items: CardItem[] }).items.map((item) =>
233
- variant === undefined ? item : { ...item, link: { ...item.link, variant } },
234
- );
235
- const merged = {
236
- ...host,
237
- data: { ...host.data, items: [...host.data.items, ...added] },
238
- } as Section;
239
- return [...declared.slice(0, at), merged, ...declared.slice(at + 1)];
240
- }
241
-
242
- function hasSections(frontmatter: unknown): boolean {
243
- const sections = (frontmatter as { sections?: unknown }).sections;
244
- return Array.isArray(sections) && sections.length > 0;
245
- }
246
-
247
- /**
248
- * Nav only (#10200): a list that is a heading in the site navigation with no
249
- * page of its own answers a permanent redirect to its first child — in the
250
- * route's own child order — and 404 when it lists none. Any other page
251
- * returns, and renders as before.
252
- */
253
- export function honourNavOnly(
254
- frontmatter: unknown,
255
- locale: string,
256
- childHrefs: readonly string[],
257
- ): void {
258
- if ((frontmatter as { navOnly?: unknown } | undefined)?.navOnly !== true)
259
- return;
260
- const first = childHrefs[0];
261
- if (first === undefined) notFound();
262
- permanentRedirect(
263
- localeHref(locale, first, process.env.NEXT_PUBLIC_DEFAULT_LOCALE ?? "en"),
264
- );
265
- }
266
-
267
- type RenderPageInput = Parameters<typeof renderPage>[0];
268
-
269
- /**
270
- * Everything a hub's `renderPage` call needs beyond its literal `type` and
271
- * `slug`, which stay written out in each page.tsx where the content-render
272
- * lint reads them.
273
- */
274
- export async function hubPageInput(
275
- config: HubConfig,
276
- locale: string,
277
- loaders: HubLoaders,
278
- ): Promise<Omit<RenderPageInput, "type" | "slug">> {
279
- const load = loaders.getMdxSource ?? loadMdxSource;
280
- const base = {
281
- locale,
282
- translationsNamespace: config.slug,
283
- ...(loaders.getMdxSource !== undefined && {
284
- getMdxSource: loaders.getMdxSource,
285
- }),
286
- };
287
-
288
- const source = await load(config.listType, config.slug, locale);
289
- const mdxBody =
290
- config.body === "mdx-body" ||
291
- (config.body === "composed" &&
292
- (source === null || !hasSections(source.frontmatter)));
293
- if (source === null) {
294
- // The hub's existing empty-state rule, unchanged.
295
- return {
296
- ...base,
297
- ...(mdxBody && { bodyMode: "mdx-body" as const }),
298
- ...(loaders.getPageSections !== undefined && {
299
- getPageSections: loaders.getPageSections,
300
- }),
301
- };
302
- }
303
-
304
- const listed = await listDetailPages(
305
- config.childType,
306
- locale,
307
- load,
308
- loaders.getMdxSlugs ?? loadMdxSlugs,
309
- );
310
- const pages = config.includeChild
311
- ? listed.filter(config.includeChild)
312
- : listed;
313
- honourNavOnly(
314
- source.frontmatter,
315
- locale,
316
- pages.flatMap((page) => {
317
- const card = config.card?.(page) ?? defaultCard(page, config);
318
- return card.link === undefined ? [] : [card.link.href];
319
- }),
320
- );
321
- const loadSections = loaders.getPageSections ?? loadPageSections;
322
- const declared = await loadSections(source.frontmatter);
323
- // A prose hub renders its MDX body, never its declared sections, so its
324
- // existing links are read from the body and its cards stand alone after it.
325
- const linked = mdxBody
326
- ? bodyLinkPaths(source.body)
327
- : linkedPaths(declared);
328
- const generated = childCardsSection(linked, pages, config);
329
- // #10929 D3 — the loader builds from the frontmatter renderPage hands it,
330
- // which under the database adapter carries the published words; the child
331
- // pages and their card section are computed once, above.
332
- const place = (sections: typeof declared) => {
333
- const placed =
334
- generated === null
335
- ? sections
336
- : mdxBody
337
- ? insertBeforeClosingCtas(sections, generated)
338
- : placeChildCards(sections, generated, config.slug);
339
- return config.mapSections ? config.mapSections(placed) : placed;
340
- };
341
-
342
- return {
343
- ...base,
344
- getPageSections: async (frontmatter) => place(await loadSections(frontmatter)),
345
- ...(mdxBody && { bodyMode: "mdx-body" as const }),
346
- ...(mdxBody &&
347
- generated !== null && {
348
- trailing: <SectionRenderer sections={[generated]} locale={locale} />,
349
- }),
350
- };
351
- }
@@ -1,5 +0,0 @@
1
- // The Free `/meet/<slug>` placeholder hub (#6897 D2). `MEET_PLACEHOLDER_HUB`
2
- // is the one fixed top-level slug the `[slug]/[detail]` route answers under —
3
- // never a copied literal, so the route and the structured-data walk
4
- // (`apps/web/lib/__tests__/structured-data.test.tsx`) can never drift.
5
- export const MEET_PLACEHOLDER_HUB = "meet";
@@ -1,39 +0,0 @@
1
- /**
2
- * The posting a `/careers/<slug>/apply` page applies to, read by its title
3
- * (#8840 D11). The read sits here, not in a page, so the structured-data walk
4
- * does not take an apply page for a JobPosting page: the posting's own JSON-LD
5
- * is `/careers/<slug>`'s. In `lib/` (#8849 D9), not a route directory, so
6
- * every scaffold carries it: the `signal-collectors` walk and the Free apply
7
- * page (`careers/[slug]/[action]`) both read it.
8
- *
9
- * #10054 D2 — both pages read the posting through `postingForApply`, which
10
- * also returns the magnet the posting names (`applicationFlow`, checked as a
11
- * flow slug by the frontmatter schema); one read serves both.
12
- */
13
- import { getMdxSource } from "@working-theory/page-renderer";
14
-
15
- /** What an apply page needs from its posting. */
16
- export interface ApplyPosting {
17
- title: string;
18
- /** The magnet this posting's apply page runs; absent, the Job application. */
19
- applicationFlow?: string;
20
- }
21
-
22
- /** The posting in `locale`, or `null` when no posting has this slug or it has no title. */
23
- export async function postingForApply(slug: string, locale: string): Promise<ApplyPosting | null> {
24
- const source = await getMdxSource("JobPosting", slug, locale);
25
- if (source === null) return null;
26
- const { title, applicationFlow } = source.frontmatter as {
27
- title?: unknown;
28
- applicationFlow?: unknown;
29
- };
30
- if (typeof title !== "string" || title.trim() === "") return null;
31
- return typeof applicationFlow === "string" && applicationFlow !== ""
32
- ? { title, applicationFlow }
33
- : { title };
34
- }
35
-
36
- /** The posting's title in `locale`, or `null` when no posting has this slug. */
37
- export async function postingTitle(slug: string, locale: string): Promise<string | null> {
38
- return (await postingForApply(slug, locale))?.title ?? null;
39
- }
@@ -1,69 +0,0 @@
1
- /**
2
- * The route-family helper (#10051 D5) — the generic half of a content hub
3
- * that lists its detail pages automatically: read every detail page of one
4
- * type, and slot a generated section in before the page's closing CTAs.
5
- *
6
- * The /templates hub (#10051) is its first caller. It is shaped for the next
7
- * two: #10043 (a services category page listing its child `Service` pages)
8
- * and #10044 (a pricing hub listing its offering `Pricing` pages). The
9
- * /alternatives and /reports routes keep their own local copies (#10051
10
- * § Out of scope).
11
- *
12
- * Base tree: no paid import, no `oss: false`.
13
- */
14
- import {
15
- getMdxSlugs,
16
- getMdxSource,
17
- type getPageSections,
18
- type SchemaOrgType,
19
- } from "@working-theory/page-renderer";
20
-
21
- type Section = Awaited<ReturnType<typeof getPageSections>>[number];
22
-
23
- /** One detail page as a hub lists it: its slug and raw frontmatter. */
24
- export interface DetailPage {
25
- slug: string;
26
- frontmatter: Record<string, unknown>;
27
- }
28
-
29
- /**
30
- * Every detail page of `type` for `locale`, loaded through `load` (the
31
- * content adapter by default), a slug whose load is `null` dropped, sorted
32
- * by slug so the list is stable. `listSlugs` defaults to the content adapter
33
- * too; a route passes its own to stay injectable in tests.
34
- */
35
- export async function listDetailPages(
36
- type: SchemaOrgType,
37
- locale: string,
38
- load: typeof getMdxSource = getMdxSource,
39
- listSlugs: typeof getMdxSlugs = getMdxSlugs,
40
- ): Promise<DetailPage[]> {
41
- const slugs = await listSlugs(type, locale);
42
- const pages = await Promise.all(
43
- slugs.map(async (slug): Promise<DetailPage | null> => {
44
- const source = await load(type, slug, locale);
45
- if (source === null) return null;
46
- return {
47
- slug,
48
- frontmatter: source.frontmatter as Record<string, unknown>,
49
- };
50
- }),
51
- );
52
- return pages
53
- .filter((page): page is DetailPage => page !== null)
54
- .sort((a, b) => a.slug.localeCompare(b.slug));
55
- }
56
-
57
- /**
58
- * Insert `section` before the trailing run of `cta` sections — the page's
59
- * closing call to action stays last — or append it when the page does not end
60
- * in a CTA (the /reports rule, #7745 D4).
61
- */
62
- export function insertBeforeClosingCtas(
63
- sections: Section[],
64
- section: Section,
65
- ): Section[] {
66
- let at = sections.length;
67
- while (at > 0 && sections[at - 1]?.type === "cta") at -= 1;
68
- return [...sections.slice(0, at), section, ...sections.slice(at)];
69
- }
@@ -1,89 +0,0 @@
1
- /**
2
- * The services listing (#10043 D8) — a service's public URL under the site's
3
- * services base and its category, the list a category page shows of its
4
- * services, and the hub's own section links re-pointed onto the base. Pure,
5
- * no I/O: the routes load the pages and the translated labels and pass them
6
- * in, so no user-facing copy lives here (customer-facing-i18n, ADR 0019).
7
- *
8
- * Base tree: no paid import, no `oss: false`.
9
- */
10
- import { pagePath } from "@working-theory/templates/routes";
11
- import type { PageSection } from "@working-theory/validation";
12
-
13
- import type { DetailPage } from "./route-family";
14
- import {
15
- SERVICES_PATH,
16
- SERVICES_ROUTE,
17
- toPublicServicesHref,
18
- } from "./services-path";
19
-
20
- type ItemsSection = Extract<PageSection, { type: "items" }>;
21
-
22
- /** The `services` messages namespace labels a category's list reads (#10043 D11). */
23
- export interface ServiceListingLabels {
24
- childrenHeading: string;
25
- viewService: string;
26
- }
27
-
28
- /** A service's public path: `<base>[/<category>]/<slug>`. */
29
- export function servicePublicPath(slug: string, parent?: string): string {
30
- return pagePath({ type: "Service", slug, parent }, SERVICES_PATH);
31
- }
32
-
33
- /** The services whose `parent` is `category`, from a slug-sorted page list. */
34
- export function childServices(
35
- pages: DetailPage[],
36
- category: string,
37
- ): DetailPage[] {
38
- return pages.filter((page) => page.frontmatter.parent === category);
39
- }
40
-
41
- /** The list a category page renders after its body: one card per child service. */
42
- export function serviceChildrenSection(
43
- children: DetailPage[],
44
- labels: ServiceListingLabels,
45
- ): ItemsSection {
46
- const text = (value: unknown): string | undefined =>
47
- typeof value === "string" && value.length > 0 ? value : undefined;
48
- return {
49
- type: "items",
50
- id: "service-children",
51
- data: {
52
- headline: labels.childrenHeading,
53
- items: children.map((child) => ({
54
- title: text(child.frontmatter.title) ?? child.slug,
55
- description:
56
- text(child.frontmatter.summary) ??
57
- text(child.frontmatter.description) ??
58
- "",
59
- link: {
60
- label: labels.viewService,
61
- href: servicePublicPath(child.slug, text(child.frontmatter.parent)),
62
- },
63
- })),
64
- },
65
- };
66
- }
67
-
68
- function mapHrefs(value: unknown): unknown {
69
- if (Array.isArray(value)) return value.map(mapHrefs);
70
- if (value === null || typeof value !== "object") return value;
71
- return Object.fromEntries(
72
- Object.entries(value).map(([key, entry]) => [
73
- key,
74
- key === "href" && typeof entry === "string"
75
- ? toPublicServicesHref(entry)
76
- : mapHrefs(entry),
77
- ]),
78
- );
79
- }
80
-
81
- /**
82
- * The hub's sections with every site `href` starting `/services` re-pointed
83
- * onto the base, at any depth; the same array on a site with no
84
- * `services.path`.
85
- */
86
- export function withPublicServicesSections<S>(sections: S[]): S[] {
87
- if (SERVICES_PATH === SERVICES_ROUTE) return sections;
88
- return sections.map((section) => mapHrefs(section) as S);
89
- }