create-ailk 0.39.0 → 0.40.1
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/component-catalog.json +1 -1
- package/component-catalog.md +1 -1
- package/dist/add-route.js +15 -0
- package/dist/body-heading.d.ts +2 -1
- package/dist/body-heading.js +31 -3
- package/dist/module-architecture.js +0 -3
- package/dist/remove-module.js +13 -4
- package/dist/routes.d.ts +7 -0
- package/dist/routes.js +1 -1
- package/dist/site-roster.js +7 -1
- package/dist/surfaces.d.ts +2 -0
- package/dist/surfaces.js +59 -172
- package/package.json +3 -3
- package/templates/apps/web/CLAUDE.md +19 -2
- package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +3 -2
- package/templates/apps/web/__tests__/__mocks__/next-intl.ts +3 -2
- package/templates/apps/web/app/[locale]/layout.tsx +42 -25
- package/templates/apps/web/app/api/revalidate/__tests__/route.test.ts +56 -1
- package/templates/apps/web/app/api/revalidate/route.ts +45 -4
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +53 -0
- package/templates/apps/web/app/llms.txt/route.ts +5 -2
- package/templates/apps/web/i18n/request.ts +5 -1
- package/templates/apps/web/jest.config.cjs +6 -0
- package/templates/apps/web/lib/__tests__/deck-page.test.ts +9 -0
- package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +239 -0
- package/templates/apps/web/lib/__tests__/in-page-magnet-self-request.test.ts +1 -1
- package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +2 -2
- package/templates/apps/web/lib/__tests__/pricing-page.test.ts +1 -1
- package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +58 -0
- package/templates/apps/web/lib/__tests__/served-pages.test.ts +163 -20
- package/templates/apps/web/lib/__tests__/site-brand.test.ts +77 -0
- package/templates/apps/web/{app/[locale]/contact → lib}/__tests__/site-contact-lines.test.ts +64 -0
- package/templates/apps/web/lib/__tests__/site-identity-feature-list.test.ts +115 -3
- package/templates/apps/web/lib/__tests__/structured-data.test.tsx +17 -4
- package/templates/apps/web/lib/hub-site-config.ts +151 -0
- package/templates/apps/web/lib/in-page-magnet.ts +2 -2
- package/templates/apps/web/lib/pricing-page.ts +3 -3
- package/templates/apps/web/lib/profile-back-link.ts +49 -12
- package/templates/apps/web/lib/served-pages.ts +144 -39
- package/templates/apps/web/lib/site-brand.tsx +66 -0
- package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-email.ts +25 -5
- package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-lines.ts +21 -5
- package/templates/apps/web/lib/site-header.ts +1 -1
- package/templates/apps/web/lib/site-identity.ts +38 -2
- package/templates/apps/web/messages/en.json +3 -119
- package/templates/apps/web/next.config.mjs +7 -0
- package/templates/apps/web/package.json +1 -0
- package/templates/apps/web/site-pages.config.tsx +85 -0
- package/templates/tools/body-heading.ts +30 -3
- package/versions.json +50 -49
- package/templates/apps/web/app/[locale]/(authed)/leads/__tests__/page.test.tsx +0 -205
- package/templates/apps/web/app/[locale]/(authed)/leads/components/LeadsTable.tsx +0 -137
- package/templates/apps/web/app/[locale]/(authed)/leads/page.tsx +0 -122
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ForbiddenState.tsx +0 -24
- package/templates/apps/web/app/[locale]/(authed)/waitlist/format.ts +0 -111
- package/templates/apps/web/app/[locale]/[slug]/[detail]/__tests__/page.test.tsx +0 -402
- package/templates/apps/web/app/[locale]/[slug]/[detail]/page.tsx +0 -143
- package/templates/apps/web/app/[locale]/[slug]/__tests__/page.test.tsx +0 -148
- package/templates/apps/web/app/[locale]/[slug]/page.tsx +0 -109
- package/templates/apps/web/app/[locale]/about/[slug]/page.tsx +0 -46
- package/templates/apps/web/app/[locale]/about/__tests__/about-routes.test.tsx +0 -353
- package/templates/apps/web/app/[locale]/about/page.tsx +0 -122
- package/templates/apps/web/app/[locale]/alternatives/__tests__/page.test.tsx +0 -161
- package/templates/apps/web/app/[locale]/alternatives/page.tsx +0 -112
- package/templates/apps/web/app/[locale]/careers/[slug]/[action]/page.tsx +0 -244
- package/templates/apps/web/app/[locale]/careers/[slug]/apply.actions.ts +0 -325
- package/templates/apps/web/app/[locale]/careers/[slug]/job-application-form.ts +0 -120
- package/templates/apps/web/app/[locale]/careers/[slug]/page.tsx +0 -73
- package/templates/apps/web/app/[locale]/careers/__tests__/apply.actions.test.ts +0 -497
- package/templates/apps/web/app/[locale]/careers/__tests__/careers-hub.test.tsx +0 -172
- package/templates/apps/web/app/[locale]/careers/__tests__/careers-set.test.tsx +0 -153
- package/templates/apps/web/app/[locale]/careers/__tests__/job-application-form.test.ts +0 -141
- package/templates/apps/web/app/[locale]/careers/__tests__/job-apply-page.test.tsx +0 -546
- package/templates/apps/web/app/[locale]/careers/__tests__/page-renderer-migration.test.tsx +0 -189
- package/templates/apps/web/app/[locale]/careers/page.tsx +0 -165
- package/templates/apps/web/app/[locale]/case-studies/[slug]/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/case-studies/__tests__/hub-children.test.tsx +0 -65
- package/templates/apps/web/app/[locale]/case-studies/__tests__/page-renderer-migration.test.tsx +0 -125
- package/templates/apps/web/app/[locale]/case-studies/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/clients/__tests__/page-renderer-migration.test.tsx +0 -85
- package/templates/apps/web/app/[locale]/clients/page.tsx +0 -47
- package/templates/apps/web/app/[locale]/contact/ConversationalIntakeWrapper.tsx +0 -249
- package/templates/apps/web/app/[locale]/contact/__tests__/ConversationalIntakeWrapper.test.tsx +0 -400
- package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-magnet.test.ts +0 -138
- package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-text.test.ts +0 -49
- package/templates/apps/web/app/[locale]/contact/__tests__/contact-magnet-page.test.tsx +0 -494
- package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +0 -1122
- package/templates/apps/web/app/[locale]/contact/__tests__/intake-analytics.test.ts +0 -51
- package/templates/apps/web/app/[locale]/contact/__tests__/page-renderer-migration.test.tsx +0 -319
- package/templates/apps/web/app/[locale]/contact/contact-form-magnet.ts +0 -77
- package/templates/apps/web/app/[locale]/contact/contact-form-text.ts +0 -52
- package/templates/apps/web/app/[locale]/contact/contact.actions.ts +0 -403
- package/templates/apps/web/app/[locale]/contact/intake-analytics.ts +0 -49
- package/templates/apps/web/app/[locale]/contact/intake-script.ts +0 -92
- package/templates/apps/web/app/[locale]/contact/page.tsx +0 -267
- package/templates/apps/web/app/[locale]/courses/[slug]/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/courses/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/courses/__tests__/page-renderer-migration.test.tsx +0 -123
- package/templates/apps/web/app/[locale]/courses/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/events/[slug]/page.tsx +0 -57
- package/templates/apps/web/app/[locale]/events/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/events/__tests__/page-renderer-migration.test.tsx +0 -164
- package/templates/apps/web/app/[locale]/events/__tests__/program-event.test.tsx +0 -120
- package/templates/apps/web/app/[locale]/events/page.tsx +0 -60
- package/templates/apps/web/app/[locale]/faq/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/features/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/features/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/features/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/for/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/for/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/for/__tests__/page-renderer-migration.test.tsx +0 -90
- package/templates/apps/web/app/[locale]/for/page.tsx +0 -51
- package/templates/apps/web/app/[locale]/glossary/page.tsx +0 -53
- package/templates/apps/web/app/[locale]/how-to/[slug]/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/how-to/__tests__/page-renderer-migration.test.tsx +0 -78
- package/templates/apps/web/app/[locale]/how-to/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/integrations/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/integrations/__tests__/hub-children.test.tsx +0 -38
- package/templates/apps/web/app/[locale]/integrations/__tests__/page-renderer-migration.test.tsx +0 -141
- package/templates/apps/web/app/[locale]/integrations/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/launch-service/page.tsx +0 -44
- package/templates/apps/web/app/[locale]/newsletter/__tests__/page.test.tsx +0 -236
- package/templates/apps/web/app/[locale]/newsletter/page.tsx +0 -179
- package/templates/apps/web/app/[locale]/page.tsx +0 -147
- package/templates/apps/web/app/[locale]/partners/[slug]/page.tsx +0 -45
- package/templates/apps/web/app/[locale]/partners/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/partners/__tests__/page-renderer-migration.test.tsx +0 -125
- package/templates/apps/web/app/[locale]/partners/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/portfolio/[slug]/page.tsx +0 -46
- package/templates/apps/web/app/[locale]/portfolio/__tests__/hub-children.test.tsx +0 -38
- package/templates/apps/web/app/[locale]/portfolio/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/pricing/[slug]/__tests__/page.test.tsx +0 -324
- package/templates/apps/web/app/[locale]/pricing/[slug]/page.tsx +0 -87
- package/templates/apps/web/app/[locale]/pricing/__tests__/__snapshots__/unconnected.test.tsx.snap +0 -7
- package/templates/apps/web/app/[locale]/pricing/__tests__/offerings.test.tsx +0 -605
- package/templates/apps/web/app/[locale]/pricing/__tests__/page.test.tsx +0 -219
- package/templates/apps/web/app/[locale]/pricing/__tests__/pricing-pages.test.tsx +0 -215
- package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +0 -282
- package/templates/apps/web/app/[locale]/pricing/page.tsx +0 -120
- package/templates/apps/web/app/[locale]/privacy/page.tsx +0 -40
- package/templates/apps/web/app/[locale]/products/[slug]/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/products/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/products/__tests__/page-renderer-migration.test.tsx +0 -141
- package/templates/apps/web/app/[locale]/products/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/projects/[slug]/page.tsx +0 -37
- package/templates/apps/web/app/[locale]/projects/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/projects/__tests__/page-renderer-migration.test.tsx +0 -157
- package/templates/apps/web/app/[locale]/projects/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/purchase-policy/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/resources/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/resources/__tests__/hub-children.test.tsx +0 -38
- package/templates/apps/web/app/[locale]/resources/__tests__/page-renderer-migration.test.tsx +0 -151
- package/templates/apps/web/app/[locale]/resources/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/services/[slug]/[child]/page.tsx +0 -68
- package/templates/apps/web/app/[locale]/services/[slug]/page.tsx +0 -88
- package/templates/apps/web/app/[locale]/services/__tests__/hub-children.test.tsx +0 -158
- package/templates/apps/web/app/[locale]/services/__tests__/page-renderer-migration.test.tsx +0 -187
- package/templates/apps/web/app/[locale]/services/__tests__/service-detail-sections.test.tsx +0 -224
- package/templates/apps/web/app/[locale]/services/__tests__/service-families.test.tsx +0 -368
- package/templates/apps/web/app/[locale]/services/page.tsx +0 -71
- package/templates/apps/web/app/[locale]/software/[slug]/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/software/__tests__/page-renderer-migration.test.tsx +0 -81
- package/templates/apps/web/app/[locale]/software/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/team/[slug]/page.tsx +0 -45
- package/templates/apps/web/app/[locale]/team/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/team/__tests__/team-routes.test.tsx +0 -161
- package/templates/apps/web/app/[locale]/team/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/tech-articles/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/tech-articles/__tests__/page-renderer-migration.test.tsx +0 -82
- package/templates/apps/web/app/[locale]/tech-articles/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/templates/[slug]/__tests__/page.test.tsx +0 -203
- package/templates/apps/web/app/[locale]/templates/[slug]/page.tsx +0 -81
- package/templates/apps/web/app/[locale]/templates/__tests__/page.test.tsx +0 -237
- package/templates/apps/web/app/[locale]/templates/page.tsx +0 -114
- package/templates/apps/web/app/[locale]/terms/page.tsx +0 -40
- package/templates/apps/web/app/[locale]/testimonials/__tests__/page-renderer-migration.test.tsx +0 -85
- package/templates/apps/web/app/[locale]/testimonials/page.tsx +0 -51
- package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/page.test.tsx +0 -136
- package/templates/apps/web/app/[locale]/thanks/[slug]/page.tsx +0 -39
- package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +0 -226
- package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +0 -217
- package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +0 -106
- package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +0 -94
- package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe.actions.ts +0 -55
- package/templates/apps/web/app/[locale]/vs/[slug]/__tests__/page.test.tsx +0 -100
- package/templates/apps/web/app/[locale]/vs/[slug]/page.tsx +0 -60
- package/templates/apps/web/app/[locale]/whitepapers/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/whitepapers/__tests__/page-renderer-migration.test.tsx +0 -82
- package/templates/apps/web/app/[locale]/whitepapers/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/working-agreement/__tests__/page.test.tsx +0 -63
- package/templates/apps/web/app/[locale]/working-agreement/page.tsx +0 -41
- package/templates/apps/web/lib/__tests__/hub-children.fixtures.ts +0 -279
- package/templates/apps/web/lib/__tests__/route-family.test.ts +0 -57
- package/templates/apps/web/lib/__tests__/service-listing.test.ts +0 -111
- package/templates/apps/web/lib/__tests__/template-listing.test.ts +0 -158
- package/templates/apps/web/lib/hub-children.tsx +0 -351
- package/templates/apps/web/lib/meet-placeholder.ts +0 -5
- package/templates/apps/web/lib/posting-title.ts +0 -39
- package/templates/apps/web/lib/route-family.ts +0 -69
- package/templates/apps/web/lib/service-listing.ts +0 -89
- package/templates/apps/web/lib/template-listing.ts +0 -169
- package/templates/apps/web/src/lib/__tests__/lead-write.test.ts +0 -187
- package/templates/apps/web/src/lib/lead-write.ts +0 -90
package/templates/apps/web/{app/[locale]/contact → lib}/__tests__/site-contact-lines.test.ts
RENAMED
|
@@ -8,6 +8,12 @@ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
|
8
8
|
import { tmpdir } from "node:os";
|
|
9
9
|
import { join } from "node:path";
|
|
10
10
|
|
|
11
|
+
// #11456 D4 — the held hub value, `undefined` (no hub connection) unless a
|
|
12
|
+
// case sets one; the hub read itself is pinned in `hub-site-config.test.ts`.
|
|
13
|
+
const mockHeldHubSite = jest.fn((): unknown => undefined);
|
|
14
|
+
// eslint-disable-next-line no-restricted-syntax -- the held hub value stands in for the hub read, an HTTP boundary
|
|
15
|
+
jest.mock("../hub-site-config", () => ({ heldHubSite: () => mockHeldHubSite() }));
|
|
16
|
+
|
|
11
17
|
import { readSiteContactLines } from "../site-contact-lines";
|
|
12
18
|
|
|
13
19
|
let root: string;
|
|
@@ -210,3 +216,61 @@ describe("readSiteContactLines(locality) — the site's own locality line (#1055
|
|
|
210
216
|
]);
|
|
211
217
|
});
|
|
212
218
|
});
|
|
219
|
+
|
|
220
|
+
describe("readSiteContactLines on a hub-connected site (#11456 D4)", () => {
|
|
221
|
+
afterEach(() => mockHeldHubSite.mockReset().mockReturnValue(undefined));
|
|
222
|
+
|
|
223
|
+
it("takes the locality and email from the held hub identity, never the file's", () => {
|
|
224
|
+
writeSite(
|
|
225
|
+
[
|
|
226
|
+
"siteName: Acme",
|
|
227
|
+
"contactEmail: file@acme.test",
|
|
228
|
+
"siteIdentity:",
|
|
229
|
+
" kind: LocalBusiness",
|
|
230
|
+
" name: Acme",
|
|
231
|
+
" url: https://acme.test",
|
|
232
|
+
" telephone: '+14155550100'",
|
|
233
|
+
...addressYaml(" ", "San Francisco", "CA"),
|
|
234
|
+
].join("\n"),
|
|
235
|
+
);
|
|
236
|
+
mockHeldHubSite.mockReturnValue({
|
|
237
|
+
identity: {
|
|
238
|
+
kind: "Person",
|
|
239
|
+
name: "Hub Person",
|
|
240
|
+
url: "https://hub.example",
|
|
241
|
+
email: "hub@hub.example",
|
|
242
|
+
address: {
|
|
243
|
+
streetAddress: "1 Hub St",
|
|
244
|
+
addressLocality: "Hubton",
|
|
245
|
+
addressRegion: "HB",
|
|
246
|
+
postalCode: "00001",
|
|
247
|
+
addressCountry: "US",
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
seo: null,
|
|
251
|
+
});
|
|
252
|
+
expect(readSiteContactLines()).toEqual([
|
|
253
|
+
{ label: "Hubton, HB" },
|
|
254
|
+
{ label: "hub@hub.example", href: "mailto:hub@hub.example" },
|
|
255
|
+
]);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("a hub Organization identity has no locality line, whatever the file declares", () => {
|
|
259
|
+
writeSite(
|
|
260
|
+
[
|
|
261
|
+
"siteName: Acme",
|
|
262
|
+
"siteIdentity:",
|
|
263
|
+
" kind: LocalBusiness",
|
|
264
|
+
" name: Acme",
|
|
265
|
+
" url: https://acme.test",
|
|
266
|
+
" telephone: '+14155550100'",
|
|
267
|
+
...addressYaml(" ", "San Francisco", "CA"),
|
|
268
|
+
].join("\n"),
|
|
269
|
+
);
|
|
270
|
+
mockHeldHubSite.mockReturnValue({
|
|
271
|
+
identity: { kind: "Organization", name: "Hub Co", url: "https://hub.example" },
|
|
272
|
+
seo: null,
|
|
273
|
+
});
|
|
274
|
+
expect(readSiteContactLines()).toEqual([]);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
@@ -24,9 +24,26 @@ jest.mock("node:fs", () => {
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
const mockGetContentAdapter = jest.fn<Pick<ContentAdapter, "listPages">, []>();
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
// #11456 — the two registrations site-identity.ts makes, recorded per module
|
|
28
|
+
// registry (spies passing through to that registry's real renderer).
|
|
29
|
+
jest.mock("@working-theory/page-renderer", () => {
|
|
30
|
+
const actual = jest.requireActual<PageRenderer>("@working-theory/page-renderer");
|
|
31
|
+
return {
|
|
32
|
+
...actual,
|
|
33
|
+
getContentAdapter: () => mockGetContentAdapter(),
|
|
34
|
+
setSiteIdentity: jest.fn(actual.setSiteIdentity),
|
|
35
|
+
setSiteIdentityReader: jest.fn(actual.setSiteIdentityReader),
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// #11456 — the hub read's HTTP call; the rest of the client stays real.
|
|
40
|
+
const mockSiteConfigGet = jest.fn();
|
|
41
|
+
jest.mock("@working-theory/api-client", () => ({
|
|
42
|
+
...jest.requireActual("@working-theory/api-client"),
|
|
43
|
+
siteConfig: { get: (...args: unknown[]) => mockSiteConfigGet(...args) },
|
|
44
|
+
}));
|
|
45
|
+
jest.mock("next/cache", () => ({
|
|
46
|
+
unstable_cache: (fn: () => Promise<unknown>) => fn,
|
|
30
47
|
}));
|
|
31
48
|
|
|
32
49
|
type Row = { type: string; slug: string; title: string; sections?: unknown[] };
|
|
@@ -143,6 +160,7 @@ describe("the featureList registration with no content directory (#10644 AC-2)",
|
|
|
143
160
|
|
|
144
161
|
afterEach(() => {
|
|
145
162
|
renderer?.setSiteFeatureListReader(undefined);
|
|
163
|
+
renderer?.setSiteIdentityReader(undefined);
|
|
146
164
|
renderer?.setSiteIdentity(undefined);
|
|
147
165
|
renderer = undefined;
|
|
148
166
|
rmSync(root, { recursive: true, force: true });
|
|
@@ -193,4 +211,98 @@ describe("the featureList registration with no content directory (#10644 AC-2)",
|
|
|
193
211
|
expect(appNode(result as Record<string, unknown>)).not.toHaveProperty("featureList");
|
|
194
212
|
expect(mockGetContentAdapter).toHaveBeenCalledTimes(0);
|
|
195
213
|
});
|
|
214
|
+
|
|
215
|
+
describe("the hub identity reader (#11456 D4, AC-2)", () => {
|
|
216
|
+
const HUB_IDENTITY = {
|
|
217
|
+
kind: "Organization",
|
|
218
|
+
name: "Hub Co",
|
|
219
|
+
// Another origin: no workspace value may move an `@id` (SEC-11456-6).
|
|
220
|
+
url: "https://elsewhere.example",
|
|
221
|
+
description: "The hub's description.",
|
|
222
|
+
sameAs: ["https://social.example/hub"],
|
|
223
|
+
};
|
|
224
|
+
const savedHub = {
|
|
225
|
+
key: process.env.AILK_SPOKE_KEY,
|
|
226
|
+
api: process.env.AILK_API_URL,
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
function hubConnect(): void {
|
|
230
|
+
process.env.CONTENT_ADAPTER = "database";
|
|
231
|
+
process.env.AILK_SPOKE_KEY = "ailk_spk_TESTKEYxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
|
232
|
+
process.env.AILK_API_URL = "https://hub.example";
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** The registrations the last `loadSiteIdentity()` made. */
|
|
236
|
+
const calls = (name: "setSiteIdentity" | "setSiteIdentityReader") =>
|
|
237
|
+
jest.mocked(loadedRenderer![name]).mock.calls;
|
|
238
|
+
let loadedRenderer: PageRenderer | undefined;
|
|
239
|
+
const load = (): PageRenderer => {
|
|
240
|
+
// The mocked renderer is one instance across registries: forget the
|
|
241
|
+
// registrations earlier loads made.
|
|
242
|
+
const shared = jest.requireMock<PageRenderer>("@working-theory/page-renderer");
|
|
243
|
+
jest.mocked(shared.setSiteIdentity).mockClear();
|
|
244
|
+
jest.mocked(shared.setSiteIdentityReader).mockClear();
|
|
245
|
+
return (loadedRenderer = loadSiteIdentity());
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
beforeEach(() => {
|
|
249
|
+
mockSiteConfigGet.mockReset();
|
|
250
|
+
mockSiteConfigGet.mockResolvedValue({ ok: true, body: { identity: HUB_IDENTITY, seo: null } });
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
afterEach(() => {
|
|
254
|
+
restore("AILK_SPOKE_KEY", savedHub.key);
|
|
255
|
+
restore("AILK_API_URL", savedHub.api);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("hub-connected: registers a reader carrying the hub identity on the file's baseUrl; every @id stays on the file's origin", async () => {
|
|
259
|
+
hubConnect();
|
|
260
|
+
delete process.env.NEXT_PUBLIC_SITE_URL;
|
|
261
|
+
const renderer = load();
|
|
262
|
+
|
|
263
|
+
expect(calls("setSiteIdentityReader")).toHaveLength(1);
|
|
264
|
+
const reader = calls("setSiteIdentityReader")[0]![0] as () => Promise<unknown>;
|
|
265
|
+
await expect(reader()).resolves.toEqual({
|
|
266
|
+
siteName: "Hub Co",
|
|
267
|
+
baseUrl: ORIGIN,
|
|
268
|
+
identity: HUB_IDENTITY,
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
const result = (await renderer.pageToJsonLd(
|
|
272
|
+
{ type: "AboutPage", slug: "about", title: "About" } as Parameters<PageRenderer["pageToJsonLd"]>[0],
|
|
273
|
+
"en",
|
|
274
|
+
)) as Record<string, unknown>;
|
|
275
|
+
const graph = (result["@graph"] ?? []) as Array<Record<string, unknown>>;
|
|
276
|
+
expect(graph.find((n) => n["@type"] === "Organization")).toMatchObject({
|
|
277
|
+
"@id": `${ORIGIN}/#organization`,
|
|
278
|
+
name: "Hub Co",
|
|
279
|
+
description: "The hub's description.",
|
|
280
|
+
sameAs: ["https://social.example/hub"],
|
|
281
|
+
});
|
|
282
|
+
const ids = graph.map((n) => n["@id"]).filter((id): id is string => typeof id === "string");
|
|
283
|
+
expect(ids.length).toBeGreaterThan(0);
|
|
284
|
+
for (const id of ids) expect(id.startsWith(`${ORIGIN}/`)).toBe(true);
|
|
285
|
+
expect(JSON.stringify(result)).not.toContain("elsewhere.example/#");
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("hub-connected with no hub identity row: the reader answers undefined, so the file registration composes", async () => {
|
|
289
|
+
hubConnect();
|
|
290
|
+
mockSiteConfigGet.mockResolvedValue({ ok: true, body: { identity: null, seo: null } });
|
|
291
|
+
load();
|
|
292
|
+
const reader = calls("setSiteIdentityReader")[0]![0] as () => Promise<unknown>;
|
|
293
|
+
await expect(reader()).resolves.toBeUndefined();
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it.each([
|
|
297
|
+
["no AILK_SPOKE_KEY", () => delete process.env.AILK_SPOKE_KEY],
|
|
298
|
+
["CONTENT_ADAPTER unset", () => delete process.env.CONTENT_ADAPTER],
|
|
299
|
+
])("not hub-connected (%s): registers no reader, and setSiteIdentity receives the file registration", (_label, unset) => {
|
|
300
|
+
hubConnect();
|
|
301
|
+
unset();
|
|
302
|
+
load();
|
|
303
|
+
expect(calls("setSiteIdentityReader")).toEqual([]);
|
|
304
|
+
expect(calls("setSiteIdentity")).toEqual([[readSiteIdentity(root)]]);
|
|
305
|
+
expect(mockSiteConfigGet).not.toHaveBeenCalled();
|
|
306
|
+
});
|
|
307
|
+
});
|
|
196
308
|
});
|
|
@@ -50,6 +50,7 @@ import {
|
|
|
50
50
|
rmSync,
|
|
51
51
|
writeFileSync,
|
|
52
52
|
} from "node:fs";
|
|
53
|
+
import { createRequire } from "node:module";
|
|
53
54
|
import { tmpdir } from "node:os";
|
|
54
55
|
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
55
56
|
|
|
@@ -78,7 +79,7 @@ import {
|
|
|
78
79
|
type ValidationError,
|
|
79
80
|
} from "@working-theory/schema-validator";
|
|
80
81
|
|
|
81
|
-
import { MEET_PLACEHOLDER_HUB } from "
|
|
82
|
+
import { MEET_PLACEHOLDER_HUB } from "@working-theory/site-pages/lib/meet-placeholder";
|
|
82
83
|
import type { ReactElement } from "react";
|
|
83
84
|
import { parse as parseYaml } from "yaml";
|
|
84
85
|
|
|
@@ -105,6 +106,18 @@ jest.mock("@working-theory/analytics/server", () => ({
|
|
|
105
106
|
|
|
106
107
|
// ── Where the site's content and routes live ────────────────────────────────
|
|
107
108
|
|
|
109
|
+
/**
|
|
110
|
+
* A route file's own source (#11259 D8): a generated route file is a
|
|
111
|
+
* re-export, so it is followed to the package page it re-exports — resolved
|
|
112
|
+
* from apps/web as the build resolves it — whose text the checks below read.
|
|
113
|
+
*/
|
|
114
|
+
function routeSource(file: string): string {
|
|
115
|
+
const text = readFileSync(file, "utf8");
|
|
116
|
+
if (!text.startsWith("// Generated by create-ailk routes from ")) return text;
|
|
117
|
+
const spec = /from "(@working-theory\/[^"]+)"/.exec(text)?.[1];
|
|
118
|
+
return spec === undefined ? text : readFileSync(createRequire(join(__dirname, "..", "..", "package.json")).resolve(spec), "utf8");
|
|
119
|
+
}
|
|
120
|
+
|
|
108
121
|
const CONTENT_ROOT =
|
|
109
122
|
process.env.AILK_CONTENT_ROOT ?? resolve(__dirname, "../../../../content");
|
|
110
123
|
const ROUTE_ROOT = resolve(__dirname, "../../app/[locale]");
|
|
@@ -683,7 +696,7 @@ function hubOwnSlug(file: string, type: string): string | null {
|
|
|
683
696
|
if (basename(dirname(file)) !== "[slug]") return null;
|
|
684
697
|
const parent = join(dirname(dirname(file)), "page.tsx");
|
|
685
698
|
if (!existsSync(parent)) return null;
|
|
686
|
-
const identity = routeIdentity(
|
|
699
|
+
const identity = routeIdentity(routeSource(parent));
|
|
687
700
|
return identity !== null && identity.type === type ? identity.slug : null;
|
|
688
701
|
}
|
|
689
702
|
|
|
@@ -745,7 +758,7 @@ describe("structured data — every route emits a valid JSON-LD script", () => {
|
|
|
745
758
|
|
|
746
759
|
it.each(routes)("$route", async ({ route, file }) => {
|
|
747
760
|
const label = `/${DEFAULT_LOCALE}${route === "" ? "" : "/" + route}`;
|
|
748
|
-
const src =
|
|
761
|
+
const src = routeSource(file);
|
|
749
762
|
// #10040 decision 1 — without the marketing module `/` redirects to
|
|
750
763
|
// /account before any content: no HomePage seed, no JSON-LD, and its
|
|
751
764
|
// page.tsx still names renderPage, so it is skipped here rather than
|
|
@@ -871,7 +884,7 @@ describe("structured data — every route emits a valid JSON-LD script", () => {
|
|
|
871
884
|
|
|
872
885
|
describe("structured data — a hub's own page is not rendered at its detail route (#10044 AC-6)", () => {
|
|
873
886
|
const dynamicRoutes = walkRoutes(ROUTE_ROOT).flatMap(({ route, file }) => {
|
|
874
|
-
const identity = routeIdentity(
|
|
887
|
+
const identity = routeIdentity(routeSource(file));
|
|
875
888
|
return identity !== null && identity.slug === null
|
|
876
889
|
? [{ route, file, type: identity.type }]
|
|
877
890
|
: [];
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hub read of the site's identity and seo (#11456, spec
|
|
3
|
+
* docs/specs/11456-a-hub-connected-site-reads-spec.md D3).
|
|
4
|
+
*
|
|
5
|
+
* A HUB-CONNECTED site — `CONTENT_ADAPTER=database` (the switch
|
|
6
|
+
* `resolveBlogSource` uses, samhenry#687) AND a spoke key that would go on the
|
|
7
|
+
* wire (`sendsSpokeKey()`) — reads `GET /v1/content/site-config`, which
|
|
8
|
+
* answers its own workspace's rows. Any other site makes no call and keeps
|
|
9
|
+
* reading `content/_site.mdx`: without a key the route can only answer 401.
|
|
10
|
+
*
|
|
11
|
+
* Cached with Next's `unstable_cache` under `siteConfigTag()` for at most
|
|
12
|
+
* `HUB_SITE_REVALIDATE_SECONDS`. The `site-config` revalidate event an Admin
|
|
13
|
+
* save fires purges the tag (`app/api/revalidate/route.ts`); the expiry is the
|
|
14
|
+
* safety net for a spoke with no `revalidateUrl`. The key parts carry a
|
|
15
|
+
* digest of the spoke key — never the key — so two deployments with different
|
|
16
|
+
* keys sharing one data cache never share an entry (SEC-11456-2).
|
|
17
|
+
*
|
|
18
|
+
* Inside the cached callback a non-2xx, a throw, a read slower than
|
|
19
|
+
* `HUB_SITE_TIMEOUT_MS` or a body without the two keys THROWS, so nothing is
|
|
20
|
+
* written and Next keeps serving the last entry (`page-renderer`'s
|
|
21
|
+
* `api-source.ts` failure rule). Outside, a failure answers this instance's
|
|
22
|
+
* last good value, else `undefined` — so a hub outage never reaches a page.
|
|
23
|
+
* The timeout does not abort the request (`http.ts`'s `get` takes no signal).
|
|
24
|
+
*
|
|
25
|
+
* One read per request: `readHubSite` is wrapped in React's `cache()`, so
|
|
26
|
+
* the layout's metadata, its render and every page's JSON-LD share it.
|
|
27
|
+
*
|
|
28
|
+
* `site-brand.tsx`, `site-identity.ts`, `site-contact-email.ts` and
|
|
29
|
+
* `site-contact-lines.ts` import this module; it imports none of them.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { createHash } from "node:crypto";
|
|
33
|
+
|
|
34
|
+
import { sendsSpokeKey, siteConfig } from "@working-theory/api-client";
|
|
35
|
+
import { resolvedAdapterKind } from "@working-theory/content-adapters";
|
|
36
|
+
import {
|
|
37
|
+
siteConfigTag,
|
|
38
|
+
siteWorkspaceSegment,
|
|
39
|
+
} from "@working-theory/page-renderer/edge";
|
|
40
|
+
import {
|
|
41
|
+
SEOSchema,
|
|
42
|
+
SiteIdentitySchema,
|
|
43
|
+
type SEO,
|
|
44
|
+
type SiteIdentity,
|
|
45
|
+
} from "@working-theory/site-config/schema";
|
|
46
|
+
import { cache } from "react";
|
|
47
|
+
import type { ZodType } from "zod";
|
|
48
|
+
|
|
49
|
+
/** The workspace's identity and seo rows as the site reads them; each `null` when absent or unreadable. */
|
|
50
|
+
export interface HubSite {
|
|
51
|
+
identity: SiteIdentity | null;
|
|
52
|
+
seo: SEO | null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** How long one hub read is served before it is read again. */
|
|
56
|
+
export const HUB_SITE_REVALIDATE_SECONDS = 300;
|
|
57
|
+
/** A read slower than this is a failed read. */
|
|
58
|
+
export const HUB_SITE_TIMEOUT_MS = 3_000;
|
|
59
|
+
|
|
60
|
+
/** Whether this site reads its identity from the hub. */
|
|
61
|
+
export function hubConnected(): boolean {
|
|
62
|
+
return resolvedAdapterKind() === "database" && sendsSpokeKey();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The last value `readHubSite` resolved on this instance. */
|
|
66
|
+
let held: HubSite | undefined;
|
|
67
|
+
|
|
68
|
+
function parsedOrNull<T>(schema: ZodType<T>, value: unknown): T | null {
|
|
69
|
+
const parsed = schema.safeParse(value);
|
|
70
|
+
return parsed.success ? parsed.data : null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** One hub read. Throws on any failure, so the cache writes nothing. */
|
|
74
|
+
async function fetchHubSite(): Promise<HubSite> {
|
|
75
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
76
|
+
const timeout = new Promise<never>((_resolve, reject) => {
|
|
77
|
+
timer = setTimeout(
|
|
78
|
+
() => reject(new Error("hub site-config read timed out")),
|
|
79
|
+
HUB_SITE_TIMEOUT_MS,
|
|
80
|
+
);
|
|
81
|
+
timer.unref?.();
|
|
82
|
+
});
|
|
83
|
+
try {
|
|
84
|
+
const res = await Promise.race([siteConfig.get(), timeout]);
|
|
85
|
+
if (!res.ok) throw new Error(`hub site-config read answered ${res.status}`);
|
|
86
|
+
const body: unknown = res.body;
|
|
87
|
+
if (
|
|
88
|
+
typeof body !== "object" ||
|
|
89
|
+
body === null ||
|
|
90
|
+
!("identity" in body) ||
|
|
91
|
+
!("seo" in body)
|
|
92
|
+
) {
|
|
93
|
+
throw new Error("hub site-config read answered no rows");
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
identity: parsedOrNull(SiteIdentitySchema, body.identity),
|
|
97
|
+
seo: parsedOrNull(SEOSchema, body.seo),
|
|
98
|
+
};
|
|
99
|
+
} finally {
|
|
100
|
+
clearTimeout(timer);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The first 16 hex of the spoke key's SHA-256 — a cache-key part, never the key. */
|
|
105
|
+
function spokeKeyDigest(): string {
|
|
106
|
+
return createHash("sha256")
|
|
107
|
+
.update((process.env.AILK_SPOKE_KEY ?? "").trim(), "utf8")
|
|
108
|
+
.digest("hex")
|
|
109
|
+
.slice(0, 16);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The hub's identity and seo for this site, or `undefined` when the site is
|
|
114
|
+
* not hub-connected (no call made) or no read has ever succeeded here.
|
|
115
|
+
* Never rejects. Shared within one request (React `cache()`).
|
|
116
|
+
*/
|
|
117
|
+
export const readHubSite = cache(async function readHubSite(): Promise<
|
|
118
|
+
HubSite | undefined
|
|
119
|
+
> {
|
|
120
|
+
if (!hubConnected()) return undefined;
|
|
121
|
+
try {
|
|
122
|
+
// Loaded only on the hub-connected path, so a site that is not one loads
|
|
123
|
+
// nothing it did not load before.
|
|
124
|
+
const { unstable_cache } = await import("next/cache");
|
|
125
|
+
const read = unstable_cache(
|
|
126
|
+
fetchHubSite,
|
|
127
|
+
["ailk-hub-site-config", siteWorkspaceSegment(), spokeKeyDigest()],
|
|
128
|
+
{ tags: [siteConfigTag()], revalidate: HUB_SITE_REVALIDATE_SECONDS },
|
|
129
|
+
);
|
|
130
|
+
held = await read();
|
|
131
|
+
} catch (err) {
|
|
132
|
+
console.warn(
|
|
133
|
+
`[hub-site-config] read failed (${err instanceof Error ? err.name : typeof err}); serving the last good value`,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return held;
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The last value `readHubSite` resolved on this instance (synchronous), for
|
|
141
|
+
* the readers whose seam is synchronous — the contact email and contact
|
|
142
|
+
* lines. `undefined` on a cold instance's first render.
|
|
143
|
+
*/
|
|
144
|
+
export function heldHubSite(): HubSite | undefined {
|
|
145
|
+
return hubConnected() ? held : undefined;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Test seam: forget the held value. */
|
|
149
|
+
export function __resetHubSiteForTests(): void {
|
|
150
|
+
held = undefined;
|
|
151
|
+
}
|
|
@@ -49,8 +49,8 @@ import { createElement, type ReactElement } from "react";
|
|
|
49
49
|
import {
|
|
50
50
|
contactFormFromConfig,
|
|
51
51
|
type ContactFormView,
|
|
52
|
-
} from "
|
|
53
|
-
import { captureLeadAction } from "
|
|
52
|
+
} from "@working-theory/site-pages/pages/contact/contact-form-magnet";
|
|
53
|
+
import { captureLeadAction } from "@working-theory/site-pages/pages/contact/contact.actions";
|
|
54
54
|
|
|
55
55
|
import { consentPoliciesFor } from "./consent-policies";
|
|
56
56
|
import { subscribeNewsletterAction } from "./newsletter.actions";
|
|
@@ -29,8 +29,8 @@ import {
|
|
|
29
29
|
import { getTranslations } from "next-intl/server";
|
|
30
30
|
import { createElement, type ReactNode } from "react";
|
|
31
31
|
|
|
32
|
-
import { contactFormText } from "
|
|
33
|
-
import { readSiteContactEmail } from "
|
|
32
|
+
import { contactFormText } from "@working-theory/site-pages/pages/contact/contact-form-text";
|
|
33
|
+
import { readSiteContactEmail } from "./site-contact-email";
|
|
34
34
|
|
|
35
35
|
import { browserApiOrigin } from "./api-origin.generated";
|
|
36
36
|
import {
|
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
type OfferingsPricing,
|
|
39
39
|
type OfferingsPricingLabels,
|
|
40
40
|
} from "./offerings-pricing";
|
|
41
|
-
import type { DetailPage } from "
|
|
41
|
+
import type { DetailPage } from "@working-theory/site-pages/lib/route-family";
|
|
42
42
|
|
|
43
43
|
type PricingSection = Extract<PageSection, { type: "pricing" }>;
|
|
44
44
|
type PricingData = PricingSection["data"];
|
|
@@ -36,6 +36,25 @@ function escapeRegExp(segment: string): string {
|
|
|
36
36
|
return segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* The page's ancestors below the home as bare (locale-less) paths, nearest
|
|
41
|
+
* first — every parent the walk may ask about (`lib/served-pages.ts` matches
|
|
42
|
+
* them against the app's dynamic page routes, #11438). None for an absent or
|
|
43
|
+
* empty pathname.
|
|
44
|
+
*/
|
|
45
|
+
export function ancestorPaths(
|
|
46
|
+
pathname: string | null | undefined,
|
|
47
|
+
locales: readonly string[],
|
|
48
|
+
): string[] {
|
|
49
|
+
if (!pathname) return [];
|
|
50
|
+
const segments = barePath(pathname, locales).split("/").filter(Boolean);
|
|
51
|
+
const ancestors: string[] = [];
|
|
52
|
+
for (let depth = segments.length - 1; depth >= 1; depth--) {
|
|
53
|
+
ancestors.push(`/${segments.slice(0, depth).join("/")}`);
|
|
54
|
+
}
|
|
55
|
+
return ancestors;
|
|
56
|
+
}
|
|
57
|
+
|
|
39
58
|
/**
|
|
40
59
|
* The page's served parent as a bare (locale-less) path, nearest first, or
|
|
41
60
|
* `null` when no ancestor below the home is served.
|
|
@@ -48,14 +67,7 @@ export function servedParent(input: {
|
|
|
48
67
|
locales: readonly string[];
|
|
49
68
|
served: (barePath: string) => boolean;
|
|
50
69
|
}): string | null {
|
|
51
|
-
|
|
52
|
-
if (!pathname) return null;
|
|
53
|
-
const segments = barePath(pathname, locales).split("/").filter(Boolean);
|
|
54
|
-
for (let depth = segments.length - 1; depth >= 1; depth--) {
|
|
55
|
-
const parent = `/${segments.slice(0, depth).join("/")}`;
|
|
56
|
-
if (served(parent)) return parent;
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
70
|
+
return ancestorPaths(input.pathname, input.locales).find((path) => input.served(path)) ?? null;
|
|
59
71
|
}
|
|
60
72
|
|
|
61
73
|
/** The arrow's server href: the served parent under the home's locale prefix, else `homePath`. */
|
|
@@ -104,20 +116,45 @@ export function navLabelsByPath(
|
|
|
104
116
|
return labels;
|
|
105
117
|
}
|
|
106
118
|
|
|
119
|
+
/** The separators a page title may join a trailing site name with. */
|
|
120
|
+
const SITE_NAME_SEPARATORS = [" — ", " | ", " - "] as const;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* `title` without a trailing ` — <siteName>` / ` | <siteName>` /
|
|
124
|
+
* ` - <siteName>` (hub-built pages title themselves "About — Sam Henry").
|
|
125
|
+
* Only that exact trailing form is removed: the site name anywhere else, or
|
|
126
|
+
* a suffix that would leave nothing, is left alone.
|
|
127
|
+
*/
|
|
128
|
+
function stripSiteNameSuffix(title: string, siteName: string | undefined): string {
|
|
129
|
+
const name = siteName?.trim();
|
|
130
|
+
if (!name) return title;
|
|
131
|
+
for (const separator of SITE_NAME_SEPARATORS) {
|
|
132
|
+
const suffix = `${separator}${name}`;
|
|
133
|
+
if (title.endsWith(suffix) && title.length > suffix.length) {
|
|
134
|
+
return title.slice(0, -suffix.length).trim() || title;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return title;
|
|
138
|
+
}
|
|
139
|
+
|
|
107
140
|
/**
|
|
108
141
|
* The name the arrow's label gives its destination ("Back to <name>"): the
|
|
109
|
-
* parent's nav label, else its page title
|
|
110
|
-
* (`/meet` → "Meet",
|
|
111
|
-
* names where the
|
|
142
|
+
* parent's nav label, else its page title with a trailing site-name suffix
|
|
143
|
+
* removed, else its last segment in words (`/meet` → "Meet",
|
|
144
|
+
* `/case-studies` → "Case studies"), so the label always names where the
|
|
145
|
+
* link goes.
|
|
112
146
|
*/
|
|
113
147
|
export function backLinkName(
|
|
114
148
|
parent: string,
|
|
115
149
|
sources: {
|
|
116
150
|
navLabels: ReadonlyMap<string, string>;
|
|
117
151
|
titles: ReadonlyMap<string, string>;
|
|
152
|
+
siteName?: string;
|
|
118
153
|
},
|
|
119
154
|
): string {
|
|
120
|
-
const
|
|
155
|
+
const title = sources.titles.get(parent);
|
|
156
|
+
const named =
|
|
157
|
+
sources.navLabels.get(parent) || (title ? stripSiteNameSuffix(title, sources.siteName) : "");
|
|
121
158
|
if (named) return named;
|
|
122
159
|
const words = (parent.split("/").pop() ?? "").replace(/-/g, " ");
|
|
123
160
|
return words.charAt(0).toUpperCase() + words.slice(1);
|