@luhtech/site-template 0.16.0 → 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 +3 -2
- package/src/components/PaperLanding.astro +242 -0
- package/src/content/loadSite.ts +1 -1
- package/src/lib/assetRequest.ts +13 -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/*"
|
|
@@ -52,7 +53,7 @@
|
|
|
52
53
|
"luhtech": {
|
|
53
54
|
"schemaPins": {
|
|
54
55
|
"content/page.schema.json": "2.5.0",
|
|
55
|
-
"content/site.schema.json": "1.
|
|
56
|
+
"content/site.schema.json": "1.4.0",
|
|
56
57
|
"content/capability-claim.schema.json": "0.2.0",
|
|
57
58
|
"content/tool.schema.json": "1.2.0",
|
|
58
59
|
"portfolio/brand-identity.schema.json": "1.5.0"
|
|
@@ -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>
|
package/src/content/loadSite.ts
CHANGED
package/src/lib/assetRequest.ts
CHANGED
|
@@ -40,6 +40,17 @@ export function sourceRefFor(search: string, pathname: string): string {
|
|
|
40
40
|
return SOURCE_REF.test(pageRef) ? pageRef : 'page:home';
|
|
41
41
|
}
|
|
42
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
|
+
|
|
43
54
|
/** The /requests endpoint beside the /assets endpoint the site config names. */
|
|
44
55
|
export function requestEndpointFor(assetRequestEndpoint: string): string {
|
|
45
56
|
return assetRequestEndpoint.replace(/\/assets\/?$/, '/requests');
|
|
@@ -66,6 +77,7 @@ export interface AssetContext {
|
|
|
66
77
|
/** The asset request body. */
|
|
67
78
|
export function assetRequestBody(input: AssetFormInput, ctx: AssetContext) {
|
|
68
79
|
const utm = utmFromSearch(ctx.search);
|
|
80
|
+
const referredByCode = referredByCodeFrom(ctx.search);
|
|
69
81
|
return {
|
|
70
82
|
assetRef: ctx.assetRef,
|
|
71
83
|
sourceRef: sourceRefFor(ctx.search, ctx.pathname),
|
|
@@ -74,6 +86,7 @@ export function assetRequestBody(input: AssetFormInput, ctx: AssetContext) {
|
|
|
74
86
|
persona: PERSONAS.some((p) => p.value === input.persona) ? input.persona : 'unclassified',
|
|
75
87
|
seriesOptIn: input.seriesOptIn === true,
|
|
76
88
|
...(utm ? { utm } : {}),
|
|
89
|
+
...(referredByCode ? { referredByCode } : {}),
|
|
77
90
|
contact: {
|
|
78
91
|
firstName: input.firstName.trim(),
|
|
79
92
|
lastName: input.lastName.trim(),
|
|
@@ -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
|
+
}
|