create-freeholder 0.2.0-beta.5 → 0.2.0-beta.6
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/dist/template/.changeset/blog-playground-content.md +4 -0
- package/dist/template/.changeset/blog-wordpress-structure.md +6 -0
- package/dist/template/.changeset/managed-preview-assistant.md +4 -0
- package/dist/template/.changeset/public-beta-6.md +4 -0
- package/dist/template/.github/ISSUE_TEMPLATE/bug_report.yml +1 -1
- package/dist/template/MASTER.md +81 -8
- package/dist/template/README.md +1 -1
- package/dist/template/app/(admin)/admin/assistant/page.tsx +9 -1
- package/dist/template/app/(admin)/admin/blog/PostSettings.tsx +26 -0
- package/dist/template/app/(admin)/admin/blog/[kind]/page.tsx +53 -0
- package/dist/template/app/(admin)/admin/blog/actions.ts +186 -6
- package/dist/template/app/(admin)/admin/blog/comments/page.tsx +25 -0
- package/dist/template/app/(admin)/admin/blog/page.tsx +21 -5
- package/dist/template/app/(admin)/admin/imports/[id]/page.tsx +2 -0
- package/dist/template/app/(admin)/admin/pages/[id]/page.tsx +3 -0
- package/dist/template/app/(admin)/assistant-actions.ts +13 -6
- package/dist/template/app/(public)/[[...slug]]/ReaderComments.tsx +25 -0
- package/dist/template/app/(public)/[[...slug]]/blog-parts.tsx +153 -0
- package/dist/template/app/(public)/[[...slug]]/comment-actions.ts +16 -0
- package/dist/template/app/(public)/[[...slug]]/page.tsx +182 -18
- package/dist/template/app/api/chat/assistant/call/route.ts +35 -0
- package/dist/template/db/migrations/0061_blog_structure.sql +89 -0
- package/dist/template/db/migrations/0062_blog_reader_comments.sql +24 -0
- package/dist/template/db/migrations/meta/_journal.json +14 -0
- package/dist/template/deploy/blog-wordpress-2026-11-07.md +146 -0
- package/dist/template/deploy/docker-selfhost/.env.example +1 -1
- package/dist/template/deploy/docker-selfhost/README.md +3 -2
- package/dist/template/deploy/docker-selfhost/infra/compose.https.yml +1 -1
- package/dist/template/deploy/docker-selfhost/infra/compose.yml +1 -1
- package/dist/template/deploy/f-criteria-matrix.md +74 -0
- package/dist/template/deploy/linux/README.md +1 -1
- package/dist/template/deploy/linux/install.sh +1 -1
- package/dist/template/deploy/managed-preview-assistant.md +99 -0
- package/dist/template/eslint.config.mjs +3 -1
- package/dist/template/locales/ar.json +85 -6
- package/dist/template/locales/en.json +83 -4
- package/dist/template/locales/es.json +83 -4
- package/dist/template/locales/fr.json +85 -6
- package/dist/template/next.config.ts +2 -0
- package/dist/template/package.json +1 -1
- package/dist/template/packages/cli/package.json +1 -1
- package/dist/template/packages/create-freeholder/package.json +1 -1
- package/dist/template/packages/freeholder-app/package.json +1 -1
- package/dist/template/packages/mobile-app/package.json +1 -1
- package/dist/template/packages/plugin-kit/package.json +1 -1
- package/dist/template/packages/sdk/package.json +1 -1
- package/dist/template/packages/sdk/src/generated.ts +177 -9
- package/dist/template/packages/sdk/src/version.ts +1 -1
- package/dist/template/packages/templates/package.json +1 -1
- package/dist/template/proxy.ts +18 -1
- package/dist/template/public/managed-assistant/0.1.10/duplex-codec/NOTICE.txt +117 -0
- package/dist/template/public/managed-assistant/0.1.10/duplex-codec/audio-output-processor.js +267 -0
- package/dist/template/public/managed-assistant/0.1.10/duplex-codec/decoderWorker.min.js +847 -0
- package/dist/template/public/managed-assistant/0.1.10/duplex-codec/decoderWorker.min.wasm +0 -0
- package/dist/template/public/managed-assistant/0.1.10/duplex-codec/encoderWorker.min.js +1 -0
- package/dist/template/public/managed-assistant/0.1.10/manifest.json +12 -0
- package/dist/template/public/managed-assistant/0.1.10/pm-ai-duplex-client.js +1376 -0
- package/dist/template/scripts/license-headers.mjs +3 -0
- package/dist/template/scripts/verify-wordpress-migration.d.mts +8 -0
- package/dist/template/scripts/verify-wordpress-migration.mjs +105 -0
- package/dist/template/security/adversarial-audit-2026-10-08.md +1 -1
- package/dist/template/src/adapters/ai/types.ts +5 -0
- package/dist/template/src/adapters/paradise/assistant.ts +37 -0
- package/dist/template/src/adapters/paradise/http.ts +4 -3
- package/dist/template/src/core/contract/json-schema.ts +8 -0
- package/dist/template/src/core/demo/playground-inserts.ts +29 -0
- package/dist/template/src/core/demo/playground-policy.ts +9 -0
- package/dist/template/src/core/env.ts +2 -0
- package/dist/template/src/core/http/csp.ts +10 -2
- package/dist/template/src/core/http/csrf-client.ts +10 -0
- package/dist/template/src/core/import/service.ts +217 -12
- package/dist/template/src/core/import/wordpress.ts +80 -15
- package/dist/template/src/core/notifications/service.ts +1 -0
- package/dist/template/src/core/retention/registry.ts +2 -0
- package/dist/template/src/core/search/registry.ts +2 -0
- package/dist/template/src/core/seo/feeds.ts +2 -0
- package/dist/template/src/core/seo/jsonld.ts +46 -2
- package/dist/template/src/core/seo/legacy-proxy.ts +53 -0
- package/dist/template/src/core/seo/meta.ts +10 -7
- package/dist/template/src/core/seo/service.ts +14 -1
- package/dist/template/src/core/update/release-declaration.json +1 -1
- package/dist/template/src/modules/assistant/contract.ts +1 -1
- package/dist/template/src/modules/assistant/limits.ts +3 -0
- package/dist/template/src/modules/assistant/preview.ts +124 -0
- package/dist/template/src/modules/assistant/provider.ts +7 -0
- package/dist/template/src/modules/assistant/service.ts +21 -5
- package/dist/template/src/modules/cms/blocks/PreviewAssistantCall.tsx +176 -0
- package/dist/template/src/modules/cms/blocks/SiteChatClient.tsx +10 -4
- package/dist/template/src/modules/cms/blocks/surfaces.tsx +10 -0
- package/dist/template/src/modules/cms/blog-comments-schema.ts +27 -0
- package/dist/template/src/modules/cms/blog-comments.ts +111 -0
- package/dist/template/src/modules/cms/blog-schema.ts +146 -0
- package/dist/template/src/modules/cms/blog-service.ts +999 -0
- package/dist/template/src/modules/cms/blog.tsx +245 -25
- package/dist/template/src/modules/cms/manifest.ts +7 -1
- package/dist/template/src/modules/cms/read.ts +18 -0
- package/dist/template/src/modules/cms/service.ts +22 -4
- package/dist/template/src/modules/cms/tables.ts +2 -0
- package/dist/template/src/modules/seed/launch.ts +31 -3
- package/dist/template/tests/browser/blog-structure.spec.ts +69 -0
- package/dist/template/tests/core/analytics-consent.test.ts +1 -1
- package/dist/template/tests/core/blog-playground.test.ts +106 -0
- package/dist/template/tests/core/blog-structure-comments.test.ts +166 -0
- package/dist/template/tests/core/csp.test.ts +1 -1
- package/dist/template/tests/core/internal-services.test.ts +4 -0
- package/dist/template/tests/core/legacy-redirect-proxy.test.ts +59 -0
- package/dist/template/tests/core/locale-routing.test.ts +1 -1
- package/dist/template/tests/core/playground-cache.test.ts +1 -1
- package/dist/template/tests/core/playground.test.ts +3 -3
- package/dist/template/tests/core/preview-assistant-call.test.ts +88 -0
- package/dist/template/tests/core/private-preview-webhooks.test.ts +1 -1
- package/dist/template/tests/core/private-preview.test.ts +1 -1
- package/dist/template/tests/core/proxy-locale.test.ts +1 -1
- package/dist/template/tests/core/sdk-schema.test.ts +20 -0
- package/dist/template/tests/core/seo.test.ts +1 -1
- package/dist/template/tests/core/site-chat-client.test.ts +50 -0
- package/dist/template/tests/core/wordpress-import-flow.test.ts +81 -18
- package/dist/template/tests/core/wordpress-import.test.ts +25 -12
- package/dist/template/tests/core/wordpress-migration-verification.test.ts +37 -0
- package/dist/template/tests/modules/preview-assistant.test.ts +164 -0
- package/dist/template-manifest.json +349 -139
- package/package.json +1 -1
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
saveKnowledge,
|
|
21
21
|
setScope,
|
|
22
22
|
updateSettings,
|
|
23
|
+
syncManagedSettings,
|
|
23
24
|
} from "@/modules/assistant/service";
|
|
24
25
|
import { ownerFacing } from "./action-helpers";
|
|
25
26
|
|
|
@@ -62,20 +63,26 @@ function done(error?: unknown): never {
|
|
|
62
63
|
export async function saveAssistantAction(form: FormData): Promise<void> {
|
|
63
64
|
const provider = text(form, "provider");
|
|
64
65
|
try {
|
|
66
|
+
const authorized = await actor();
|
|
67
|
+
if (provider === "paradise") await syncManagedSettings.call({
|
|
68
|
+
enabled: form.get("enabled") === "1",
|
|
69
|
+
talentSlug: optional(form, "managedTalent") ?? "sienna-rodriguez",
|
|
70
|
+
dailyCapUsd: digits(form, "spendCapCents", 0) / 100,
|
|
71
|
+
}, authorized);
|
|
65
72
|
await updateSettings.call(
|
|
66
73
|
{
|
|
67
74
|
enabled: form.get("enabled") === "1",
|
|
68
|
-
provider: provider === "anthropic" || provider === "openai" ? provider : "none",
|
|
69
|
-
model: optional(form, "model"),
|
|
75
|
+
provider: provider === "anthropic" || provider === "openai" || provider === "paradise" ? provider : "none",
|
|
76
|
+
model: provider === "paradise" ? "paradise-managed-assistant" : optional(form, "model"),
|
|
70
77
|
baseUrl: optional(form, "baseUrl"),
|
|
71
|
-
credentialRef: optional(form, "credentialRef"),
|
|
78
|
+
credentialRef: provider === "paradise" ? "PARADISEMODERN_API_KEY" : optional(form, "credentialRef"),
|
|
72
79
|
inputCentsPerMillion: optionalDigits(form, "inputCentsPerMillion"),
|
|
73
80
|
outputCentsPerMillion: optionalDigits(form, "outputCentsPerMillion"),
|
|
74
|
-
maxOutputTokens: digits(form, "maxOutputTokens", 700),
|
|
81
|
+
maxOutputTokens: provider === "paradise" ? Math.min(600, digits(form, "maxOutputTokens", 600)) : digits(form, "maxOutputTokens", 700),
|
|
75
82
|
displayName: optional(form, "displayName"),
|
|
76
83
|
spendCapCents: digits(form, "spendCapCents", 0),
|
|
77
84
|
spendPeriod:
|
|
78
|
-
text(form, "spendPeriod") === "day"
|
|
85
|
+
provider === "paradise" || text(form, "spendPeriod") === "day"
|
|
79
86
|
? "day"
|
|
80
87
|
: text(form, "spendPeriod") === "week"
|
|
81
88
|
? "week"
|
|
@@ -92,7 +99,7 @@ export async function saveAssistantAction(form: FormData): Promise<void> {
|
|
|
92
99
|
escalateTopics: parseTopics(text(form, "escalateTopics")),
|
|
93
100
|
contactFormPath: optional(form, "contactFormPath"),
|
|
94
101
|
},
|
|
95
|
-
|
|
102
|
+
authorized,
|
|
96
103
|
);
|
|
97
104
|
} catch (error) {
|
|
98
105
|
done(error);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { listReaderComments } from "@/modules/cms/blog-comments";
|
|
4
|
+
import { blogSettingsCached } from "@/modules/cms/read";
|
|
5
|
+
import type { Translate } from "@/core/i18n";
|
|
6
|
+
import { Button, Field, Input, Select } from "@/ui/primitives";
|
|
7
|
+
import { submitReaderCommentAction } from "./comment-actions";
|
|
8
|
+
|
|
9
|
+
export async function ReaderComments({ pageId, enabled, returnTo, result, locale, t, pageValue }: { pageId: string; enabled: boolean; returnTo: string; result?: string; locale: string; t: Translate; pageValue?: string }) {
|
|
10
|
+
const page = Math.max(1, Math.min(10000, Math.floor(Number(pageValue)) || 1));
|
|
11
|
+
const [comments, settings] = await Promise.all([listReaderComments.call({ pageId, page }, { kind: "anonymous" }), blogSettingsCached()]);
|
|
12
|
+
const open = enabled && settings.commentsEnabled;
|
|
13
|
+
if (!open && !comments.length && page === 1) return null;
|
|
14
|
+
return <section id="comments" className="grid gap-5 border-t border-rule pt-6" aria-labelledby="comments-title"><h2 id="comments-title" className="text-xl font-semibold">{t("blog.comments")}</h2>
|
|
15
|
+
{result === "pending" ? <p role="status">{t("blog.commentReceived")}</p> : result === "error" ? <p role="alert">{t("blog.commentFailed")}</p> : null}
|
|
16
|
+
<ol className="grid list-none gap-5 p-0">{comments.map(comment => <li id={`comment-${comment.id}`} key={comment.id} className="grid gap-2 rounded-lg border border-rule p-4"><p className="flex flex-wrap justify-between gap-3"><strong>{comment.authorName}</strong><time dateTime={comment.createdAt.toISOString()}>{new Intl.DateTimeFormat(locale, { dateStyle: "medium" }).format(comment.createdAt)}</time></p>{comment.parentId && comments.some(parent => parent.id === comment.parentId) ? <a className="text-sm underline" href={`#comment-${comment.parentId}`}>{t("blog.commentInReplyTo")}</a> : null}<p className="whitespace-pre-wrap break-words">{comment.body}</p></li>)}</ol>
|
|
17
|
+
{page > 1 || comments.length === 100 ? <nav className="flex justify-between gap-4" aria-label={t("blog.comments")}>{page > 1 ? <a className="underline" href={`${returnTo}?commentPage=${page - 1}#comments`}>{t("blog.previous")}</a> : <span />}{comments.length === 100 && page < 10000 ? <a className="underline" href={`${returnTo}?commentPage=${page + 1}#comments`}>{t("blog.next")}</a> : null}</nav> : null}
|
|
18
|
+
{open ? <form action={submitReaderCommentAction} className="grid max-w-xl gap-4"><input type="hidden" name="pageId" value={pageId} /><input type="hidden" name="returnTo" value={returnTo} /><h3 className="text-lg font-semibold">{t("blog.commentLeave")}</h3><p className="text-sm text-ink-muted">{t("blog.commentPrivacy")}</p>
|
|
19
|
+
<Field label={t("blog.name")} htmlFor="comment-name"><Input id="comment-name" name="name" autoComplete="name" required maxLength={200} /></Field><Field label={t("blog.commentEmail")} htmlFor="comment-email"><Input id="comment-email" name="email" type="email" autoComplete="email" required maxLength={320} /></Field>
|
|
20
|
+
{comments.length ? <Field label={t("blog.commentReply")} htmlFor="comment-parent"><Select id="comment-parent" name="parentId"><option value="">{t("blog.none")}</option>{comments.map(comment => <option key={comment.id} value={comment.id}>{comment.authorName}: {comment.body.slice(0, 70)}</option>)}</Select></Field> : null}
|
|
21
|
+
<Field label={t("blog.commentBody")} htmlFor="comment-body"><textarea id="comment-body" name="body" required maxLength={10000} rows={5} className="w-full rounded-md border border-rule bg-surface px-3 py-2 text-ink" /></Field>
|
|
22
|
+
<div hidden aria-hidden="true"><label htmlFor="comment-website">{t("blog.commentWebsite")}</label><input id="comment-website" name="website" tabIndex={-1} autoComplete="off" /></div><Button type="submit">{t("blog.commentSubmit")}</Button>
|
|
23
|
+
</form> : <p>{t("blog.commentClosed")}</p>}
|
|
24
|
+
</section>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// The blog's share of the public route (C2.27, C2.28): archive pages for a
|
|
4
|
+
// category, tag or author, and the byline a post carries.
|
|
5
|
+
//
|
|
6
|
+
// An archive is not a stored page, so it is rendered from a block tree built
|
|
7
|
+
// here — a heading, the description, and the same `blogIndex` block the blog
|
|
8
|
+
// page uses, filtered — which keeps one listing implementation and lets the
|
|
9
|
+
// archive inherit everything that block already does (pagination, locale
|
|
10
|
+
// links, dates).
|
|
11
|
+
import type { BlockNode } from "@/modules/cms/blocks/types";
|
|
12
|
+
import type { Translate } from "@/core/i18n";
|
|
13
|
+
|
|
14
|
+
export type BlogArchive = {
|
|
15
|
+
kind: "category" | "tag" | "author" | "date";
|
|
16
|
+
id: string;
|
|
17
|
+
slug: string;
|
|
18
|
+
path: string;
|
|
19
|
+
name: string;
|
|
20
|
+
description: string | null;
|
|
21
|
+
seo: { title?: string; description?: string; noindex?: boolean };
|
|
22
|
+
trail: Array<{ name: string; path: string }>;
|
|
23
|
+
posts: number;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type PostMeta = {
|
|
27
|
+
pageId: string;
|
|
28
|
+
author: { name: string; path: string; bio: string | null } | null;
|
|
29
|
+
categories: Array<{ name: string; path: string }>;
|
|
30
|
+
tags: Array<{ name: string; path: string }>;
|
|
31
|
+
commentsEnabled: boolean;
|
|
32
|
+
publishedAt: Date | null;
|
|
33
|
+
modifiedAt: Date | null;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function archiveBlocks(archive: BlogArchive, postsPerPage: number): BlockNode[] {
|
|
37
|
+
return [
|
|
38
|
+
{ id: "archive-heading", type: "heading", props: { text: archive.name, level: 1, align: "start" } },
|
|
39
|
+
...(archive.description
|
|
40
|
+
? [{ id: "archive-description", type: "text", props: { body: archive.description } }]
|
|
41
|
+
: []),
|
|
42
|
+
{
|
|
43
|
+
id: "archive-posts",
|
|
44
|
+
type: "blogIndex",
|
|
45
|
+
props: {
|
|
46
|
+
prefix: "blog",
|
|
47
|
+
limit: postsPerPage,
|
|
48
|
+
...(archive.kind === "category" ? { category: archive.slug } : {}),
|
|
49
|
+
...(archive.kind === "tag" ? { tag: archive.slug } : {}),
|
|
50
|
+
...(archive.kind === "author" ? { author: archive.slug } : {}),
|
|
51
|
+
...(archive.kind === "date" ? { date: archive.slug.replaceAll("/", "-") } : {}),
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function archiveEyebrow(archive: BlogArchive, t: Translate): string {
|
|
58
|
+
return t(`blog.archive.${archive.kind}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Byline under a post's title: author, dates, categories. */
|
|
62
|
+
export function PostByline({
|
|
63
|
+
meta,
|
|
64
|
+
t,
|
|
65
|
+
locale,
|
|
66
|
+
href,
|
|
67
|
+
}: {
|
|
68
|
+
meta: PostMeta;
|
|
69
|
+
t: Translate;
|
|
70
|
+
locale: string;
|
|
71
|
+
href: (path: string) => string;
|
|
72
|
+
}) {
|
|
73
|
+
const format = (date: Date) => new Intl.DateTimeFormat(locale, { dateStyle: "long" }).format(date);
|
|
74
|
+
const updated =
|
|
75
|
+
meta.modifiedAt && meta.publishedAt && meta.modifiedAt.getTime() - meta.publishedAt.getTime() > 24 * 60 * 60 * 1000
|
|
76
|
+
? meta.modifiedAt
|
|
77
|
+
: null;
|
|
78
|
+
return (
|
|
79
|
+
<p className="flex flex-wrap items-center gap-x-3 gap-y-1 text-sm text-ink-muted">
|
|
80
|
+
{meta.author ? (
|
|
81
|
+
<span>
|
|
82
|
+
{t("blog.by")}{" "}
|
|
83
|
+
<a className="font-medium text-ink underline underline-offset-4" href={href(`/${meta.author.path}`)} rel="author">
|
|
84
|
+
{meta.author.name}
|
|
85
|
+
</a>
|
|
86
|
+
</span>
|
|
87
|
+
) : null}
|
|
88
|
+
{meta.publishedAt ? (
|
|
89
|
+
<span>
|
|
90
|
+
<time dateTime={meta.publishedAt.toISOString()}>{format(meta.publishedAt)}</time>
|
|
91
|
+
</span>
|
|
92
|
+
) : null}
|
|
93
|
+
{updated ? (
|
|
94
|
+
<span>
|
|
95
|
+
{t("blog.updated")} <time dateTime={updated.toISOString()}>{format(updated)}</time>
|
|
96
|
+
</span>
|
|
97
|
+
) : null}
|
|
98
|
+
{meta.categories.length ? (
|
|
99
|
+
<span className="flex flex-wrap gap-x-2">
|
|
100
|
+
{meta.categories.map((category) => (
|
|
101
|
+
<a key={category.path} className="underline underline-offset-4" href={href(`/${category.path}`)}>
|
|
102
|
+
{category.name}
|
|
103
|
+
</a>
|
|
104
|
+
))}
|
|
105
|
+
</span>
|
|
106
|
+
) : null}
|
|
107
|
+
</p>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Tags and the author's note, after the post. */
|
|
112
|
+
export function PostFooter({
|
|
113
|
+
meta,
|
|
114
|
+
t,
|
|
115
|
+
href,
|
|
116
|
+
}: {
|
|
117
|
+
meta: PostMeta;
|
|
118
|
+
t: Translate;
|
|
119
|
+
href: (path: string) => string;
|
|
120
|
+
}) {
|
|
121
|
+
if (!meta.tags.length && !meta.author?.bio) return null;
|
|
122
|
+
return (
|
|
123
|
+
<footer className="grid gap-4 border-t border-rule pt-6">
|
|
124
|
+
{meta.tags.length ? (
|
|
125
|
+
<nav aria-label={t("blog.tags")}>
|
|
126
|
+
<ul className="flex list-none flex-wrap gap-2 p-0">
|
|
127
|
+
{meta.tags.map((tag) => (
|
|
128
|
+
<li key={tag.path}>
|
|
129
|
+
<a
|
|
130
|
+
className="inline-flex rounded-full border border-rule px-3 py-1 text-sm text-ink underline-offset-4 hover:underline"
|
|
131
|
+
href={href(`/${tag.path}`)}
|
|
132
|
+
rel="tag"
|
|
133
|
+
>
|
|
134
|
+
{tag.name}
|
|
135
|
+
</a>
|
|
136
|
+
</li>
|
|
137
|
+
))}
|
|
138
|
+
</ul>
|
|
139
|
+
</nav>
|
|
140
|
+
) : null}
|
|
141
|
+
{meta.author?.bio ? (
|
|
142
|
+
<section aria-label={t("blog.aboutAuthor")} className="grid gap-1 text-sm">
|
|
143
|
+
<p className="font-semibold text-ink">
|
|
144
|
+
<a className="underline underline-offset-4" href={href(`/${meta.author.path}`)}>
|
|
145
|
+
{meta.author.name}
|
|
146
|
+
</a>
|
|
147
|
+
</p>
|
|
148
|
+
<p className="max-w-prose text-ink-muted">{meta.author.bio}</p>
|
|
149
|
+
</section>
|
|
150
|
+
) : null}
|
|
151
|
+
</footer>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"use server";
|
|
4
|
+
import { redirect } from "next/navigation";
|
|
5
|
+
import { submitReaderComment } from "@/modules/cms/blog-comments";
|
|
6
|
+
|
|
7
|
+
export async function submitReaderCommentAction(form: FormData) {
|
|
8
|
+
const value = (key: string) => { const field = form.get(key); return typeof field === "string" ? field.trim() : ""; };
|
|
9
|
+
const back = value("returnTo");
|
|
10
|
+
const path = back.startsWith("/") && !back.startsWith("//") && !/[\\\r\n]/.test(back) ? back.split(/[?#]/)[0]! : "/";
|
|
11
|
+
let result = "pending";
|
|
12
|
+
try {
|
|
13
|
+
await submitReaderComment.call({ pageId: value("pageId"), parentId: value("parentId") || null, name: value("name"), email: value("email"), body: value("body"), website: value("website") }, { kind: "anonymous" });
|
|
14
|
+
} catch { result = "error"; }
|
|
15
|
+
redirect(`${path}?comment=${result}#comments`);
|
|
16
|
+
}
|
|
@@ -28,6 +28,7 @@ import { resolveRedirect } from "@/core/seo/service";
|
|
|
28
28
|
import {
|
|
29
29
|
articleJsonLd,
|
|
30
30
|
breadcrumbJsonLd,
|
|
31
|
+
breadcrumbTrailJsonLd,
|
|
31
32
|
collectionPageJsonLd,
|
|
32
33
|
creativeWorkJsonLd,
|
|
33
34
|
eventJsonLd,
|
|
@@ -53,7 +54,8 @@ import { getLocale, getT, requestedLocale } from "../../i18n";
|
|
|
53
54
|
import { alternatesFor, localePath, translatedLocales } from "./alternates";
|
|
54
55
|
import { recordPageView } from "./pageview";
|
|
55
56
|
import { currentBusiness } from "@/core/settings/read";
|
|
56
|
-
import { publishedPage } from "@/modules/cms/read";
|
|
57
|
+
import { blogArchiveAt, blogSettingsCached, postMetaFor, publishedPage } from "@/modules/cms/read";
|
|
58
|
+
import { archiveBlocks, archiveEyebrow, PostByline, PostFooter, type BlogArchive, type PostMeta } from "./blog-parts";
|
|
57
59
|
import { assignmentsFor } from "@/modules/cms/experiments";
|
|
58
60
|
import { ANON_HEADER, SESSION_HEADER } from "@/modules/analytics/visitor";
|
|
59
61
|
import { SESSION_COOKIE } from "@/core/auth/sessions";
|
|
@@ -67,6 +69,7 @@ import {
|
|
|
67
69
|
} from "@/core/http/csp";
|
|
68
70
|
import { targetFor } from "@/modules/share/service";
|
|
69
71
|
import { ShareBar } from "../ShareBar";
|
|
72
|
+
import { ReaderComments } from "./ReaderComments";
|
|
70
73
|
|
|
71
74
|
export const dynamic = "force-dynamic";
|
|
72
75
|
|
|
@@ -123,6 +126,8 @@ export async function generateMetadata({
|
|
|
123
126
|
currentBusiness(),
|
|
124
127
|
]);
|
|
125
128
|
if (!page) {
|
|
129
|
+
const archive = await blogArchiveAt(await pathFor(slug));
|
|
130
|
+
if (archive) return archiveMetadata(archive, business?.name, isFilterQuery(query));
|
|
126
131
|
// The 404 still needs a document title: an empty <title> is the first
|
|
127
132
|
// thing a screen reader announces (WCAG 2.4.2).
|
|
128
133
|
const t = await getT();
|
|
@@ -139,15 +144,24 @@ export async function generateMetadata({
|
|
|
139
144
|
title?: string;
|
|
140
145
|
description?: string;
|
|
141
146
|
ogImage?: string;
|
|
147
|
+
preserveTitle?: boolean;
|
|
148
|
+
preserveDescription?: boolean;
|
|
149
|
+
noindex?: boolean;
|
|
150
|
+
nofollow?: boolean;
|
|
151
|
+
canonical?: string;
|
|
152
|
+
ogTitle?: string;
|
|
153
|
+
ogDescription?: string;
|
|
142
154
|
};
|
|
143
155
|
const siteName = business?.name;
|
|
144
156
|
const title = composeDocumentTitle(
|
|
145
157
|
seo.title ?? page.title,
|
|
146
158
|
siteName,
|
|
147
159
|
page.slug === "",
|
|
160
|
+
seo.preserveTitle === true,
|
|
148
161
|
);
|
|
149
162
|
const description = composeDescription(
|
|
150
163
|
seo.description ?? business?.tagline ?? undefined,
|
|
164
|
+
seo.preserveDescription === true,
|
|
151
165
|
);
|
|
152
166
|
|
|
153
167
|
// §5 wants the canonical *absolute*, and absolute means configured rather
|
|
@@ -170,7 +184,7 @@ export async function generateMetadata({
|
|
|
170
184
|
? locale
|
|
171
185
|
: (business?.defaultLocale ?? locale);
|
|
172
186
|
|
|
173
|
-
const canonical = canonicalFor(origin, page.slug, servedLocale, business);
|
|
187
|
+
const canonical = seo.canonical ? new URL(seo.canonical, origin).href : canonicalFor(origin, page.slug, servedLocale, business);
|
|
174
188
|
|
|
175
189
|
// §34: the `ShareTarget` is "canonical URL + auto-generated OG image", so
|
|
176
190
|
// the social card is the share target's when the owner has written one. It
|
|
@@ -181,28 +195,45 @@ export async function generateMetadata({
|
|
|
181
195
|
const share = await targetFor
|
|
182
196
|
.call({ path: page.slug, locale: servedLocale }, ANONYMOUS)
|
|
183
197
|
.catch(() => null);
|
|
184
|
-
const socialTitle = share?.socialTitle ?? title;
|
|
185
|
-
const socialDescription = share?.socialDescription ?? description;
|
|
198
|
+
const socialTitle = share?.socialTitle ?? seo.ogTitle ?? title;
|
|
199
|
+
const socialDescription = share?.socialDescription ?? seo.ogDescription ?? description;
|
|
186
200
|
const ogImage =
|
|
187
201
|
share?.imageUrl ?? seo.ogImage ?? `${origin}${ogImagePath(page.slug)}`;
|
|
188
202
|
const filtered = isFilterQuery(query);
|
|
203
|
+
// C2.27: a post is an article to Open Graph, with its dates, author,
|
|
204
|
+
// section and tags, so a shared link reads as one.
|
|
205
|
+
const post = await postMetaFor(page.slug);
|
|
189
206
|
|
|
190
207
|
return {
|
|
191
208
|
title,
|
|
192
209
|
description,
|
|
193
|
-
robots: filtered ? { index:
|
|
210
|
+
robots: filtered || seo.noindex || seo.nofollow ? { index: !(filtered || seo.noindex), follow: !seo.nofollow } : undefined,
|
|
194
211
|
alternates: {
|
|
195
212
|
canonical,
|
|
196
213
|
...(alternates ? { languages: alternates } : {}),
|
|
197
214
|
},
|
|
198
|
-
openGraph:
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
215
|
+
openGraph: post
|
|
216
|
+
? {
|
|
217
|
+
title: socialTitle,
|
|
218
|
+
description: socialDescription,
|
|
219
|
+
type: "article",
|
|
220
|
+
url: canonical,
|
|
221
|
+
siteName: siteName ?? undefined,
|
|
222
|
+
images: [{ url: ogImage, width: 1200, height: 630, alt: socialTitle }],
|
|
223
|
+
...(post.publishedAt ? { publishedTime: post.publishedAt.toISOString() } : {}),
|
|
224
|
+
...(post.modifiedAt ? { modifiedTime: post.modifiedAt.toISOString() } : {}),
|
|
225
|
+
...(post.author ? { authors: [`${origin}/${post.author.path}`] } : {}),
|
|
226
|
+
...(post.categories[0] ? { section: post.categories[0].name } : {}),
|
|
227
|
+
...(post.tags.length ? { tags: post.tags.map((tag) => tag.name) } : {}),
|
|
228
|
+
}
|
|
229
|
+
: {
|
|
230
|
+
title: socialTitle,
|
|
231
|
+
description: socialDescription,
|
|
232
|
+
type: "website",
|
|
233
|
+
url: canonical,
|
|
234
|
+
siteName: siteName ?? undefined,
|
|
235
|
+
images: [{ url: ogImage, width: 1200, height: 630, alt: socialTitle }],
|
|
236
|
+
},
|
|
206
237
|
twitter: {
|
|
207
238
|
card: "summary_large_image",
|
|
208
239
|
title: socialTitle,
|
|
@@ -253,6 +284,11 @@ export default async function PublicPage({
|
|
|
253
284
|
// intact, and search engines treat 308 as 301's equal. The redirect *row*
|
|
254
285
|
// still records 301/302, so serving a literal 301 later is a change here and
|
|
255
286
|
// nowhere else.
|
|
287
|
+
// C2.27: a category, tag or author archive answers at its own path.
|
|
288
|
+
const archive = page ? null : await blogArchiveAt(path);
|
|
289
|
+
if (archive) {
|
|
290
|
+
return renderArchive({ archive, path, locale, t, business, query, nonce });
|
|
291
|
+
}
|
|
256
292
|
if (!page) {
|
|
257
293
|
const moved = await resolveRedirect.call({ path, locale }, ANONYMOUS);
|
|
258
294
|
if (moved) {
|
|
@@ -289,7 +325,8 @@ export default async function PublicPage({
|
|
|
289
325
|
}
|
|
290
326
|
const cookieJar = await cookies();
|
|
291
327
|
const actor = await actorFromToken(cookieJar.get(SESSION_COOKIE)?.value);
|
|
292
|
-
const
|
|
328
|
+
const post = await postMetaFor(page.slug);
|
|
329
|
+
const renderContext = {
|
|
293
330
|
locale,
|
|
294
331
|
t,
|
|
295
332
|
business: business ? {
|
|
@@ -317,7 +354,21 @@ export default async function PublicPage({
|
|
|
317
354
|
// a string, and a comparison with an array is simply false.
|
|
318
355
|
query: { ...query },
|
|
319
356
|
formReturn: decodeFormReturn(cookieJar.get(FORM_RETURN_COOKIE)?.value),
|
|
320
|
-
}
|
|
357
|
+
};
|
|
358
|
+
const localize = (href: string) => (business ? localizeCustomerHref(href, locale, business) : href);
|
|
359
|
+
// A post's byline sits under its title: render the leading H1 on its own,
|
|
360
|
+
// then the byline, then the rest of the body.
|
|
361
|
+
const titled = post && blocks[0]?.type === "heading" && blocks[0].props.level === 1;
|
|
362
|
+
const rendered = titled
|
|
363
|
+
? [
|
|
364
|
+
...(await renderBlocks([blocks[0]!], renderContext)),
|
|
365
|
+
<PostByline key="post-byline" meta={post} t={t} locale={locale} href={localize} />,
|
|
366
|
+
...(await renderBlocks(blocks.slice(1), renderContext)),
|
|
367
|
+
]
|
|
368
|
+
: [
|
|
369
|
+
...(post ? [<PostByline key="post-byline" meta={post} t={t} locale={locale} href={localize} />] : []),
|
|
370
|
+
...(await renderBlocks(blocks, renderContext)),
|
|
371
|
+
];
|
|
321
372
|
|
|
322
373
|
// Structured data comes from two places, and neither is a setting an owner
|
|
323
374
|
// has to find: the page's own identity (§5 — WebSite and the business on the
|
|
@@ -348,7 +399,10 @@ export default async function PublicPage({
|
|
|
348
399
|
localBusiness ?? organizationJsonLd(origin, facts),
|
|
349
400
|
]
|
|
350
401
|
: []),
|
|
351
|
-
...(
|
|
402
|
+
...(post
|
|
403
|
+
? postJsonLd({ origin, path, title: page.title, seo: page.seo, post, publisher: facts?.name ?? null, t })
|
|
404
|
+
: []),
|
|
405
|
+
...(path !== "" && !post
|
|
352
406
|
? [
|
|
353
407
|
breadcrumbJsonLd(origin, path, (segmentPath) =>
|
|
354
408
|
segmentPath === ""
|
|
@@ -359,7 +413,7 @@ export default async function PublicPage({
|
|
|
359
413
|
),
|
|
360
414
|
].filter((entry) => entry !== undefined)
|
|
361
415
|
: []),
|
|
362
|
-
...(await entityJsonLd({
|
|
416
|
+
...(post ? [] : await entityJsonLd({
|
|
363
417
|
origin,
|
|
364
418
|
path,
|
|
365
419
|
title: page.title,
|
|
@@ -382,7 +436,11 @@ export default async function PublicPage({
|
|
|
382
436
|
dangerouslySetInnerHTML={{ __html: serializeJsonLd(entry) }}
|
|
383
437
|
/>
|
|
384
438
|
))}
|
|
385
|
-
<article className="grid gap-8">
|
|
439
|
+
<article className="grid gap-8">
|
|
440
|
+
{rendered}
|
|
441
|
+
{post ? <PostFooter meta={post} t={t} href={localize} /> : null}
|
|
442
|
+
{post ? <ReaderComments pageValue={typeof query.commentPage === "string" ? query.commentPage : undefined} pageId={page.id} enabled={post.commentsEnabled} returnTo={localize(`/${path}`)} result={typeof query.comment === "string" ? query.comment : undefined} locale={locale} t={t} /> : null}
|
|
443
|
+
</article>
|
|
386
444
|
{/*
|
|
387
445
|
§34: sharing is "a property of every entity with a public face", so it
|
|
388
446
|
is rendered by the one public route rather than added per page. The
|
|
@@ -400,6 +458,112 @@ export default async function PublicPage({
|
|
|
400
458
|
);
|
|
401
459
|
}
|
|
402
460
|
|
|
461
|
+
/** Title, description, canonical and robots for a blog archive (C2.27). */
|
|
462
|
+
function archiveMetadata(archive: BlogArchive, siteName: string | undefined, filtered: boolean): Metadata {
|
|
463
|
+
const origin = siteOrigin();
|
|
464
|
+
const canonical = `${origin}/${archive.path}`;
|
|
465
|
+
const title = composeDocumentTitle(archive.seo.title ?? archive.name, siteName, false);
|
|
466
|
+
const description = composeDescription(archive.seo.description ?? archive.description ?? undefined);
|
|
467
|
+
return {
|
|
468
|
+
title,
|
|
469
|
+
description,
|
|
470
|
+
robots: archive.seo.noindex || filtered ? { index: false, follow: true } : undefined,
|
|
471
|
+
alternates: { canonical },
|
|
472
|
+
openGraph: { title, description, type: "website", url: canonical, siteName },
|
|
473
|
+
twitter: { card: "summary", title, description },
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
async function renderArchive(input: {
|
|
478
|
+
archive: BlogArchive;
|
|
479
|
+
path: string;
|
|
480
|
+
locale: string;
|
|
481
|
+
t: Awaited<ReturnType<typeof getT>>;
|
|
482
|
+
business: Awaited<ReturnType<typeof currentBusiness>>;
|
|
483
|
+
query: Record<string, string | string[] | undefined>;
|
|
484
|
+
nonce: string | undefined;
|
|
485
|
+
}) {
|
|
486
|
+
const { archive, path, locale, t, business, query, nonce } = input;
|
|
487
|
+
await recordPageView(`/${path}`, locale, query);
|
|
488
|
+
const settings = await blogSettingsCached();
|
|
489
|
+
const cookieJar = await cookies();
|
|
490
|
+
const actor = await actorFromToken(cookieJar.get(SESSION_COOKIE)?.value);
|
|
491
|
+
const rendered = await renderBlocks(archiveBlocks(archive, settings.postsPerPage), {
|
|
492
|
+
locale,
|
|
493
|
+
t,
|
|
494
|
+
business: business
|
|
495
|
+
? { name: business.name, tagline: business.tagline, defaultLocale: business.defaultLocale, enabledLocales: business.enabledLocales }
|
|
496
|
+
: null,
|
|
497
|
+
path: `/${path}`,
|
|
498
|
+
actor,
|
|
499
|
+
query: { ...query },
|
|
500
|
+
cspNonce: nonce,
|
|
501
|
+
localizeHref: business ? (href: string) => localizeCustomerHref(href, locale, business) : undefined,
|
|
502
|
+
});
|
|
503
|
+
const origin = siteOrigin();
|
|
504
|
+
const blog = await publishedPage("blog", locale);
|
|
505
|
+
const jsonLd = [
|
|
506
|
+
collectionPageJsonLd({
|
|
507
|
+
name: archive.name,
|
|
508
|
+
url: `${origin}/${archive.path}`,
|
|
509
|
+
description: archive.seo.description ?? archive.description,
|
|
510
|
+
}),
|
|
511
|
+
breadcrumbTrailJsonLd([
|
|
512
|
+
{ name: business?.name ?? t("home.brand"), item: `${origin}/` },
|
|
513
|
+
...(blog ? [{ name: blog.title, item: `${origin}/blog` }] : []),
|
|
514
|
+
...archive.trail.map((step) => ({ name: step.name, item: `${origin}/${step.path}` })),
|
|
515
|
+
{ name: archive.name, item: `${origin}/${archive.path}` },
|
|
516
|
+
]),
|
|
517
|
+
].filter((entry) => entry !== undefined);
|
|
518
|
+
return (
|
|
519
|
+
<>
|
|
520
|
+
{jsonLd.map((entry, i) => (
|
|
521
|
+
<script key={i} nonce={nonce} type="application/ld+json" dangerouslySetInnerHTML={{ __html: serializeJsonLd(entry) }} />
|
|
522
|
+
))}
|
|
523
|
+
<p className="text-sm font-semibold uppercase tracking-wide text-ink-muted">{archiveEyebrow(archive, t)}</p>
|
|
524
|
+
<div className="grid gap-8">{rendered}</div>
|
|
525
|
+
</>
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** BlogPosting and its breadcrumb: Home › Blog › primary category › post. */
|
|
530
|
+
function postJsonLd(input: {
|
|
531
|
+
origin: string;
|
|
532
|
+
path: string;
|
|
533
|
+
title: string;
|
|
534
|
+
seo: unknown;
|
|
535
|
+
post: PostMeta;
|
|
536
|
+
publisher: string | null;
|
|
537
|
+
t: Awaited<ReturnType<typeof getT>>;
|
|
538
|
+
}) {
|
|
539
|
+
const { origin, path, post } = input;
|
|
540
|
+
const seo = (input.seo ?? {}) as { title?: string; description?: string; ogImage?: string };
|
|
541
|
+
const url = `${origin}/${path}`;
|
|
542
|
+
const primary = post.categories[0];
|
|
543
|
+
return [
|
|
544
|
+
articleJsonLd({
|
|
545
|
+
type: "BlogPosting",
|
|
546
|
+
headline: input.title,
|
|
547
|
+
url,
|
|
548
|
+
description: seo.description ?? null,
|
|
549
|
+
datePublished: post.publishedAt,
|
|
550
|
+
dateModified: post.modifiedAt ?? post.publishedAt ?? undefined,
|
|
551
|
+
authorName: post.author?.name ?? input.publisher,
|
|
552
|
+
authorUrl: post.author ? `${origin}/${post.author.path}` : null,
|
|
553
|
+
section: primary?.name ?? null,
|
|
554
|
+
keywords: post.tags.map((tag) => tag.name),
|
|
555
|
+
image: seo.ogImage ?? null,
|
|
556
|
+
publisherName: input.publisher,
|
|
557
|
+
}),
|
|
558
|
+
breadcrumbTrailJsonLd([
|
|
559
|
+
{ name: input.publisher ?? input.t("home.brand"), item: `${origin}/` },
|
|
560
|
+
{ name: input.t("blog.title"), item: `${origin}/blog` },
|
|
561
|
+
...(primary ? [{ name: primary.name, item: `${origin}/${primary.path}` }] : []),
|
|
562
|
+
{ name: input.title, item: url },
|
|
563
|
+
]),
|
|
564
|
+
].filter((entry) => entry !== undefined);
|
|
565
|
+
}
|
|
566
|
+
|
|
403
567
|
/**
|
|
404
568
|
* Page-type structured data beyond the site/business/breadcrumb.
|
|
405
569
|
*
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { readCookie } from "@/core/http/cookies";
|
|
4
|
+
import { readBoundedText } from "@/core/http/body";
|
|
5
|
+
import { serviceRoute } from "@/core/http/route";
|
|
6
|
+
import { SITE_CHAT_COOKIE } from "@/core/messaging/chat-cookie";
|
|
7
|
+
import { ServiceError } from "@/core/service";
|
|
8
|
+
import { previewCall } from "@/modules/assistant/service";
|
|
9
|
+
import { env } from "@/core/env";
|
|
10
|
+
import { json } from "@/core/http/respond";
|
|
11
|
+
|
|
12
|
+
export const dynamic = "force-dynamic";
|
|
13
|
+
const control = serviceRoute(previewCall, {
|
|
14
|
+
readInput: async (request) => {
|
|
15
|
+
const token = readCookie(request, SITE_CHAT_COOKIE);
|
|
16
|
+
if (!token) throw new ServiceError("not_found", "There is no active chat in this browser.");
|
|
17
|
+
const raw = await readBoundedText(request, 12288);
|
|
18
|
+
let body: unknown;
|
|
19
|
+
try { body = JSON.parse(raw); } catch { throw new ServiceError("validation", "Invalid call request."); }
|
|
20
|
+
if (!body || typeof body !== "object" || Array.isArray(body) || "token" in body) {
|
|
21
|
+
throw new ServiceError("validation", "Invalid call request.");
|
|
22
|
+
}
|
|
23
|
+
return { ...body, token };
|
|
24
|
+
},
|
|
25
|
+
present: (body) => ({ body, headers: { "cache-control": "private, no-store" } }),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export function POST(request: Request): Promise<Response> {
|
|
29
|
+
const origin = request.headers.get("origin");
|
|
30
|
+
if (request.headers.get("sec-fetch-site") === "cross-site"
|
|
31
|
+
|| (origin && ![new URL(request.url).origin, new URL(env().APP_URL).origin].includes(origin))) {
|
|
32
|
+
return Promise.resolve(json({ error: "Cross-site chat refused." }, 403));
|
|
33
|
+
}
|
|
34
|
+
return control(request);
|
|
35
|
+
}
|