@zero2webmaster/starter-kit 0.2.1 → 0.3.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/README.md +12 -14
- package/dist/airtable.d.ts +119 -0
- package/dist/airtable.js +273 -0
- package/dist/cli.js +116 -18
- package/dist/confirm.d.ts +5 -4
- package/dist/confirm.js +41 -29
- package/dist/index.d.ts +179 -6
- package/dist/index.js +155 -6
- package/dist/inventory.d.ts +137 -0
- package/dist/inventory.js +258 -0
- package/dist/license.js +8 -6
- package/dist/parse-brief.d.ts +28 -2
- package/dist/parse-brief.js +151 -16
- package/dist/scaffolders/cf-worker.js +2 -2
- package/dist/scaffolders/common.d.ts +30 -1
- package/dist/scaffolders/common.js +538 -21
- package/dist/scaffolders/index.d.ts +1 -0
- package/dist/scaffolders/index.js +3 -0
- package/dist/scaffolders/library.js +26 -2
- package/dist/scaffolders/nextjs.d.ts +1 -1
- package/dist/scaffolders/nextjs.js +250 -24
- package/dist/scaffolders/node-service.d.ts +3 -0
- package/dist/scaffolders/node-service.js +320 -0
- package/dist/scaffolders/pro-seo-extension.js +1 -1
- package/dist/scaffolders/python-service.js +5 -2
- package/dist/standards.d.ts +1 -1
- package/dist/standards.js +123 -3
- package/dist/substitute.d.ts +14 -3
- package/dist/substitute.js +8 -5
- package/dist/summary.d.ts +9 -0
- package/dist/summary.js +27 -10
- package/dist/templates.d.ts +43 -57
- package/dist/templates.js +108 -175
- package/dist/with-init.d.ts +18 -2
- package/dist/with-init.js +105 -16
- package/dist/wizard.js +21 -0
- package/dist/writer.d.ts +3 -5
- package/dist/writer.js +88 -15
- package/package.json +2 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// No web surface, no /health, no Fathom, no SEO baseline. Just a clean npm
|
|
4
4
|
// package skeleton that compiles with `tsc` and exports a stub `version`.
|
|
5
|
-
import { commonBaseFiles, resolveBrandSpec, sub, } from "./common.js";
|
|
5
|
+
import { commonBaseFiles, localEnvFrom, resolveBrandSpec, sub, } from "./common.js";
|
|
6
6
|
const NARRATIVE = `## What this is
|
|
7
7
|
|
|
8
8
|
\`{{slug}}\` is a TypeScript library scaffolded under the {{brand_name}} brand. No deploy target, no \`/health\` endpoint, no analytics — this is a code library consumed by other projects.
|
|
@@ -55,7 +55,7 @@ const PACKAGE_JSON_TEMPLATE = `{
|
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/node": "^20.0.0",
|
|
57
57
|
"typescript": "^5.4.0",
|
|
58
|
-
"vitest": "^
|
|
58
|
+
"vitest": "^4.0.0"
|
|
59
59
|
},
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public"
|
|
@@ -102,6 +102,25 @@ const SRC_INDEX_TEMPLATE = `// {{slug}} — public API.
|
|
|
102
102
|
|
|
103
103
|
export const version = "{{version}}";
|
|
104
104
|
`;
|
|
105
|
+
// A no-deploy library has no runtime secrets of its own, but in this portfolio
|
|
106
|
+
// libraries routinely need keys for dogfood scripts, integration tests, or a
|
|
107
|
+
// later HTTP surface (z2w-ai-engine, a library wrapping embedding providers, is
|
|
108
|
+
// the live example — it shipped with `.env.example` but no local `.env`, which
|
|
109
|
+
// is the gap this template + the derived `.env` below close). A purely-offline
|
|
110
|
+
// library with no external dependencies can safely delete both files.
|
|
111
|
+
const ENV_EXAMPLE_TEMPLATE = `# {{slug}} — example environment variables.
|
|
112
|
+
#
|
|
113
|
+
# This is a no-deploy library, so it has no runtime secrets of its own. But a
|
|
114
|
+
# library often needs keys for dogfood scripts, integration tests, or a future
|
|
115
|
+
# HTTP surface. Add them here as you need them; a gitignored \`.env\` was
|
|
116
|
+
# scaffolded alongside this file — put real values there, never here.
|
|
117
|
+
#
|
|
118
|
+
# A purely-offline library with no external dependencies can safely delete both
|
|
119
|
+
# \`.env.example\` and \`.env\`.
|
|
120
|
+
|
|
121
|
+
# Example (uncomment + rename for your service):
|
|
122
|
+
# SOME_SERVICE_API_KEY=
|
|
123
|
+
`;
|
|
105
124
|
const LICENSE_TEMPLATE = `Proprietary License — © {{year}} {{author}}
|
|
106
125
|
|
|
107
126
|
All rights reserved. This software is the proprietary work of {{author}} and is licensed for use only under the terms of a separate written agreement with the author or {{brand_name}}. Unauthorized copying, modification, distribution, or use is prohibited.
|
|
@@ -111,11 +130,16 @@ For licensing inquiries, contact {{author_url}}.
|
|
|
111
130
|
export function scaffoldLibrary(inputs, opts) {
|
|
112
131
|
const spec = resolveBrandSpec(inputs);
|
|
113
132
|
const base = commonBaseFiles(inputs, opts, NARRATIVE);
|
|
133
|
+
const envExample = sub(ENV_EXAMPLE_TEMPLATE, inputs, opts, spec);
|
|
114
134
|
const typeSpecific = [
|
|
115
135
|
{ path: "package.json", content: sub(PACKAGE_JSON_TEMPLATE, inputs, opts, spec) },
|
|
116
136
|
{ path: "tsconfig.json", content: sub(TSCONFIG_TEMPLATE, inputs, opts, spec) },
|
|
117
137
|
{ path: "src/index.ts", content: sub(SRC_INDEX_TEMPLATE, inputs, opts, spec) },
|
|
118
138
|
{ path: "LICENSE", content: sub(LICENSE_TEMPLATE, inputs, opts, spec) },
|
|
139
|
+
{ path: ".env.example", content: envExample },
|
|
140
|
+
// A library's local-env convention is `.env` (gitignored), like python — not
|
|
141
|
+
// `.env.local`. Closes the z2w-ai-engine 2026-06-20 Open question.
|
|
142
|
+
{ path: ".env", content: localEnvFrom(envExample, ".env", inputs.slug) },
|
|
119
143
|
];
|
|
120
144
|
return [...base, ...typeSpecific];
|
|
121
145
|
}
|
|
@@ -6,4 +6,4 @@ export declare function scaffoldNextjs(inputs: ScaffoldInputs, opts?: Scaffolder
|
|
|
6
6
|
* they can assert / require the canonical SEO baseline file list without
|
|
7
7
|
* hardcoding the paths in two places.
|
|
8
8
|
*/
|
|
9
|
-
export declare const NEXTJS_SEO_BASELINE_PATHS: readonly ["app/layout.tsx", "app/page.tsx", "app/sitemap.ts", "app/robots.ts", "app/opengraph-image.tsx", "SEO-CHECKLIST.md", ".env.example"];
|
|
9
|
+
export declare const NEXTJS_SEO_BASELINE_PATHS: readonly ["app/layout.tsx", "app/page.tsx", "app/sitemap.ts", "app/robots.ts", "app/opengraph-image.tsx", "lib/analytics/utm.ts", "lib/analytics/Analytics.tsx", "lib/analytics/RouteTracker.tsx", "SEO-CHECKLIST.md", ".env.example"];
|
|
@@ -13,13 +13,19 @@
|
|
|
13
13
|
// 5. JSON-LD — `Organization` schema injected in app/layout.tsx.
|
|
14
14
|
// 6. sitemap.xml + robots.txt — app/sitemap.ts + app/robots.ts; preview
|
|
15
15
|
// noindex gated on `VERCEL_ENV !== 'production'`.
|
|
16
|
-
// 7. Fathom —
|
|
17
|
-
//
|
|
16
|
+
// 7. Fathom — the three-file pattern under lib/analytics/ (utm.ts +
|
|
17
|
+
// Analytics.tsx + RouteTracker.tsx), mounted as <Analytics /> in
|
|
18
|
+
// app/layout.tsx, gated on `NEXT_PUBLIC_FATHOM_SITE_ID` (per
|
|
19
|
+
// [[fathom-analytics]]). The RouteTracker fires trackPageview() on route
|
|
20
|
+
// change — data-auto="false" alone records nothing.
|
|
18
21
|
//
|
|
19
22
|
// Also emits: app/api/health/route.ts (DB-free), app/opengraph-image.tsx
|
|
20
23
|
// (placeholder), SEO-CHECKLIST.md (per-page checklist), `.env.example` with
|
|
21
|
-
// NEXT_PUBLIC_SITE_URL + NEXT_PUBLIC_FATHOM_SITE_ID stubs
|
|
22
|
-
|
|
24
|
+
// NEXT_PUBLIC_SITE_URL + NEXT_PUBLIC_FATHOM_SITE_ID stubs, and a
|
|
25
|
+
// next.config.mjs that redirects the production *.vercel.app alias to the
|
|
26
|
+
// custom domain (SEO-duplicate fix — Z2W heads-up 2026-06-29; self-disabling
|
|
27
|
+
// until NEXT_PUBLIC_SITE_URL is a real custom domain).
|
|
28
|
+
import { commonBaseFiles, EMAIL_DEPS, EMAIL_ENV_BLOCK, emailFiles, localEnvFrom, resolveBrandSpec, sub, } from "./common.js";
|
|
23
29
|
const NARRATIVE = `## What this is
|
|
24
30
|
|
|
25
31
|
\`{{slug}}\` is a Next.js App Router project scaffolded under the {{brand_name}} brand. The 7-item SEO baseline (per Z2W standing org requirement 2026-05-30) is wired in at instantiation.
|
|
@@ -35,8 +41,9 @@ npm run build && npm start # production build
|
|
|
35
41
|
|
|
36
42
|
**SEO baseline (wired in):**
|
|
37
43
|
|
|
38
|
-
- \`app/layout.tsx\` — root \`metadata\` with \`title.template\`, \`title.default\`, \`description\`, \`openGraph\`, \`twitter\`, \`metadataBase\`;
|
|
44
|
+
- \`app/layout.tsx\` — root \`metadata\` with \`title.template\`, \`title.default\`, \`description\`, \`openGraph\`, \`twitter\`, \`metadataBase\`; mounts \`<Analytics />\`; JSON-LD Organization schema.
|
|
39
45
|
- \`app/page.tsx\` — per-page \`metadata\` (unique title + description; never inherit defaults); exactly one \`<h1>\`; semantic HTML.
|
|
46
|
+
- \`lib/analytics/{utm.ts,Analytics.tsx,RouteTracker.tsx}\` — Fathom (per [[fathom-analytics]]); the RouteTracker fires \`trackPageview()\` on route change + captures first-touch UTM. Gated on \`NEXT_PUBLIC_FATHOM_SITE_ID\`.
|
|
40
47
|
- \`app/sitemap.ts\` — sitemap generator; lists indexable pages.
|
|
41
48
|
- \`app/robots.ts\` — robots generator; preview/staging emits \`noindex\` (gated on \`VERCEL_ENV !== 'production'\`).
|
|
42
49
|
- \`app/opengraph-image.tsx\` — default OG image (replace placeholder before launch).
|
|
@@ -74,8 +81,48 @@ const PACKAGE_JSON_TEMPLATE = `{
|
|
|
74
81
|
}
|
|
75
82
|
`;
|
|
76
83
|
const NEXT_CONFIG_TEMPLATE = `/** @type {import('next').NextConfig} */
|
|
84
|
+
|
|
85
|
+
// SEO: redirect the auto-assigned PRODUCTION *.vercel.app alias to the custom
|
|
86
|
+
// domain so it is not crawled as an indexable duplicate of the whole site
|
|
87
|
+
// (Z2W standing heads-up 2026-06-29; recipe = [[portable-stack]] §14 rule 5b).
|
|
88
|
+
// It lives in-repo (portable — survives a move off Vercel) and self-disables:
|
|
89
|
+
// - The alias host defaults to "{{slug}}.vercel.app" (Vercel's default
|
|
90
|
+
// project domain); override with VERCEL_ALIAS_HOST if your project's
|
|
91
|
+
// production alias differs.
|
|
92
|
+
// - The redirect only fires once NEXT_PUBLIC_SITE_URL is a REAL custom domain.
|
|
93
|
+
// While it is blank, the *.example.com placeholder, or itself a *.vercel.app
|
|
94
|
+
// host, the redirect list is empty — so a fresh scaffold never self-redirects.
|
|
95
|
+
// - It matches ONLY the exact production alias, never per-deployment PREVIEW
|
|
96
|
+
// URLs (e.g. {{slug}}-<hash>.vercel.app), which stay reachable + noindex'd.
|
|
97
|
+
const vercelAliasHost = process.env.VERCEL_ALIAS_HOST || "{{slug}}.vercel.app";
|
|
98
|
+
|
|
99
|
+
function canonicalHost() {
|
|
100
|
+
const raw = process.env.NEXT_PUBLIC_SITE_URL || "";
|
|
101
|
+
try {
|
|
102
|
+
const host = new URL(raw).host;
|
|
103
|
+
if (host && !host.endsWith(".vercel.app") && !host.endsWith(".example.com")) {
|
|
104
|
+
return host;
|
|
105
|
+
}
|
|
106
|
+
} catch {
|
|
107
|
+
// NEXT_PUBLIC_SITE_URL not a valid absolute URL yet — no redirect.
|
|
108
|
+
}
|
|
109
|
+
return "";
|
|
110
|
+
}
|
|
111
|
+
|
|
77
112
|
const nextConfig = {
|
|
78
113
|
reactStrictMode: true,
|
|
114
|
+
async redirects() {
|
|
115
|
+
const host = canonicalHost();
|
|
116
|
+
if (!host) return [];
|
|
117
|
+
return [
|
|
118
|
+
{
|
|
119
|
+
source: "/:path*",
|
|
120
|
+
has: [{ type: "host", value: vercelAliasHost }],
|
|
121
|
+
destination: \`https://\${host}/:path*\`,
|
|
122
|
+
permanent: true,
|
|
123
|
+
},
|
|
124
|
+
];
|
|
125
|
+
},
|
|
79
126
|
};
|
|
80
127
|
|
|
81
128
|
export default nextConfig;
|
|
@@ -107,10 +154,13 @@ const APP_LAYOUT_TEMPLATE = `// Root layout — SEO baseline wiring per Z2W stan
|
|
|
107
154
|
// rely on these defaults to fill in per-page values.
|
|
108
155
|
|
|
109
156
|
import type { Metadata, Viewport } from "next";
|
|
110
|
-
import
|
|
157
|
+
import { Analytics } from "@/lib/analytics/Analytics";
|
|
111
158
|
|
|
112
|
-
|
|
113
|
-
|
|
159
|
+
// Use \`||\` (not \`??\`) so a present-but-EMPTY env value falls back too. The
|
|
160
|
+
// scaffolded .env.local seeds NEXT_PUBLIC_SITE_URL="" until you fill it in,
|
|
161
|
+
// and \`"" ?? fallback\` keeps the empty string — which makes \`new URL("")\`
|
|
162
|
+
// below throw and crashes \`next build\`. \`||\` treats "" as missing.
|
|
163
|
+
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || "https://{{slug}}.example.com";
|
|
114
164
|
|
|
115
165
|
export const metadata: Metadata = {
|
|
116
166
|
metadataBase: new URL(siteUrl),
|
|
@@ -147,7 +197,9 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
147
197
|
return (
|
|
148
198
|
<html lang="en">
|
|
149
199
|
<head>
|
|
150
|
-
|
|
200
|
+
{/* Canonical URLs are emitted per page by Next.js's Metadata API via
|
|
201
|
+
\`alternates.canonical\` — do NOT add a literal canonical link here,
|
|
202
|
+
it would produce a SECOND, conflicting canonical on every page. */}
|
|
151
203
|
<script
|
|
152
204
|
type="application/ld+json"
|
|
153
205
|
dangerouslySetInnerHTML={{ __html: JSON.stringify(organizationJsonLd) }}
|
|
@@ -161,20 +213,158 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
161
213
|
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
162
214
|
}}
|
|
163
215
|
>
|
|
164
|
-
{fathomSiteId ? (
|
|
165
|
-
<Script
|
|
166
|
-
src="https://cdn.usefathom.com/script.js"
|
|
167
|
-
data-site={fathomSiteId}
|
|
168
|
-
data-auto="false"
|
|
169
|
-
strategy="afterInteractive"
|
|
170
|
-
/>
|
|
171
|
-
) : null}
|
|
172
216
|
{children}
|
|
217
|
+
{/* Fathom analytics (per [[fathom-analytics]]). \`<Analytics />\` renders
|
|
218
|
+
the loader AND the RouteTracker that fires trackPageview() on every
|
|
219
|
+
route change — the two are one pattern. It no-ops until
|
|
220
|
+
NEXT_PUBLIC_FATHOM_SITE_ID is set. */}
|
|
221
|
+
<Analytics />
|
|
173
222
|
</body>
|
|
174
223
|
</html>
|
|
175
224
|
);
|
|
176
225
|
}
|
|
177
226
|
`;
|
|
227
|
+
// --- Fathom analytics: the three-file canonical pattern ---------------------
|
|
228
|
+
// Per [[fathom-analytics]] §2 (single-tenant). data-auto="false" alone records
|
|
229
|
+
// ZERO pageviews — it MUST be paired with the RouteTracker that calls
|
|
230
|
+
// trackPageview() on route change. Shipping the loader without the tracker is
|
|
231
|
+
// the #1 scaffold trap (silent empty dashboard forever); this closes it.
|
|
232
|
+
// Storage keys are slug-namespaced so two Z2W apps on one domain don't collide.
|
|
233
|
+
const ANALYTICS_UTM_TEMPLATE = `export const UTM_KEYS = [
|
|
234
|
+
"utm_source",
|
|
235
|
+
"utm_medium",
|
|
236
|
+
"utm_campaign",
|
|
237
|
+
"utm_term",
|
|
238
|
+
"utm_content",
|
|
239
|
+
] as const;
|
|
240
|
+
|
|
241
|
+
export type UtmKey = (typeof UTM_KEYS)[number];
|
|
242
|
+
export type UtmParams = Partial<Record<UtmKey, string>>;
|
|
243
|
+
|
|
244
|
+
// Slug-namespaced so two Z2W apps sharing a domain don't collide in storage.
|
|
245
|
+
const STORAGE_KEY = "{{slug}}_utm_first_touch";
|
|
246
|
+
const SENT_FLAG_KEY = "{{slug}}_utm_event_sent";
|
|
247
|
+
|
|
248
|
+
export function readUtmFromUrl(search: string | URLSearchParams): UtmParams {
|
|
249
|
+
const params =
|
|
250
|
+
typeof search === "string" ? new URLSearchParams(search) : search;
|
|
251
|
+
const out: UtmParams = {};
|
|
252
|
+
for (const key of UTM_KEYS) {
|
|
253
|
+
const value = params.get(key);
|
|
254
|
+
if (value) out[key] = value.slice(0, 200);
|
|
255
|
+
}
|
|
256
|
+
return out;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export function captureFirstTouch(utm: UtmParams): UtmParams | null {
|
|
260
|
+
if (typeof window === "undefined") return null;
|
|
261
|
+
if (Object.keys(utm).length === 0) return null;
|
|
262
|
+
try {
|
|
263
|
+
const existing = window.sessionStorage.getItem(STORAGE_KEY);
|
|
264
|
+
if (existing) return JSON.parse(existing) as UtmParams;
|
|
265
|
+
window.sessionStorage.setItem(STORAGE_KEY, JSON.stringify(utm));
|
|
266
|
+
return utm;
|
|
267
|
+
} catch {
|
|
268
|
+
return utm;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function getFirstTouch(): UtmParams | null {
|
|
273
|
+
if (typeof window === "undefined") return null;
|
|
274
|
+
try {
|
|
275
|
+
const raw = window.sessionStorage.getItem(STORAGE_KEY);
|
|
276
|
+
return raw ? (JSON.parse(raw) as UtmParams) : null;
|
|
277
|
+
} catch {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function markUtmEventSent(): boolean {
|
|
283
|
+
if (typeof window === "undefined") return false;
|
|
284
|
+
try {
|
|
285
|
+
if (window.sessionStorage.getItem(SENT_FLAG_KEY)) return false;
|
|
286
|
+
window.sessionStorage.setItem(SENT_FLAG_KEY, "1");
|
|
287
|
+
return true;
|
|
288
|
+
} catch {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
`;
|
|
293
|
+
const ANALYTICS_WRAPPER_TEMPLATE = `// Fathom analytics wrapper (per [[fathom-analytics]] §2). Server component:
|
|
294
|
+
// renders the loader with data-auto="false" AND mounts the client RouteTracker
|
|
295
|
+
// that fires trackPageview() on every route change. The loader alone records
|
|
296
|
+
// nothing — the two are one pattern. No-ops until the site id env var is set.
|
|
297
|
+
|
|
298
|
+
import Script from "next/script";
|
|
299
|
+
import { Suspense } from "react";
|
|
300
|
+
import { RouteTracker } from "./RouteTracker";
|
|
301
|
+
|
|
302
|
+
export function Analytics() {
|
|
303
|
+
const siteId = process.env.NEXT_PUBLIC_FATHOM_SITE_ID;
|
|
304
|
+
if (!siteId) return null;
|
|
305
|
+
return (
|
|
306
|
+
<>
|
|
307
|
+
<Script
|
|
308
|
+
src="https://cdn.usefathom.com/script.js"
|
|
309
|
+
data-site={siteId}
|
|
310
|
+
data-auto="false"
|
|
311
|
+
strategy="afterInteractive"
|
|
312
|
+
/>
|
|
313
|
+
<Suspense fallback={null}>
|
|
314
|
+
<RouteTracker />
|
|
315
|
+
</Suspense>
|
|
316
|
+
</>
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
`;
|
|
320
|
+
const ANALYTICS_ROUTE_TRACKER_TEMPLATE = `"use client";
|
|
321
|
+
|
|
322
|
+
import { usePathname, useSearchParams } from "next/navigation";
|
|
323
|
+
import { useEffect } from "react";
|
|
324
|
+
import { captureFirstTouch, markUtmEventSent, readUtmFromUrl } from "./utm";
|
|
325
|
+
|
|
326
|
+
declare global {
|
|
327
|
+
interface Window {
|
|
328
|
+
fathom?: {
|
|
329
|
+
trackPageview: (opts?: { url?: string; referrer?: string }) => void;
|
|
330
|
+
trackEvent: (name: string, opts?: { _value?: number }) => void;
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function waitForFathom(callback: () => void, attempts = 20) {
|
|
336
|
+
if (typeof window === "undefined") return;
|
|
337
|
+
if (window.fathom) {
|
|
338
|
+
callback();
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (attempts <= 0) return;
|
|
342
|
+
window.setTimeout(() => waitForFathom(callback, attempts - 1), 150);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export function RouteTracker() {
|
|
346
|
+
const pathname = usePathname();
|
|
347
|
+
const searchParams = useSearchParams();
|
|
348
|
+
|
|
349
|
+
useEffect(() => {
|
|
350
|
+
if (typeof window === "undefined") return;
|
|
351
|
+
const search = searchParams?.toString() ?? "";
|
|
352
|
+
const url = search ? \`\${pathname}?\${search}\` : pathname;
|
|
353
|
+
|
|
354
|
+
waitForFathom(() => {
|
|
355
|
+
window.fathom?.trackPageview({ url });
|
|
356
|
+
const utm = readUtmFromUrl(searchParams ?? new URLSearchParams());
|
|
357
|
+
const firstTouch = captureFirstTouch(utm);
|
|
358
|
+
if (firstTouch && firstTouch.utm_source && markUtmEventSent()) {
|
|
359
|
+
const name = \`utm:\${firstTouch.utm_source}\`.slice(0, 64);
|
|
360
|
+
window.fathom?.trackEvent(name);
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
}, [pathname, searchParams]);
|
|
364
|
+
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
`;
|
|
178
368
|
const APP_PAGE_TEMPLATE = `// Home page — per-page \`metadata\` is mandatory per SEO baseline. Replace
|
|
179
369
|
// the title + description with intentional, page-specific copy (do NOT
|
|
180
370
|
// inherit the root defaults).
|
|
@@ -224,7 +414,8 @@ const APP_SITEMAP_TEMPLATE = `// Sitemap generator — lists every indexable pag
|
|
|
224
414
|
|
|
225
415
|
import type { MetadataRoute } from "next";
|
|
226
416
|
|
|
227
|
-
|
|
417
|
+
// \`||\` not \`??\` — a blank NEXT_PUBLIC_SITE_URL must fall back (see app/layout.tsx).
|
|
418
|
+
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || "https://{{slug}}.example.com";
|
|
228
419
|
|
|
229
420
|
export default function sitemap(): MetadataRoute.Sitemap {
|
|
230
421
|
return [
|
|
@@ -243,7 +434,8 @@ const APP_ROBOTS_TEMPLATE = `// Robots generator — production indexable, previ
|
|
|
243
434
|
|
|
244
435
|
import type { MetadataRoute } from "next";
|
|
245
436
|
|
|
246
|
-
|
|
437
|
+
// \`||\` not \`??\` — a blank NEXT_PUBLIC_SITE_URL must fall back (see app/layout.tsx).
|
|
438
|
+
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || "https://{{slug}}.example.com";
|
|
247
439
|
const isProduction = process.env.VERCEL_ENV === "production";
|
|
248
440
|
|
|
249
441
|
export default function robots(): MetadataRoute.Robots {
|
|
@@ -319,7 +511,7 @@ Per Z2W standing org requirement 2026-05-30. Run before adding a new page AND be
|
|
|
319
511
|
- [ ] JSON-LD present where warranted; validates in Google Rich Results test
|
|
320
512
|
- [ ] \`sitemap.xml\` generates correctly; \`robots.txt\` references it
|
|
321
513
|
- [ ] Production is indexable; preview/staging is NOT indexable (\`curl -I <preview-url>\` shows \`X-Robots-Tag: noindex\` OR the page returns \`Disallow: /\`)
|
|
322
|
-
- [ ] Fathom
|
|
514
|
+
- [ ] Fathom firing: load the site with \`?utm_source=test\`, open DevTools → Network, filter \`usefathom\` — expect BOTH \`script.js\` (200) AND a beacon to \`cdn-evt.usefathom.com\` (the beacon proves the RouteTracker ran; \`script.js\` alone = zero pageviews recorded)
|
|
323
515
|
- [ ] Core Web Vitals reasonable (no obvious CLS, oversized images, render-blocking)
|
|
324
516
|
|
|
325
517
|
## Wired at instantiation by \`@zero2webmaster/starter-kit\`
|
|
@@ -329,7 +521,7 @@ Per Z2W standing org requirement 2026-05-30. Run before adding a new page AND be
|
|
|
329
521
|
- ✅ \`app/sitemap.ts\`
|
|
330
522
|
- ✅ \`app/robots.ts\` (preview-noindex gated on \`VERCEL_ENV\`)
|
|
331
523
|
- ✅ \`app/opengraph-image.tsx\` (placeholder — replace before launch)
|
|
332
|
-
- ✅ Fathom
|
|
524
|
+
- ✅ Fathom three-file pattern (\`lib/analytics/\`) mounted as \`<Analytics />\`; RouteTracker fires \`trackPageview()\` on route change (gated on \`NEXT_PUBLIC_FATHOM_SITE_ID\`)
|
|
333
525
|
- ✅ \`NEXT_PUBLIC_SITE_URL\` env var stub for \`metadataBase\`
|
|
334
526
|
|
|
335
527
|
## Still content-driven (you fill these in)
|
|
@@ -351,15 +543,41 @@ NEXT_PUBLIC_SITE_URL=https://{{slug}}.example.com
|
|
|
351
543
|
# One Fathom site = one deployment.
|
|
352
544
|
NEXT_PUBLIC_FATHOM_SITE_ID=
|
|
353
545
|
`;
|
|
546
|
+
/**
|
|
547
|
+
* Merge the email SDK deps into an already-substituted package.json string.
|
|
548
|
+
* Only called on the email path, so the no-email package.json stays the exact
|
|
549
|
+
* hand-written template output (its snapshot is untouched).
|
|
550
|
+
*/
|
|
551
|
+
function withEmailDeps(pkgJson) {
|
|
552
|
+
const obj = JSON.parse(pkgJson);
|
|
553
|
+
obj.dependencies = { ...obj.dependencies, ...EMAIL_DEPS };
|
|
554
|
+
return JSON.stringify(obj, null, 2) + "\n";
|
|
555
|
+
}
|
|
354
556
|
export function scaffoldNextjs(inputs, opts) {
|
|
355
557
|
const spec = resolveBrandSpec(inputs);
|
|
356
558
|
const base = commonBaseFiles(inputs, opts, NARRATIVE);
|
|
559
|
+
const sendsEmail = inputs.sendsEmail === true;
|
|
560
|
+
let packageJson = sub(PACKAGE_JSON_TEMPLATE, inputs, opts, spec);
|
|
561
|
+
if (sendsEmail)
|
|
562
|
+
packageJson = withEmailDeps(packageJson);
|
|
563
|
+
let envExample = sub(ENV_EXAMPLE_TEMPLATE, inputs, opts, spec);
|
|
564
|
+
if (sendsEmail)
|
|
565
|
+
envExample += EMAIL_ENV_BLOCK;
|
|
357
566
|
const typeSpecific = [
|
|
358
|
-
{ path: "package.json", content:
|
|
567
|
+
{ path: "package.json", content: packageJson },
|
|
359
568
|
{ path: "next.config.mjs", content: sub(NEXT_CONFIG_TEMPLATE, inputs, opts, spec) },
|
|
360
569
|
{ path: "tsconfig.json", content: sub(TSCONFIG_TEMPLATE, inputs, opts, spec) },
|
|
361
570
|
{ path: "app/layout.tsx", content: sub(APP_LAYOUT_TEMPLATE, inputs, opts, spec) },
|
|
362
571
|
{ path: "app/page.tsx", content: sub(APP_PAGE_TEMPLATE, inputs, opts, spec) },
|
|
572
|
+
{ path: "lib/analytics/utm.ts", content: sub(ANALYTICS_UTM_TEMPLATE, inputs, opts, spec) },
|
|
573
|
+
{
|
|
574
|
+
path: "lib/analytics/Analytics.tsx",
|
|
575
|
+
content: sub(ANALYTICS_WRAPPER_TEMPLATE, inputs, opts, spec),
|
|
576
|
+
},
|
|
577
|
+
{
|
|
578
|
+
path: "lib/analytics/RouteTracker.tsx",
|
|
579
|
+
content: sub(ANALYTICS_ROUTE_TRACKER_TEMPLATE, inputs, opts, spec),
|
|
580
|
+
},
|
|
363
581
|
{
|
|
364
582
|
path: "app/api/health/route.ts",
|
|
365
583
|
content: sub(APP_HEALTH_ROUTE_TEMPLATE, inputs, opts, spec),
|
|
@@ -374,12 +592,15 @@ export function scaffoldNextjs(inputs, opts) {
|
|
|
374
592
|
path: "SEO-CHECKLIST.md",
|
|
375
593
|
content: sub(SEO_CHECKLIST_TEMPLATE, inputs, opts, spec),
|
|
376
594
|
},
|
|
377
|
-
{ path: ".env.example", content:
|
|
595
|
+
{ path: ".env.example", content: envExample },
|
|
378
596
|
];
|
|
379
597
|
typeSpecific.push({
|
|
380
598
|
path: ".env.local",
|
|
381
|
-
content: localEnvFrom(
|
|
599
|
+
content: localEnvFrom(envExample, ".env.local", inputs.slug),
|
|
382
600
|
});
|
|
601
|
+
if (sendsEmail) {
|
|
602
|
+
typeSpecific.push(...emailFiles(inputs, opts, spec, "nextjs"));
|
|
603
|
+
}
|
|
383
604
|
return [...base, ...typeSpecific];
|
|
384
605
|
}
|
|
385
606
|
/**
|
|
@@ -393,6 +614,11 @@ export const NEXTJS_SEO_BASELINE_PATHS = [
|
|
|
393
614
|
"app/sitemap.ts",
|
|
394
615
|
"app/robots.ts",
|
|
395
616
|
"app/opengraph-image.tsx",
|
|
617
|
+
// Fathom (SEO baseline item 7) — the three-file pattern; the loader alone
|
|
618
|
+
// (data-auto="false" with no RouteTracker) records zero pageviews.
|
|
619
|
+
"lib/analytics/utm.ts",
|
|
620
|
+
"lib/analytics/Analytics.tsx",
|
|
621
|
+
"lib/analytics/RouteTracker.tsx",
|
|
396
622
|
"SEO-CHECKLIST.md",
|
|
397
623
|
".env.example",
|
|
398
624
|
];
|