@luhtech/site-template 0.15.1 → 0.17.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/package.json +5 -4
- package/src/components/AssetRequestForm.astro +133 -0
- package/src/components/PaperLanding.astro +242 -0
- package/src/components/sections/Cta.astro +14 -2
- package/src/content/loadPage.ts +1 -1
- package/src/content/loadSite.ts +1 -1
- package/src/content/loadTool.ts +21 -6
- package/src/lib/assetRequest.ts +109 -0
- package/src/lib/paperLanding.ts +182 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luhtech/site-template",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Shared Astro component library + content-instance contract for LuhTech venture marketing sites -- one template renders every site from content/page.schema.json + content/site.schema.json instances.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"exports": {
|
|
24
24
|
"./content": "./src/content/index.ts",
|
|
25
|
+
"./lib/paperLanding": "./src/lib/paperLanding.ts",
|
|
25
26
|
"./layouts/SiteLayout.astro": "./src/layouts/SiteLayout.astro",
|
|
26
27
|
"./components/*": "./src/components/*",
|
|
27
28
|
"./components/sections/*": "./src/components/sections/*"
|
|
@@ -51,10 +52,10 @@
|
|
|
51
52
|
},
|
|
52
53
|
"luhtech": {
|
|
53
54
|
"schemaPins": {
|
|
54
|
-
"content/page.schema.json": "2.
|
|
55
|
-
"content/site.schema.json": "1.
|
|
55
|
+
"content/page.schema.json": "2.5.0",
|
|
56
|
+
"content/site.schema.json": "1.4.0",
|
|
56
57
|
"content/capability-claim.schema.json": "0.2.0",
|
|
57
|
-
"content/tool.schema.json": "1.
|
|
58
|
+
"content/tool.schema.json": "1.2.0",
|
|
58
59
|
"portfolio/brand-identity.schema.json": "1.5.0"
|
|
59
60
|
}
|
|
60
61
|
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
---
|
|
2
|
+
// d-2026-10-01-st-asset-request-form. The gated asset form a cta section
|
|
3
|
+
// renders when it carries assetRequest (page.schema.json v2.5.0): name, work
|
|
4
|
+
// email, company, role and one unticked series opt-in, posted to the capture
|
|
5
|
+
// service (site.leadCapture.assetRequestEndpoint, site.schema.json v1.3.0).
|
|
6
|
+
// The capture service emails a seven-day link; this page only ever shows a
|
|
7
|
+
// confirmation -- it never receives, renders or links the asset itself.
|
|
8
|
+
//
|
|
9
|
+
// An optional "discuss this with us" box, with the page's requestPrompt as
|
|
10
|
+
// its question, also submits a request (request.submitted: an Opportunity).
|
|
11
|
+
// Same anti-bot controls as LeadCaptureForm: a CSS-hidden honeypot and a
|
|
12
|
+
// minimum time-to-submit.
|
|
13
|
+
import { PERSONAS } from '../lib/assetRequest.ts';
|
|
14
|
+
|
|
15
|
+
export interface Props {
|
|
16
|
+
assetRequest: { assetRef: string; requestPrompt?: string };
|
|
17
|
+
leadCapture: { assetRequestEndpoint: string; honeypotField: string; minSubmitMs?: number; ventureField?: string };
|
|
18
|
+
}
|
|
19
|
+
const { assetRequest, leadCapture } = Astro.props;
|
|
20
|
+
const minSubmitMs = leadCapture.minSubmitMs ?? 2000;
|
|
21
|
+
const field = 'w-full px-3 py-2 rounded-md border border-ink/20 bg-canvas text-ink';
|
|
22
|
+
---
|
|
23
|
+
<form
|
|
24
|
+
class="asset-request-form max-w-md space-y-4 text-left"
|
|
25
|
+
data-endpoint={leadCapture.assetRequestEndpoint}
|
|
26
|
+
data-asset-ref={assetRequest.assetRef}
|
|
27
|
+
data-venture={leadCapture.ventureField}
|
|
28
|
+
data-honeypot={leadCapture.honeypotField}
|
|
29
|
+
data-min-submit-ms={minSubmitMs}
|
|
30
|
+
>
|
|
31
|
+
<div class="grid grid-cols-2 gap-3">
|
|
32
|
+
<div>
|
|
33
|
+
<label class="block text-sm font-medium mb-1" for={`ar-first-${assetRequest.assetRef}`}>First name</label>
|
|
34
|
+
<input id={`ar-first-${assetRequest.assetRef}`} name="firstName" type="text" required maxlength="100" autocomplete="given-name" class={field} />
|
|
35
|
+
</div>
|
|
36
|
+
<div>
|
|
37
|
+
<label class="block text-sm font-medium mb-1" for={`ar-last-${assetRequest.assetRef}`}>Last name</label>
|
|
38
|
+
<input id={`ar-last-${assetRequest.assetRef}`} name="lastName" type="text" required maxlength="100" autocomplete="family-name" class={field} />
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
<div>
|
|
42
|
+
<label class="block text-sm font-medium mb-1" for={`ar-email-${assetRequest.assetRef}`}>Work email</label>
|
|
43
|
+
<input id={`ar-email-${assetRequest.assetRef}`} name="email" type="email" required maxlength="255" autocomplete="email" class={field} />
|
|
44
|
+
</div>
|
|
45
|
+
<div>
|
|
46
|
+
<label class="block text-sm font-medium mb-1" for={`ar-company-${assetRequest.assetRef}`}>Company</label>
|
|
47
|
+
<input id={`ar-company-${assetRequest.assetRef}`} name="company" type="text" maxlength="255" autocomplete="organization" class={field} />
|
|
48
|
+
</div>
|
|
49
|
+
<div>
|
|
50
|
+
<label class="block text-sm font-medium mb-1" for={`ar-role-${assetRequest.assetRef}`}>Role</label>
|
|
51
|
+
<select id={`ar-role-${assetRequest.assetRef}`} name="persona" class={field}>
|
|
52
|
+
{PERSONAS.map((p) => <option value={p.value} selected={p.value === 'unclassified'}>{p.label}</option>)}
|
|
53
|
+
</select>
|
|
54
|
+
</div>
|
|
55
|
+
<label class="flex gap-2 items-start text-sm">
|
|
56
|
+
<input name="seriesOptIn" type="checkbox" class="mt-1" />
|
|
57
|
+
<span>Send me the rest of the series as it comes out.</span>
|
|
58
|
+
</label>
|
|
59
|
+
<label class="flex gap-2 items-start text-sm">
|
|
60
|
+
<input name="discuss" type="checkbox" class="mt-1" />
|
|
61
|
+
<span>I'd like to discuss this with LuhTech.</span>
|
|
62
|
+
</label>
|
|
63
|
+
{assetRequest.requestPrompt && (
|
|
64
|
+
<div>
|
|
65
|
+
<label class="block text-sm font-medium mb-1" for={`ar-answer-${assetRequest.assetRef}`}>{assetRequest.requestPrompt}</label>
|
|
66
|
+
<textarea id={`ar-answer-${assetRequest.assetRef}`} name="answer" rows="3" maxlength="4000" class={field}></textarea>
|
|
67
|
+
</div>
|
|
68
|
+
)}
|
|
69
|
+
<div class="hidden" aria-hidden="true">
|
|
70
|
+
<label for={`ar-${leadCapture.honeypotField}-${assetRequest.assetRef}`}>Website</label>
|
|
71
|
+
<input id={`ar-${leadCapture.honeypotField}-${assetRequest.assetRef}`} name={leadCapture.honeypotField} type="text" tabindex="-1" autocomplete="off" />
|
|
72
|
+
</div>
|
|
73
|
+
<button type="submit" class="px-5 py-2.5 rounded-md bg-accent-primary text-canvas font-medium transition-all duration-200 hover:opacity-90 disabled:opacity-50 focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent-secondary focus-visible:rounded">
|
|
74
|
+
Send me the paper
|
|
75
|
+
</button>
|
|
76
|
+
<p class="asset-request-status text-sm" role="status" aria-live="polite"></p>
|
|
77
|
+
</form>
|
|
78
|
+
|
|
79
|
+
<script>
|
|
80
|
+
import { assetRequestBody, contentRequestBody, requestEndpointFor } from '../lib/assetRequest.ts';
|
|
81
|
+
|
|
82
|
+
for (const form of document.querySelectorAll<HTMLFormElement>('form.asset-request-form')) {
|
|
83
|
+
const status = form.querySelector('.asset-request-status') as HTMLParagraphElement;
|
|
84
|
+
const loadedAt = Date.now();
|
|
85
|
+
const endpoint = form.dataset.endpoint!;
|
|
86
|
+
const honeypot = form.dataset.honeypot!;
|
|
87
|
+
const minSubmitMs = Number(form.dataset.minSubmitMs ?? '2000');
|
|
88
|
+
|
|
89
|
+
form.addEventListener('submit', async (e) => {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
const data = new FormData(form);
|
|
92
|
+
if ((data.get(honeypot) as string)?.length > 0) return;
|
|
93
|
+
if (Date.now() - loadedAt < minSubmitMs) return;
|
|
94
|
+
|
|
95
|
+
const button = form.querySelector('button[type="submit"]') as HTMLButtonElement;
|
|
96
|
+
button.disabled = true;
|
|
97
|
+
status.textContent = 'Sending...';
|
|
98
|
+
|
|
99
|
+
const input = {
|
|
100
|
+
firstName: String(data.get('firstName') ?? ''),
|
|
101
|
+
lastName: String(data.get('lastName') ?? ''),
|
|
102
|
+
email: String(data.get('email') ?? ''),
|
|
103
|
+
company: String(data.get('company') ?? ''),
|
|
104
|
+
persona: String(data.get('persona') ?? 'unclassified'),
|
|
105
|
+
seriesOptIn: data.get('seriesOptIn') === 'on',
|
|
106
|
+
discuss: data.get('discuss') === 'on',
|
|
107
|
+
answer: String(data.get('answer') ?? ''),
|
|
108
|
+
};
|
|
109
|
+
const ctx = {
|
|
110
|
+
assetRef: form.dataset.assetRef!,
|
|
111
|
+
search: window.location.search,
|
|
112
|
+
pathname: window.location.pathname,
|
|
113
|
+
ventureRef: form.dataset.venture || undefined,
|
|
114
|
+
};
|
|
115
|
+
const post = (url: string, body: unknown) =>
|
|
116
|
+
fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
const res = await post(endpoint, assetRequestBody(input, ctx));
|
|
120
|
+
if (!res.ok) throw new Error(String(res.status));
|
|
121
|
+
const request = contentRequestBody(input, ctx);
|
|
122
|
+
if (request) await post(requestEndpointFor(endpoint), request).catch(() => undefined);
|
|
123
|
+
status.textContent = request
|
|
124
|
+
? "Check your inbox -- the link works for seven days. We'll be in touch about your question."
|
|
125
|
+
: 'Check your inbox -- the link works for seven days.';
|
|
126
|
+
form.reset();
|
|
127
|
+
} catch {
|
|
128
|
+
status.textContent = 'Something went wrong. Try again in a moment.';
|
|
129
|
+
button.disabled = false;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
</script>
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
---
|
|
2
|
+
// d-2026-10-02-st-paper-landing-three-actions. The paper's one page
|
|
3
|
+
// (/papers/<slug>/): its open summary and figures (rendered through the same
|
|
4
|
+
// section components as the landing page it replaces,
|
|
5
|
+
// d-2026-10-01-eb-whitepaper-hybrid-gate), then three actions.
|
|
6
|
+
//
|
|
7
|
+
// - Download: arriving with ?t=<token> (the delivery email's link) it links
|
|
8
|
+
// to the gateway's download route, ${assetRequestEndpoint}/<token>, which
|
|
9
|
+
// records the open and stamps through business-tools. Otherwise it shows
|
|
10
|
+
// the asset request form; arriving with ?c=<code> the request names that
|
|
11
|
+
// code as referredByCode (AssetRequestForm / assetRequest.ts).
|
|
12
|
+
// - Feedback (#feedback): the record's feedbackForm, behind a Cloudflare
|
|
13
|
+
// Turnstile challenge, posted to site.leadCapture.feedbackEndpoint. Name and
|
|
14
|
+
// email are asked on both arrivals. Without a feedbackEndpoint and a
|
|
15
|
+
// turnstileSiteKey in site config (site.schema.json 1.4.0) it says plainly
|
|
16
|
+
// that feedback is not open yet. The fragment is an anchor only; the token
|
|
17
|
+
// stays in the query.
|
|
18
|
+
// - Share: the page URL with no query or fragment -- never a token or code.
|
|
19
|
+
//
|
|
20
|
+
// Turnstile, implicit rendering (developers.cloudflare.com/turnstile/get-started/
|
|
21
|
+
// client-side-rendering/, read 2026-10-02): the api.js script from
|
|
22
|
+
// challenges.cloudflare.com, a <div class="cf-turnstile" data-sitekey> inside
|
|
23
|
+
// the form, and the token in the hidden input cf-turnstile-response it adds.
|
|
24
|
+
// Tokens are single-use, so the widget is reset after every attempt.
|
|
25
|
+
import Section from './Section.astro';
|
|
26
|
+
import AssetRequestForm from './AssetRequestForm.astro';
|
|
27
|
+
import {
|
|
28
|
+
feedbackOpen,
|
|
29
|
+
linkedInShareUrl,
|
|
30
|
+
mailtoShareUrl,
|
|
31
|
+
paperSections,
|
|
32
|
+
shareUrlFor,
|
|
33
|
+
type PaperRecord,
|
|
34
|
+
} from '../lib/paperLanding.ts';
|
|
35
|
+
|
|
36
|
+
export interface Props {
|
|
37
|
+
paper: PaperRecord;
|
|
38
|
+
slug: string;
|
|
39
|
+
site: { leadCapture: { assetRequestEndpoint?: string; feedbackEndpoint?: string; turnstileSiteKey?: string; honeypotField: string; minSubmitMs?: number; ventureField?: string; [k: string]: unknown } };
|
|
40
|
+
route?: string;
|
|
41
|
+
}
|
|
42
|
+
const { paper, slug, site } = Astro.props;
|
|
43
|
+
const route = Astro.props.route ?? `/papers/${slug}/`;
|
|
44
|
+
const leadCapture = site.leadCapture;
|
|
45
|
+
if (!paper.pdfAssetRef) throw new Error(`PaperLanding: paper ${slug} has no pdfAssetRef`);
|
|
46
|
+
if (!leadCapture?.assetRequestEndpoint) throw new Error(`PaperLanding: site.leadCapture has no assetRequestEndpoint for paper ${slug}`);
|
|
47
|
+
|
|
48
|
+
const sections = paperSections(paper, slug);
|
|
49
|
+
const shareUrl = shareUrlFor(new URL(route, Astro.site ?? Astro.url).href);
|
|
50
|
+
const form = paper.feedbackForm;
|
|
51
|
+
const open = feedbackOpen(leadCapture) && Boolean(form);
|
|
52
|
+
const field = 'w-full px-3 py-2 rounded-md border border-ink/20 bg-canvas text-ink';
|
|
53
|
+
const button = 'px-5 py-2.5 rounded-md bg-accent-primary text-canvas font-medium transition-all duration-200 hover:opacity-90 disabled:opacity-50 focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent-secondary focus-visible:rounded';
|
|
54
|
+
const secondary = 'px-4 py-2 rounded-md border border-ink/20 text-ink font-medium hover:border-accent-primary';
|
|
55
|
+
---
|
|
56
|
+
<div class="paper-landing" data-asset-request-endpoint={leadCapture.assetRequestEndpoint}>
|
|
57
|
+
{sections.map((s) => <Section section={s} site={site} />)}
|
|
58
|
+
|
|
59
|
+
<section id="download" class="py-12 border-t border-ink/10" data-reveal>
|
|
60
|
+
<h2 class="font-display text-2xl font-bold mb-4">Download</h2>
|
|
61
|
+
<div class="paper-download-link" hidden>
|
|
62
|
+
<a class={`${button} inline-block`} href="#download" rel="nofollow">Download the paper</a>
|
|
63
|
+
</div>
|
|
64
|
+
<div class="paper-download-request max-w-md">
|
|
65
|
+
<AssetRequestForm assetRequest={{ assetRef: paper.pdfAssetRef }} leadCapture={leadCapture as any} />
|
|
66
|
+
</div>
|
|
67
|
+
</section>
|
|
68
|
+
|
|
69
|
+
<section id="feedback" class="py-12 border-t border-ink/10" data-reveal>
|
|
70
|
+
<h2 class="font-display text-2xl font-bold mb-4">Feedback</h2>
|
|
71
|
+
{open && form ? (
|
|
72
|
+
<>
|
|
73
|
+
<p class="paper-feedback-needs-arrival text-sm opacity-80">Feedback opens from the link in your email or the code on your copy of the paper.</p>
|
|
74
|
+
<form
|
|
75
|
+
class="paper-feedback-form max-w-xl space-y-4"
|
|
76
|
+
hidden
|
|
77
|
+
data-endpoint={leadCapture.feedbackEndpoint}
|
|
78
|
+
data-asset-ref={paper.pdfAssetRef}
|
|
79
|
+
>
|
|
80
|
+
<div>
|
|
81
|
+
<label class="block text-sm font-medium mb-1" for="pf-role">Your role</label>
|
|
82
|
+
<select id="pf-role" name="roleId" required class={field}>
|
|
83
|
+
{form.roles.map((r, i) => <option value={r.roleId} selected={i === 0}>{r.label}</option>)}
|
|
84
|
+
</select>
|
|
85
|
+
</div>
|
|
86
|
+
{form.questions.map((q) => (
|
|
87
|
+
<div data-question-id={q.questionId}>
|
|
88
|
+
<label class="block text-sm font-medium mb-1" for={`pf-q-${q.questionId}`}>{q.prompt}</label>
|
|
89
|
+
{q.answerType === 'choice' ? (
|
|
90
|
+
<>
|
|
91
|
+
<select id={`pf-q-${q.questionId}`} name={`answer:${q.questionId}`} class={field}>
|
|
92
|
+
<option value="" selected></option>
|
|
93
|
+
{(q.choices ?? []).map((c) => <option value={c.choiceId}>{c.label}</option>)}
|
|
94
|
+
</select>
|
|
95
|
+
{q.allowOther && (
|
|
96
|
+
<input name={`other:${q.questionId}`} type="text" maxlength="4000" aria-label={`${q.prompt} (other)`} class={`${field} mt-2`} />
|
|
97
|
+
)}
|
|
98
|
+
</>
|
|
99
|
+
) : (
|
|
100
|
+
<textarea id={`pf-q-${q.questionId}`} name={`answer:${q.questionId}`} rows="3" maxlength="4000" class={field}></textarea>
|
|
101
|
+
)}
|
|
102
|
+
</div>
|
|
103
|
+
))}
|
|
104
|
+
<div class="grid grid-cols-2 gap-3">
|
|
105
|
+
<div>
|
|
106
|
+
<label class="block text-sm font-medium mb-1" for="pf-first">First name</label>
|
|
107
|
+
<input id="pf-first" name="firstName" type="text" required maxlength="100" autocomplete="given-name" class={field} />
|
|
108
|
+
</div>
|
|
109
|
+
<div>
|
|
110
|
+
<label class="block text-sm font-medium mb-1" for="pf-last">Last name</label>
|
|
111
|
+
<input id="pf-last" name="lastName" type="text" required maxlength="100" autocomplete="family-name" class={field} />
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
<div>
|
|
115
|
+
<label class="block text-sm font-medium mb-1" for="pf-email">Email</label>
|
|
116
|
+
<input id="pf-email" name="email" type="email" required maxlength="255" autocomplete="email" class={field} />
|
|
117
|
+
</div>
|
|
118
|
+
<div>
|
|
119
|
+
<label class="block text-sm font-medium mb-1" for="pf-company">Company</label>
|
|
120
|
+
<input id="pf-company" name="company" type="text" maxlength="255" autocomplete="organization" class={field} />
|
|
121
|
+
</div>
|
|
122
|
+
<label class="flex gap-2 items-start text-sm">
|
|
123
|
+
<input name="publishConsent" type="checkbox" class="mt-1" />
|
|
124
|
+
<span>LuhTech may publish my answers.</span>
|
|
125
|
+
</label>
|
|
126
|
+
<div class="cf-turnstile" data-sitekey={leadCapture.turnstileSiteKey}></div>
|
|
127
|
+
<button type="submit" class={button}>Send my answers</button>
|
|
128
|
+
<p class="paper-feedback-status text-sm" role="status" aria-live="polite"></p>
|
|
129
|
+
</form>
|
|
130
|
+
<script is:inline src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
|
|
131
|
+
</>
|
|
132
|
+
) : (
|
|
133
|
+
<p class="text-sm opacity-80">Feedback is not open yet.</p>
|
|
134
|
+
)}
|
|
135
|
+
</section>
|
|
136
|
+
|
|
137
|
+
<section id="share" class="py-12 border-t border-ink/10" data-reveal>
|
|
138
|
+
<h2 class="font-display text-2xl font-bold mb-4">Share</h2>
|
|
139
|
+
<div class="flex gap-3 flex-wrap items-center">
|
|
140
|
+
<button type="button" class={`paper-share-copy ${secondary}`} data-share-url={shareUrl}>Copy link</button>
|
|
141
|
+
<a class={secondary} href={linkedInShareUrl(shareUrl)} target="_blank" rel="noopener noreferrer">LinkedIn</a>
|
|
142
|
+
<a class={secondary} href={mailtoShareUrl(shareUrl, paper.title)}>Email</a>
|
|
143
|
+
<span class="paper-share-status text-sm" role="status" aria-live="polite"></span>
|
|
144
|
+
</div>
|
|
145
|
+
</section>
|
|
146
|
+
</div>
|
|
147
|
+
|
|
148
|
+
<script>
|
|
149
|
+
import { arrivalFrom, downloadUrlFor, feedbackBody, feedbackMessage } from '../lib/paperLanding.ts';
|
|
150
|
+
import { sourceRefFor } from '../lib/assetRequest.ts';
|
|
151
|
+
|
|
152
|
+
for (const root of document.querySelectorAll<HTMLElement>('.paper-landing')) {
|
|
153
|
+
const arrival = arrivalFrom(window.location.search);
|
|
154
|
+
|
|
155
|
+
// Download: a token links straight to the gateway's download route.
|
|
156
|
+
if (arrival.by === 'token') {
|
|
157
|
+
const link = root.querySelector<HTMLElement>('.paper-download-link');
|
|
158
|
+
const anchor = link?.querySelector('a');
|
|
159
|
+
if (link && anchor) {
|
|
160
|
+
anchor.href = downloadUrlFor(root.dataset.assetRequestEndpoint!, arrival.token);
|
|
161
|
+
link.hidden = false;
|
|
162
|
+
root.querySelector<HTMLElement>('.paper-download-request')!.hidden = true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Feedback: open to a reader who arrived by token or code.
|
|
167
|
+
const form = root.querySelector<HTMLFormElement>('form.paper-feedback-form');
|
|
168
|
+
if (form && arrival.by !== 'none') {
|
|
169
|
+
form.hidden = false;
|
|
170
|
+
root.querySelector<HTMLElement>('.paper-feedback-needs-arrival')!.hidden = true;
|
|
171
|
+
const status = form.querySelector('.paper-feedback-status') as HTMLParagraphElement;
|
|
172
|
+
form.addEventListener('submit', async (e) => {
|
|
173
|
+
e.preventDefault();
|
|
174
|
+
const data = new FormData(form);
|
|
175
|
+
const turnstileToken = String(data.get('cf-turnstile-response') ?? '');
|
|
176
|
+
if (!turnstileToken) {
|
|
177
|
+
status.textContent = 'Complete the challenge first.';
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const answers: Record<string, string> = {};
|
|
181
|
+
for (const [k, v] of data.entries()) {
|
|
182
|
+
if (k.startsWith('answer:')) answers[k.slice(7)] = String(v);
|
|
183
|
+
}
|
|
184
|
+
for (const [k, v] of data.entries()) {
|
|
185
|
+
if (k.startsWith('other:') && String(v).trim()) answers[k.slice(6)] = String(v);
|
|
186
|
+
}
|
|
187
|
+
const body = feedbackBody(
|
|
188
|
+
{
|
|
189
|
+
roleId: String(data.get('roleId') ?? ''),
|
|
190
|
+
answers,
|
|
191
|
+
publishConsent: data.get('publishConsent') === 'on',
|
|
192
|
+
firstName: String(data.get('firstName') ?? ''),
|
|
193
|
+
lastName: String(data.get('lastName') ?? ''),
|
|
194
|
+
email: String(data.get('email') ?? ''),
|
|
195
|
+
company: String(data.get('company') ?? ''),
|
|
196
|
+
turnstileToken,
|
|
197
|
+
},
|
|
198
|
+
{ assetRef: form.dataset.assetRef!, arrival, sourceRef: sourceRefFor('', window.location.pathname) }
|
|
199
|
+
);
|
|
200
|
+
if (!body) return;
|
|
201
|
+
if (Object.keys(body.answers).length === 0) {
|
|
202
|
+
status.textContent = 'Answer at least one question.';
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const button = form.querySelector('button[type="submit"]') as HTMLButtonElement;
|
|
206
|
+
button.disabled = true;
|
|
207
|
+
status.textContent = 'Sending...';
|
|
208
|
+
try {
|
|
209
|
+
const res = await fetch(form.dataset.endpoint!, {
|
|
210
|
+
method: 'POST',
|
|
211
|
+
headers: { 'Content-Type': 'application/json' },
|
|
212
|
+
body: JSON.stringify(body),
|
|
213
|
+
});
|
|
214
|
+
const json = (await res.json().catch(() => ({}))) as { error?: string };
|
|
215
|
+
status.textContent = feedbackMessage(res.status, json.error);
|
|
216
|
+
if (res.status === 201) form.reset();
|
|
217
|
+
} catch {
|
|
218
|
+
status.textContent = feedbackMessage(0);
|
|
219
|
+
}
|
|
220
|
+
button.disabled = false;
|
|
221
|
+
(window as unknown as { turnstile?: { reset: () => void } }).turnstile?.reset();
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Share: copy the non-personal link the button carries.
|
|
226
|
+
const copy = root.querySelector<HTMLButtonElement>('.paper-share-copy');
|
|
227
|
+
const shareStatus = root.querySelector('.paper-share-status') as HTMLSpanElement;
|
|
228
|
+
copy?.addEventListener('click', async () => {
|
|
229
|
+
try {
|
|
230
|
+
await navigator.clipboard.writeText(copy.dataset.shareUrl!);
|
|
231
|
+
shareStatus.textContent = 'Link copied.';
|
|
232
|
+
} catch {
|
|
233
|
+
shareStatus.textContent = copy.dataset.shareUrl!;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// #feedback lands on the Feedback action once the arrival has shown or hidden its parts.
|
|
238
|
+
if (window.location.hash === '#feedback') {
|
|
239
|
+
root.querySelector('#feedback')?.scrollIntoView();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
</script>
|
|
@@ -9,23 +9,35 @@
|
|
|
9
9
|
// heading and a dead-end button).
|
|
10
10
|
import Block from '../Block.astro';
|
|
11
11
|
import CtaLink from '../CtaLink.astro';
|
|
12
|
+
import AssetRequestForm from '../AssetRequestForm.astro';
|
|
12
13
|
import LeadCaptureForm from '../LeadCaptureForm.astro';
|
|
13
14
|
import SectionHeading from '../SectionHeading.astro';
|
|
14
15
|
import type { SectionIcons } from '../Section.astro';
|
|
15
16
|
|
|
16
17
|
export interface Props {
|
|
17
18
|
section: any;
|
|
18
|
-
leadCapture?: { destination: string; source: string; ventureField: string; honeypotField: string; minSubmitMs?: number };
|
|
19
|
+
leadCapture?: { destination: string; source: string; ventureField: string; honeypotField: string; minSubmitMs?: number; assetRequestEndpoint?: string; toolSubmitEndpoint?: string };
|
|
19
20
|
companyLabel?: string;
|
|
20
21
|
icons?: SectionIcons;
|
|
21
22
|
}
|
|
22
23
|
const { section, leadCapture, companyLabel, icons } = Astro.props;
|
|
23
24
|
const sectionIcon = icons?.section?.[section.sectionId];
|
|
25
|
+
// A gated asset cta with nowhere to post would render a form that silently
|
|
26
|
+
// fails -- refuse the build instead.
|
|
27
|
+
if (section.assetRequest && !leadCapture?.assetRequestEndpoint) {
|
|
28
|
+
throw new Error(`Cta.astro: section ${section.sectionId} carries assetRequest but site.leadCapture has no assetRequestEndpoint`);
|
|
29
|
+
}
|
|
24
30
|
---
|
|
25
31
|
<section id={section.sectionId} class="py-12 text-center border-t border-ink/10" data-reveal>
|
|
26
32
|
<SectionHeading eyebrow={section.eyebrow} heading={section.heading} subheading={section.subheading} icon={sectionIcon} center class="mb-3" />
|
|
27
33
|
{section.blocks?.map((b: any) => <Block block={b} class="mb-4 max-w-xl mx-auto text-left" />)}
|
|
28
|
-
{leadCapture ? (
|
|
34
|
+
{section.assetRequest && leadCapture?.assetRequestEndpoint ? (
|
|
35
|
+
// d-2026-10-01-st-asset-request-form: a gated asset cta (page.schema.json
|
|
36
|
+
// v2.5.0 assetRequest) renders the asset form against the capture service.
|
|
37
|
+
<div class="text-left max-w-md mx-auto">
|
|
38
|
+
<AssetRequestForm assetRequest={section.assetRequest} leadCapture={leadCapture as any} />
|
|
39
|
+
</div>
|
|
40
|
+
) : leadCapture ? (
|
|
29
41
|
<div class="text-left max-w-md mx-auto">
|
|
30
42
|
<LeadCaptureForm leadCapture={leadCapture} heading="" companyLabel={companyLabel} />
|
|
31
43
|
</div>
|
package/src/content/loadPage.ts
CHANGED
|
@@ -3,7 +3,7 @@ import Ajv from 'ajv';
|
|
|
3
3
|
import addFormats from 'ajv-formats';
|
|
4
4
|
import { fetchSchema, fetchSupportSchema } from './schemaFetch.js';
|
|
5
5
|
|
|
6
|
-
const PAGE_PIN = '2.
|
|
6
|
+
const PAGE_PIN = '2.5.0';
|
|
7
7
|
const CAPABILITY_CLAIM_PIN = '0.2.0';
|
|
8
8
|
|
|
9
9
|
let validatorPromise: ReturnType<typeof buildValidator> | null = null;
|
package/src/content/loadSite.ts
CHANGED
package/src/content/loadTool.ts
CHANGED
|
@@ -3,7 +3,8 @@ import Ajv from 'ajv';
|
|
|
3
3
|
import addFormats from 'ajv-formats';
|
|
4
4
|
import { fetchSchema, fetchSupportSchema } from './schemaFetch.js';
|
|
5
5
|
|
|
6
|
-
const TOOL_PIN = '1.
|
|
6
|
+
const TOOL_PIN = '1.2.0';
|
|
7
|
+
const CAPABILITY_CLAIM_PIN = '0.2.0';
|
|
7
8
|
|
|
8
9
|
let validatorPromise: ReturnType<typeof buildValidator> | null = null;
|
|
9
10
|
|
|
@@ -11,14 +12,28 @@ async function buildValidator() {
|
|
|
11
12
|
const ajv = new Ajv({ strict: false, allErrors: true });
|
|
12
13
|
addFormats(ajv);
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
// tool.schema.json 1.2.0 adopts the content spine (cell refs, themes,
|
|
16
|
+
// strategy) and forbids audit-paint field names, so its $ref chain now
|
|
17
|
+
// reaches cell, content-spine (which itself $refs capability-claim) and
|
|
18
|
+
// forbidden-audit-paint-names -- found building LuhTech-Business's /tools/
|
|
19
|
+
// route against the 1.2.0 pin, which failed "can't resolve reference".
|
|
20
|
+
const [toolSchema, capabilityClaimSchema, definitionsSchema, graphSchema, cellSchema, contentSpineSchema, forbiddenNamesSchema] =
|
|
21
|
+
await Promise.all([
|
|
22
|
+
fetchSchema('content/tool.schema.json', TOOL_PIN),
|
|
23
|
+
fetchSchema('content/capability-claim.schema.json', CAPABILITY_CLAIM_PIN),
|
|
24
|
+
fetchSupportSchema('_definitions/definitions.schema.json'),
|
|
25
|
+
fetchSupportSchema('_definitions/graph.schema.json'),
|
|
26
|
+
fetchSupportSchema('_definitions/cell.schema.json'),
|
|
27
|
+
fetchSupportSchema('_definitions/content-spine.schema.json'),
|
|
28
|
+
fetchSupportSchema('_definitions/forbidden-audit-paint-names.schema.json'),
|
|
29
|
+
]);
|
|
19
30
|
|
|
31
|
+
ajv.addSchema(capabilityClaimSchema as object);
|
|
20
32
|
ajv.addSchema(definitionsSchema as object);
|
|
21
33
|
ajv.addSchema(graphSchema as object);
|
|
34
|
+
ajv.addSchema(cellSchema as object);
|
|
35
|
+
ajv.addSchema(contentSpineSchema as object);
|
|
36
|
+
ajv.addSchema(forbiddenNamesSchema as object);
|
|
22
37
|
|
|
23
38
|
return ajv.compile(toolSchema as object);
|
|
24
39
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// d-2026-10-01-st-asset-request-form: the request a gated asset form sends
|
|
2
|
+
// to the capture service (Ectropy-Business POST /api/tools/submissions/assets
|
|
3
|
+
// and /requests, d-2026-10-01-eb-capture-service-assets-and-requests). Pure,
|
|
4
|
+
// so the form's script and the tests share one implementation.
|
|
5
|
+
|
|
6
|
+
/** Persona values the form offers (crm/persona-classification plus the form default). */
|
|
7
|
+
export const PERSONAS = [
|
|
8
|
+
{ value: 'unclassified', label: 'Prefer not to say' },
|
|
9
|
+
{ value: 'owner', label: 'Owner or developer' },
|
|
10
|
+
{ value: 'gc', label: 'General contractor' },
|
|
11
|
+
{ value: 'architect', label: 'Architect or engineer' },
|
|
12
|
+
{ value: 'sub', label: 'Specialty contractor' },
|
|
13
|
+
{ value: 'super', label: 'Superintendent' },
|
|
14
|
+
{ value: 'gov', label: 'Public agency' },
|
|
15
|
+
] as const;
|
|
16
|
+
|
|
17
|
+
const UTM_KEYS = ['source', 'medium', 'campaign', 'content', 'term'] as const;
|
|
18
|
+
const SOURCE_REF = /^(article:[a-z0-9]+(-[a-z0-9]+)*|post:[A-Za-z0-9:_-]+|page:[a-z0-9]+(-[a-z0-9]+)*)$/;
|
|
19
|
+
|
|
20
|
+
/** utm_source=... -> { source: ... }, the five standard keys only. */
|
|
21
|
+
export function utmFromSearch(search: string): Record<string, string> | undefined {
|
|
22
|
+
const params = new URLSearchParams(search);
|
|
23
|
+
const utm: Record<string, string> = {};
|
|
24
|
+
for (const k of UTM_KEYS) {
|
|
25
|
+
const v = params.get(`utm_${k}`);
|
|
26
|
+
if (v) utm[k] = v.slice(0, 200);
|
|
27
|
+
}
|
|
28
|
+
return Object.keys(utm).length ? utm : undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Where the visitor came from: an explicit ?src=post:<id> or article:<slug>
|
|
33
|
+
* the post's own link carries, else this page (page:<last path segment>).
|
|
34
|
+
*/
|
|
35
|
+
export function sourceRefFor(search: string, pathname: string): string {
|
|
36
|
+
const src = new URLSearchParams(search).get('src');
|
|
37
|
+
if (src && SOURCE_REF.test(src)) return src;
|
|
38
|
+
const slug = pathname.split('/').filter(Boolean).pop() ?? 'home';
|
|
39
|
+
const pageRef = `page:${slug.toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '') || 'home'}`;
|
|
40
|
+
return SOURCE_REF.test(pageRef) ? pageRef : 'page:home';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The code a scanned or forwarded copy carried (?c=<code>), sent as
|
|
45
|
+
* referredByCode so the request is attributed to it
|
|
46
|
+
* (d-2026-10-02-eb-asset-request-referred-by-code). Undefined when absent or
|
|
47
|
+
* malformed (gateway pattern ^[A-Za-z0-9_-]{4,64}$).
|
|
48
|
+
*/
|
|
49
|
+
export function referredByCodeFrom(search: string): string | undefined {
|
|
50
|
+
const c = new URLSearchParams(search).get('c');
|
|
51
|
+
return c && /^[A-Za-z0-9_-]{4,64}$/.test(c) ? c : undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The /requests endpoint beside the /assets endpoint the site config names. */
|
|
55
|
+
export function requestEndpointFor(assetRequestEndpoint: string): string {
|
|
56
|
+
return assetRequestEndpoint.replace(/\/assets\/?$/, '/requests');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface AssetFormInput {
|
|
60
|
+
firstName: string;
|
|
61
|
+
lastName: string;
|
|
62
|
+
email: string;
|
|
63
|
+
company?: string;
|
|
64
|
+
persona: string;
|
|
65
|
+
seriesOptIn: boolean;
|
|
66
|
+
discuss: boolean;
|
|
67
|
+
answer?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface AssetContext {
|
|
71
|
+
assetRef: string;
|
|
72
|
+
search: string;
|
|
73
|
+
pathname: string;
|
|
74
|
+
ventureRef?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The asset request body. */
|
|
78
|
+
export function assetRequestBody(input: AssetFormInput, ctx: AssetContext) {
|
|
79
|
+
const utm = utmFromSearch(ctx.search);
|
|
80
|
+
const referredByCode = referredByCodeFrom(ctx.search);
|
|
81
|
+
return {
|
|
82
|
+
assetRef: ctx.assetRef,
|
|
83
|
+
sourceRef: sourceRefFor(ctx.search, ctx.pathname),
|
|
84
|
+
route: ctx.pathname,
|
|
85
|
+
...(ctx.ventureRef ? { ventureRef: ctx.ventureRef } : {}),
|
|
86
|
+
persona: PERSONAS.some((p) => p.value === input.persona) ? input.persona : 'unclassified',
|
|
87
|
+
seriesOptIn: input.seriesOptIn === true,
|
|
88
|
+
...(utm ? { utm } : {}),
|
|
89
|
+
...(referredByCode ? { referredByCode } : {}),
|
|
90
|
+
contact: {
|
|
91
|
+
firstName: input.firstName.trim(),
|
|
92
|
+
lastName: input.lastName.trim(),
|
|
93
|
+
email: input.email.trim(),
|
|
94
|
+
...(input.company?.trim() ? { company: input.company.trim() } : {}),
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The request body when the visitor ticks "discuss this with us" -- null when they do not. */
|
|
100
|
+
export function contentRequestBody(input: AssetFormInput, ctx: AssetContext) {
|
|
101
|
+
if (!input.discuss) return null;
|
|
102
|
+
const asset = assetRequestBody(input, ctx);
|
|
103
|
+
const { seriesOptIn: _optIn, ...rest } = asset;
|
|
104
|
+
return {
|
|
105
|
+
...rest,
|
|
106
|
+
requestKind: 'whitepaper' as const,
|
|
107
|
+
...(input.answer?.trim() ? { message: input.answer.trim().slice(0, 4000) } : {}),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// d-2026-10-02-st-paper-landing-three-actions: the paper's one page
|
|
2
|
+
// (/papers/<slug>/) -- its open summary and figures, then Download, Feedback
|
|
3
|
+
// and Share. It reads the whitepaper record (schema-registry
|
|
4
|
+
// content/whitepaper.schema.json 1.3.0). Pure, so the page's script and the
|
|
5
|
+
// tests share one implementation.
|
|
6
|
+
|
|
7
|
+
/** Whitepaper statuses that put a paper's page on the site (L4 approves the final paper first). */
|
|
8
|
+
export const PAPER_LIVE_STATUSES = ['APPROVED', 'COMPLETE'] as const;
|
|
9
|
+
|
|
10
|
+
export function isPaperLive(status: unknown): boolean {
|
|
11
|
+
return (PAPER_LIVE_STATUSES as readonly unknown[]).includes(status);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** The gateway's delivery token (tool-submission.routes.ts GET /assets/:token). */
|
|
15
|
+
export const TOKEN_PATTERN = /^[A-Za-z0-9_-]{43}$/;
|
|
16
|
+
/** A printed or forwarded copy's code (business-tools link-codes.ts CODE_PATTERN). */
|
|
17
|
+
export const CODE_PATTERN = /^[A-Za-z0-9_-]{4,64}$/;
|
|
18
|
+
|
|
19
|
+
export type Arrival = { by: 'token'; token: string } | { by: 'code'; code: string } | { by: 'none' };
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* How the visitor arrived: ?t=<token> from the delivery email, ?c=<code> from
|
|
23
|
+
* a scanned or forwarded copy, else neither. A malformed value counts as none.
|
|
24
|
+
*/
|
|
25
|
+
export function arrivalFrom(search: string): Arrival {
|
|
26
|
+
const params = new URLSearchParams(search);
|
|
27
|
+
const t = params.get('t');
|
|
28
|
+
if (t && TOKEN_PATTERN.test(t)) return { by: 'token', token: t };
|
|
29
|
+
const c = params.get('c');
|
|
30
|
+
if (c && CODE_PATTERN.test(c)) return { by: 'code', code: c };
|
|
31
|
+
return { by: 'none' };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The gateway's download route beside the asset request endpoint the site config names. */
|
|
35
|
+
export function downloadUrlFor(assetRequestEndpoint: string, token: string): string {
|
|
36
|
+
return `${assetRequestEndpoint.replace(/\/+$/, '')}/${encodeURIComponent(token)}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The non-personal link to share: the page URL with no query and no fragment, so never a token or code. */
|
|
40
|
+
export function shareUrlFor(pageUrl: string): string {
|
|
41
|
+
const u = new URL(pageUrl);
|
|
42
|
+
return `${u.origin}${u.pathname}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function linkedInShareUrl(shareUrl: string): string {
|
|
46
|
+
return `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(shareUrl)}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function mailtoShareUrl(shareUrl: string, title: string): string {
|
|
50
|
+
return `mailto:?subject=${encodeURIComponent(title)}&body=${encodeURIComponent(shareUrl)}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The Feedback form is open only when the site config names both its endpoint and its Turnstile site key. */
|
|
54
|
+
export function feedbackOpen(leadCapture: { feedbackEndpoint?: string; turnstileSiteKey?: string } | undefined): boolean {
|
|
55
|
+
return Boolean(leadCapture?.feedbackEndpoint && leadCapture?.turnstileSiteKey);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface FeedbackInput {
|
|
59
|
+
roleId: string;
|
|
60
|
+
answers: Record<string, string>;
|
|
61
|
+
publishConsent: boolean;
|
|
62
|
+
firstName: string;
|
|
63
|
+
lastName: string;
|
|
64
|
+
email: string;
|
|
65
|
+
company?: string;
|
|
66
|
+
turnstileToken: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The body business-tools POST /api/public/papers/feedback takes
|
|
71
|
+
* (apps/dashboard/src/lib/paper-feedback.ts parseSubmission): answers keyed by
|
|
72
|
+
* questionId (blank ones left out), the role, the consent box, how the reader
|
|
73
|
+
* arrived (a code arrival names its code), name and email on both arrivals,
|
|
74
|
+
* and the Turnstile token. Null when the reader arrived by neither.
|
|
75
|
+
*/
|
|
76
|
+
export function feedbackBody(input: FeedbackInput, ctx: { assetRef: string; arrival: Arrival; sourceRef?: string }) {
|
|
77
|
+
if (ctx.arrival.by === 'none') return null;
|
|
78
|
+
const answers: Record<string, string> = {};
|
|
79
|
+
for (const [questionId, value] of Object.entries(input.answers)) {
|
|
80
|
+
const v = String(value ?? '').trim();
|
|
81
|
+
if (v) answers[questionId] = v.slice(0, 4000);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
assetRef: ctx.assetRef,
|
|
85
|
+
roleId: input.roleId,
|
|
86
|
+
answers,
|
|
87
|
+
publishConsent: input.publishConsent === true,
|
|
88
|
+
arrivedBy: ctx.arrival.by,
|
|
89
|
+
...(ctx.arrival.by === 'code' ? { code: ctx.arrival.code } : {}),
|
|
90
|
+
...(ctx.sourceRef ? { sourceRef: ctx.sourceRef } : {}),
|
|
91
|
+
contact: {
|
|
92
|
+
firstName: input.firstName.trim(),
|
|
93
|
+
lastName: input.lastName.trim(),
|
|
94
|
+
email: input.email.trim(),
|
|
95
|
+
...(input.company?.trim() ? { company: input.company.trim() } : {}),
|
|
96
|
+
},
|
|
97
|
+
turnstileToken: input.turnstileToken,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** What the reader is told for each answer the feedback endpoint can give. */
|
|
102
|
+
export function feedbackMessage(status: number, error?: string): string {
|
|
103
|
+
if (status === 201) return 'Thank you -- your answers reached us.';
|
|
104
|
+
if (status === 503) return 'Feedback is not open yet.';
|
|
105
|
+
if (status === 429) return 'Too many submissions from here; try again in an hour.';
|
|
106
|
+
if (status === 403) return 'The challenge did not pass; reload the page and try again.';
|
|
107
|
+
if (status === 400 && error) return error;
|
|
108
|
+
return 'Something went wrong. Try again in a moment.';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
interface PaperFigure {
|
|
112
|
+
figureId: string;
|
|
113
|
+
value: string;
|
|
114
|
+
unit?: string;
|
|
115
|
+
caption?: string;
|
|
116
|
+
estimate?: boolean;
|
|
117
|
+
provenance: { sourceRef: string; public: boolean; observedAt?: string };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface PaperRecord {
|
|
121
|
+
title: string;
|
|
122
|
+
subtitle?: string;
|
|
123
|
+
summary: string;
|
|
124
|
+
status: string;
|
|
125
|
+
figures?: PaperFigure[];
|
|
126
|
+
openFigureIds?: string[];
|
|
127
|
+
pdfAssetRef?: string;
|
|
128
|
+
feedbackForm?: {
|
|
129
|
+
roles: { roleId: string; label: string; persona?: string }[];
|
|
130
|
+
questions: { questionId: string; prompt: string; answerType: 'text' | 'choice'; choices?: { choiceId: string; label: string }[]; allowOther?: boolean }[];
|
|
131
|
+
};
|
|
132
|
+
[key: string]: unknown;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The paper's open summary and figures as page sections, so the page renders
|
|
137
|
+
* them through the same section components as the landing page it replaces
|
|
138
|
+
* (d-2026-10-01-eb-whitepaper-hybrid-gate): a hero with the summary's first
|
|
139
|
+
* paragraph, a summary section with the rest, and the open figures with
|
|
140
|
+
* their captions.
|
|
141
|
+
*/
|
|
142
|
+
export function paperSections(paper: PaperRecord, slug: string) {
|
|
143
|
+
const paragraphs = paper.summary.split(/\n\s*\n/).map((p) => p.trim()).filter(Boolean);
|
|
144
|
+
const [lede, ...rest] = paragraphs;
|
|
145
|
+
const open = (paper.openFigureIds ?? []).map((id) => {
|
|
146
|
+
const f = (paper.figures ?? []).find((x) => x.figureId === id);
|
|
147
|
+
if (!f) throw new Error(`paper ${slug}: openFigureIds names ${id}, which is not in figures[]`);
|
|
148
|
+
return f;
|
|
149
|
+
});
|
|
150
|
+
const sections: Record<string, unknown>[] = [
|
|
151
|
+
{
|
|
152
|
+
sectionId: slug,
|
|
153
|
+
sectionKind: 'hero',
|
|
154
|
+
heading: paper.title,
|
|
155
|
+
...(paper.subtitle ? { subheading: paper.subtitle } : {}),
|
|
156
|
+
...(lede ? { blocks: [{ blockType: 'lede', text: lede }] } : {}),
|
|
157
|
+
},
|
|
158
|
+
];
|
|
159
|
+
if (rest.length) {
|
|
160
|
+
sections.push({
|
|
161
|
+
sectionId: `${slug}-summary`,
|
|
162
|
+
sectionKind: 'approach',
|
|
163
|
+
heading: 'Summary',
|
|
164
|
+
blocks: rest.map((text) => ({ blockType: 'paragraph', text })),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (open.length) {
|
|
168
|
+
sections.push({
|
|
169
|
+
sectionId: `${slug}-figures`,
|
|
170
|
+
sectionKind: 'proof',
|
|
171
|
+
heading: 'What the paper finds',
|
|
172
|
+
blocks: open.filter((f) => f.caption).map((f) => ({ blockType: 'paragraph', text: f.caption })),
|
|
173
|
+
figures: open.map((f) => ({
|
|
174
|
+
figureId: f.figureId,
|
|
175
|
+
value: f.estimate && !/estimate/i.test(f.value) ? `${f.value} (estimate)` : f.value,
|
|
176
|
+
...(f.unit ? { unit: f.unit } : {}),
|
|
177
|
+
provenance: f.provenance,
|
|
178
|
+
})),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return sections;
|
|
182
|
+
}
|