create-brainerce-store 1.37.0 → 1.40.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/dist/index.js +8 -3
- package/package.json +1 -1
- package/templates/nextjs/base/src/app/faq/page.tsx.ejs +46 -0
- package/templates/nextjs/base/src/app/home-client.tsx +98 -0
- package/templates/nextjs/base/src/app/layout.tsx.ejs +37 -8
- package/templates/nextjs/base/src/app/page.tsx +53 -98
- package/templates/nextjs/base/src/app/pages/[slug]/page.tsx.ejs +87 -0
- package/templates/nextjs/base/src/app/products/[slug]/page.tsx +5 -3
- package/templates/nextjs/base/src/components/content/announcement-bar.tsx.ejs +125 -0
- package/templates/nextjs/base/src/components/content/faq-section.tsx.ejs +75 -0
- package/templates/nextjs/base/src/components/content/rich-text-block.tsx.ejs +32 -0
- package/templates/nextjs/base/src/components/content/site-footer.tsx.ejs +164 -0
- package/templates/nextjs/base/src/components/content/site-header.tsx.ejs +142 -0
- package/templates/nextjs/base/src/components/seo/organization-json-ld.tsx +94 -0
- package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +6 -1
- package/templates/nextjs/base/src/i18n.ts.ejs +8 -3
- package/templates/nextjs/base/src/lib/sanitize.ts.ejs +26 -0
- package/templates/nextjs/base/src/lib/seo.ts +49 -0
- package/templates/nextjs/base/src/components/layout/footer.tsx +0 -47
- package/templates/nextjs/base/src/components/layout/header.tsx +0 -335
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var require_package = __commonJS({
|
|
|
31
31
|
"package.json"(exports2, module2) {
|
|
32
32
|
module2.exports = {
|
|
33
33
|
name: "create-brainerce-store",
|
|
34
|
-
version: "1.
|
|
34
|
+
version: "1.40.0",
|
|
35
35
|
description: "Scaffold a production-ready e-commerce storefront connected to Brainerce",
|
|
36
36
|
bin: {
|
|
37
37
|
"create-brainerce-store": "dist/index.js"
|
|
@@ -153,7 +153,10 @@ var ALLOWED_PACKAGE_MANAGERS = [
|
|
|
153
153
|
"bun"
|
|
154
154
|
];
|
|
155
155
|
var BRAINERCE_RUNTIME_DEPS = Object.freeze({
|
|
156
|
-
|
|
156
|
+
// 1.26 = adds client.content namespace (FAQ / Footer / Header / Announcement /
|
|
157
|
+
// RichText / Page). Scaffolded stores need this minimum to use the content
|
|
158
|
+
// components shipped under src/components/content/.
|
|
159
|
+
brainerce: "^1.26.0",
|
|
157
160
|
"isomorphic-dompurify": "^3.8.0"
|
|
158
161
|
});
|
|
159
162
|
|
|
@@ -332,8 +335,10 @@ async function runInteractive(defaults) {
|
|
|
332
335
|
var import_path = __toESM(require("path"));
|
|
333
336
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
334
337
|
var import_ejs = __toESM(require("ejs"));
|
|
338
|
+
var RTL_LANGUAGE_PRIMARIES = /* @__PURE__ */ new Set(["ar", "he", "fa", "ur", "yi"]);
|
|
335
339
|
function getDirection(language) {
|
|
336
|
-
|
|
340
|
+
const primary = language.split("-")[0].toLowerCase();
|
|
341
|
+
return RTL_LANGUAGE_PRIMARIES.has(primary) ? "rtl" : "ltr";
|
|
337
342
|
}
|
|
338
343
|
function stripControlChars(value) {
|
|
339
344
|
return value.replace(/\p{Cc}/gu, "");
|
package/package.json
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FAQ page — fully driven by the merchant's dashboard configuration.
|
|
3
|
+
*
|
|
4
|
+
* The merchant configures FAQs in the Brainerce dashboard under
|
|
5
|
+
* Sell → Content → FAQ
|
|
6
|
+
*
|
|
7
|
+
* This page fetches the merchant's *primary* FAQ (key='main'). For topical
|
|
8
|
+
* FAQs (e.g. /faq/shipping), copy this route to `app/faq/[topic]/page.tsx`
|
|
9
|
+
* and pass `params.topic` to `client.content.faq.get(topic, locale)`.
|
|
10
|
+
*/
|
|
11
|
+
import * as React from 'react';
|
|
12
|
+
import type { Metadata } from 'next';
|
|
13
|
+
|
|
14
|
+
import { getServerClient } from '@/lib/brainerce';
|
|
15
|
+
import { FaqSection } from '@/components/content/faq-section';
|
|
16
|
+
<% if (i18nEnabled) { %>
|
|
17
|
+
type PageProps = {
|
|
18
|
+
params: Promise<{ locale: string }>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
|
|
22
|
+
const { locale } = await params;
|
|
23
|
+
const faq = await getServerClient(locale).content.faq.get('main', locale).catch(() => null);
|
|
24
|
+
return {
|
|
25
|
+
title: faq?.name ?? 'FAQ',
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default async function FaqPage({ params }: PageProps) {
|
|
30
|
+
const { locale } = await params;
|
|
31
|
+
const faq = await getServerClient(locale).content.faq.get('main', locale).catch(() => null);
|
|
32
|
+
return <FaqSection faq={faq} />;
|
|
33
|
+
}
|
|
34
|
+
<% } else { %>
|
|
35
|
+
export async function generateMetadata(): Promise<Metadata> {
|
|
36
|
+
const faq = await getServerClient().content.faq.get('main').catch(() => null);
|
|
37
|
+
return {
|
|
38
|
+
title: faq?.name ?? 'FAQ',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default async function FaqPage() {
|
|
43
|
+
const faq = await getServerClient().content.faq.get('main').catch(() => null);
|
|
44
|
+
return <FaqSection faq={faq} />;
|
|
45
|
+
}
|
|
46
|
+
<% } %>
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { Link } from '@/lib/navigation';
|
|
5
|
+
import type { Product, DiscountBanner } from 'brainerce';
|
|
6
|
+
import { getClient } from '@/lib/brainerce';
|
|
7
|
+
import { useStoreInfo } from '@/providers/store-provider';
|
|
8
|
+
import { ProductGrid } from '@/components/products/product-grid';
|
|
9
|
+
import { LoadingSpinner } from '@/components/shared/loading-spinner';
|
|
10
|
+
import { useTranslations } from '@/lib/translations';
|
|
11
|
+
|
|
12
|
+
export function HomeClient() {
|
|
13
|
+
const { storeInfo, loading: storeLoading } = useStoreInfo();
|
|
14
|
+
const [products, setProducts] = useState<Product[]>([]);
|
|
15
|
+
const [banners, setBanners] = useState<DiscountBanner[]>([]);
|
|
16
|
+
const [loading, setLoading] = useState(true);
|
|
17
|
+
const t = useTranslations('home');
|
|
18
|
+
const tc = useTranslations('common');
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
async function load() {
|
|
22
|
+
try {
|
|
23
|
+
const client = getClient();
|
|
24
|
+
const [productsRes, bannersRes] = await Promise.allSettled([
|
|
25
|
+
client.getProducts({ limit: 8, sortBy: 'createdAt', sortOrder: 'desc' }),
|
|
26
|
+
client.getDiscountBanners(),
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
if (productsRes.status === 'fulfilled') {
|
|
30
|
+
setProducts(productsRes.value.data);
|
|
31
|
+
}
|
|
32
|
+
if (bannersRes.status === 'fulfilled') {
|
|
33
|
+
setBanners(bannersRes.value);
|
|
34
|
+
}
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.error('Failed to load home page data:', err);
|
|
37
|
+
} finally {
|
|
38
|
+
setLoading(false);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
load();
|
|
43
|
+
}, []);
|
|
44
|
+
|
|
45
|
+
if (storeLoading || loading) {
|
|
46
|
+
return (
|
|
47
|
+
<div className="flex min-h-[60vh] items-center justify-center">
|
|
48
|
+
<LoadingSpinner size="lg" />
|
|
49
|
+
</div>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div>
|
|
55
|
+
{/* Discount Banners */}
|
|
56
|
+
{banners.length > 0 && (
|
|
57
|
+
<div className="bg-primary text-primary-foreground">
|
|
58
|
+
<div className="mx-auto max-w-7xl px-4 py-2 sm:px-6 lg:px-8">
|
|
59
|
+
<div className="flex items-center justify-center gap-4 overflow-x-auto text-sm font-medium">
|
|
60
|
+
{banners.map((banner) => (
|
|
61
|
+
<span key={banner.ruleId}>{banner.text}</span>
|
|
62
|
+
))}
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
)}
|
|
67
|
+
|
|
68
|
+
{/* Hero Section */}
|
|
69
|
+
<section className="bg-muted">
|
|
70
|
+
<div className="mx-auto max-w-7xl px-4 py-20 text-center sm:px-6 lg:px-8">
|
|
71
|
+
<h1 className="text-foreground text-4xl font-bold tracking-tight sm:text-5xl">
|
|
72
|
+
{t('welcomeTo')} {storeInfo?.name || tc('store')}
|
|
73
|
+
</h1>
|
|
74
|
+
<p className="text-muted-foreground mx-auto mt-4 max-w-2xl text-lg">
|
|
75
|
+
{t('heroSubtitle')}
|
|
76
|
+
</p>
|
|
77
|
+
<Link
|
|
78
|
+
href="/products"
|
|
79
|
+
className="bg-primary text-primary-foreground mt-8 inline-flex items-center rounded px-6 py-3 font-medium transition-opacity hover:opacity-90"
|
|
80
|
+
>
|
|
81
|
+
{tc('shopNow')}
|
|
82
|
+
</Link>
|
|
83
|
+
</div>
|
|
84
|
+
</section>
|
|
85
|
+
|
|
86
|
+
{/* Featured Products */}
|
|
87
|
+
<section className="mx-auto max-w-7xl px-4 py-16 sm:px-6 lg:px-8">
|
|
88
|
+
<div className="mb-8 flex items-center justify-between">
|
|
89
|
+
<h2 className="text-foreground text-2xl font-bold">{t('featuredProducts')}</h2>
|
|
90
|
+
<Link href="/products" className="text-primary text-sm font-medium hover:underline">
|
|
91
|
+
{tc('viewAll')}
|
|
92
|
+
</Link>
|
|
93
|
+
</div>
|
|
94
|
+
<ProductGrid products={products} />
|
|
95
|
+
</section>
|
|
96
|
+
</div>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import type { Metadata } from 'next';
|
|
3
3
|
<%- fontImport %>
|
|
4
4
|
import { StoreProvider } from '@/providers/store-provider';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { AnnouncementBar } from '@/components/content/announcement-bar';
|
|
6
|
+
import { SiteHeader } from '@/components/content/site-header';
|
|
7
|
+
import { SiteFooter } from '@/components/content/site-footer';
|
|
8
|
+
import { getServerClient } from '@/lib/brainerce';
|
|
7
9
|
import { getDirection, supportedLocales } from '@/i18n';
|
|
8
10
|
import { getNonce } from '@/lib/nonce';
|
|
9
11
|
import '../globals.css';
|
|
@@ -54,6 +56,17 @@ export default async function RootLayout({
|
|
|
54
56
|
const dir = getDirection(locale);
|
|
55
57
|
const nonce = await getNonce();
|
|
56
58
|
|
|
59
|
+
// Merchant-driven layout chrome — fetched server-side. Each call falls back
|
|
60
|
+
// to null/[] on 404 so the layout never crashes when the merchant hasn't
|
|
61
|
+
// seeded a particular content type yet. New stores ship with default rows
|
|
62
|
+
// seeded by the backend (StoresService.seedDefaultContent).
|
|
63
|
+
const client = getServerClient(locale);
|
|
64
|
+
const [announcements, siteHeader, siteFooter] = await Promise.all([
|
|
65
|
+
client.content.announcement.list(locale).catch(() => []),
|
|
66
|
+
client.content.header.get('main', locale).catch(() => null),
|
|
67
|
+
client.content.footer.get('main', locale).catch(() => null),
|
|
68
|
+
]);
|
|
69
|
+
|
|
57
70
|
return (
|
|
58
71
|
<html lang={locale} dir={dir}>
|
|
59
72
|
<head>
|
|
@@ -72,9 +85,10 @@ export default async function RootLayout({
|
|
|
72
85
|
<body className={font.className}>
|
|
73
86
|
<StoreProvider locale={locale}>
|
|
74
87
|
<div className="min-h-screen flex flex-col">
|
|
75
|
-
<
|
|
88
|
+
<AnnouncementBar announcements={announcements} />
|
|
89
|
+
<SiteHeader header={siteHeader} storeName={<%- storeNameJs %>} />
|
|
76
90
|
<main className="flex-1">{children}</main>
|
|
77
|
-
<
|
|
91
|
+
<SiteFooter footer={siteFooter} storeName={<%- storeNameJs %>} />
|
|
78
92
|
</div>
|
|
79
93
|
</StoreProvider>
|
|
80
94
|
</body>
|
|
@@ -85,8 +99,10 @@ export default async function RootLayout({
|
|
|
85
99
|
import type { Metadata } from 'next';
|
|
86
100
|
<%- fontImport %>
|
|
87
101
|
import { StoreProvider } from '@/providers/store-provider';
|
|
88
|
-
import {
|
|
89
|
-
import {
|
|
102
|
+
import { AnnouncementBar } from '@/components/content/announcement-bar';
|
|
103
|
+
import { SiteHeader } from '@/components/content/site-header';
|
|
104
|
+
import { SiteFooter } from '@/components/content/site-footer';
|
|
105
|
+
import { getServerClient } from '@/lib/brainerce';
|
|
90
106
|
import { getNonce } from '@/lib/nonce';
|
|
91
107
|
import './globals.css';
|
|
92
108
|
|
|
@@ -128,6 +144,18 @@ export default async function RootLayout({
|
|
|
128
144
|
children: React.ReactNode;
|
|
129
145
|
}) {
|
|
130
146
|
const nonce = await getNonce();
|
|
147
|
+
|
|
148
|
+
// Merchant-driven layout chrome — fetched server-side. Each call falls back
|
|
149
|
+
// to null/[] on 404 so the layout never crashes when the merchant hasn't
|
|
150
|
+
// seeded a particular content type yet. New stores ship with default rows
|
|
151
|
+
// seeded by the backend (StoresService.seedDefaultContent).
|
|
152
|
+
const client = getServerClient();
|
|
153
|
+
const [announcements, siteHeader, siteFooter] = await Promise.all([
|
|
154
|
+
client.content.announcement.list().catch(() => []),
|
|
155
|
+
client.content.header.get('main').catch(() => null),
|
|
156
|
+
client.content.footer.get('main').catch(() => null),
|
|
157
|
+
]);
|
|
158
|
+
|
|
131
159
|
return (
|
|
132
160
|
<html lang="<%= language %>" dir="<%= direction %>">
|
|
133
161
|
<head>
|
|
@@ -146,9 +174,10 @@ export default async function RootLayout({
|
|
|
146
174
|
<body className={font.className}>
|
|
147
175
|
<StoreProvider>
|
|
148
176
|
<div className="min-h-screen flex flex-col">
|
|
149
|
-
<
|
|
177
|
+
<AnnouncementBar announcements={announcements} />
|
|
178
|
+
<SiteHeader header={siteHeader} storeName={<%- storeNameJs %>} />
|
|
150
179
|
<main className="flex-1">{children}</main>
|
|
151
|
-
<
|
|
180
|
+
<SiteFooter footer={siteFooter} storeName={<%- storeNameJs %>} />
|
|
152
181
|
</div>
|
|
153
182
|
</StoreProvider>
|
|
154
183
|
</body>
|
|
@@ -1,98 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
<div>
|
|
55
|
-
{/* Discount Banners */}
|
|
56
|
-
{banners.length > 0 && (
|
|
57
|
-
<div className="bg-primary text-primary-foreground">
|
|
58
|
-
<div className="mx-auto max-w-7xl px-4 py-2 sm:px-6 lg:px-8">
|
|
59
|
-
<div className="flex items-center justify-center gap-4 overflow-x-auto text-sm font-medium">
|
|
60
|
-
{banners.map((banner) => (
|
|
61
|
-
<span key={banner.ruleId}>{banner.text}</span>
|
|
62
|
-
))}
|
|
63
|
-
</div>
|
|
64
|
-
</div>
|
|
65
|
-
</div>
|
|
66
|
-
)}
|
|
67
|
-
|
|
68
|
-
{/* Hero Section */}
|
|
69
|
-
<section className="bg-muted">
|
|
70
|
-
<div className="mx-auto max-w-7xl px-4 py-20 text-center sm:px-6 lg:px-8">
|
|
71
|
-
<h1 className="text-foreground text-4xl font-bold tracking-tight sm:text-5xl">
|
|
72
|
-
{t('welcomeTo')} {storeInfo?.name || tc('store')}
|
|
73
|
-
</h1>
|
|
74
|
-
<p className="text-muted-foreground mx-auto mt-4 max-w-2xl text-lg">
|
|
75
|
-
{t('heroSubtitle')}
|
|
76
|
-
</p>
|
|
77
|
-
<Link
|
|
78
|
-
href="/products"
|
|
79
|
-
className="bg-primary text-primary-foreground mt-8 inline-flex items-center rounded px-6 py-3 font-medium transition-opacity hover:opacity-90"
|
|
80
|
-
>
|
|
81
|
-
{tc('shopNow')}
|
|
82
|
-
</Link>
|
|
83
|
-
</div>
|
|
84
|
-
</section>
|
|
85
|
-
|
|
86
|
-
{/* Featured Products */}
|
|
87
|
-
<section className="mx-auto max-w-7xl px-4 py-16 sm:px-6 lg:px-8">
|
|
88
|
-
<div className="mb-8 flex items-center justify-between">
|
|
89
|
-
<h2 className="text-foreground text-2xl font-bold">{t('featuredProducts')}</h2>
|
|
90
|
-
<Link href="/products" className="text-primary text-sm font-medium hover:underline">
|
|
91
|
-
{tc('viewAll')}
|
|
92
|
-
</Link>
|
|
93
|
-
</div>
|
|
94
|
-
<ProductGrid products={products} />
|
|
95
|
-
</section>
|
|
96
|
-
</div>
|
|
97
|
-
);
|
|
98
|
-
}
|
|
1
|
+
import type { Metadata } from 'next';
|
|
2
|
+
import { getServerClient } from '@/lib/brainerce';
|
|
3
|
+
import { buildMetaDescription } from '@/lib/seo';
|
|
4
|
+
import { OrganizationJsonLd } from '@/components/seo/organization-json-ld';
|
|
5
|
+
import { HomeClient } from './home-client';
|
|
6
|
+
|
|
7
|
+
// Build homepage metadata server-side so Google, Facebook, WhatsApp etc.
|
|
8
|
+
// see a real <meta name="description"> on first request. Falls back to the
|
|
9
|
+
// store name when the merchant hasn't authored a meta description yet.
|
|
10
|
+
export async function generateMetadata(): Promise<Metadata> {
|
|
11
|
+
try {
|
|
12
|
+
const storeInfo = await getServerClient().getStoreInfo();
|
|
13
|
+
const description = buildMetaDescription(storeInfo.metaDescription) || undefined;
|
|
14
|
+
return {
|
|
15
|
+
title: storeInfo.name,
|
|
16
|
+
description,
|
|
17
|
+
openGraph: {
|
|
18
|
+
title: storeInfo.name,
|
|
19
|
+
description,
|
|
20
|
+
type: 'website',
|
|
21
|
+
},
|
|
22
|
+
twitter: {
|
|
23
|
+
card: 'summary_large_image',
|
|
24
|
+
title: storeInfo.name,
|
|
25
|
+
description,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
} catch {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default async function HomePage() {
|
|
34
|
+
// Fetch store info server-side so the JSON-LD is in the initial HTML —
|
|
35
|
+
// crawlers and AI Overviews see it without needing to execute JavaScript.
|
|
36
|
+
// Failure here is non-fatal: the client component re-fetches via the
|
|
37
|
+
// StoreProvider so the page still renders.
|
|
38
|
+
let storeInfo = null;
|
|
39
|
+
try {
|
|
40
|
+
storeInfo = await getServerClient().getStoreInfo();
|
|
41
|
+
} catch {
|
|
42
|
+
storeInfo = null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || '';
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<>
|
|
49
|
+
{storeInfo && baseUrl ? <OrganizationJsonLd storeInfo={storeInfo} baseUrl={baseUrl} /> : null}
|
|
50
|
+
<HomeClient />
|
|
51
|
+
</>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static page route — fully driven by the merchant's dashboard.
|
|
3
|
+
*
|
|
4
|
+
* The merchant creates pages in the Brainerce dashboard under
|
|
5
|
+
* Sell → Content → Page (one row per page, each with its own `slug`)
|
|
6
|
+
*
|
|
7
|
+
* This catch-all renders any PAGE by its `data.slug`. `/pages/about` →
|
|
8
|
+
* fetches PAGE with slug='about'. Mounting under `/pages/` (rather than
|
|
9
|
+
* the root) keeps the route from clashing with existing static routes
|
|
10
|
+
* like /cart, /login, /products.
|
|
11
|
+
*
|
|
12
|
+
* Security: page HTML is sanitized via `sanitizeHtml` before injecting.
|
|
13
|
+
*/
|
|
14
|
+
import * as React from 'react';
|
|
15
|
+
import type { Metadata } from 'next';
|
|
16
|
+
import { notFound } from 'next/navigation';
|
|
17
|
+
|
|
18
|
+
import { getServerClient } from '@/lib/brainerce';
|
|
19
|
+
import { sanitizeHtml } from '@/lib/sanitize';
|
|
20
|
+
|
|
21
|
+
<% if (i18nEnabled) { %>
|
|
22
|
+
type PageProps = {
|
|
23
|
+
params: Promise<{ locale: string; slug: string }>;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
|
|
27
|
+
const { locale, slug } = await params;
|
|
28
|
+
const page = await getServerClient(locale).content.page.getBySlug(slug, locale).catch(() => null);
|
|
29
|
+
if (!page) return { title: slug };
|
|
30
|
+
const seo = page.data.seo ?? {};
|
|
31
|
+
return {
|
|
32
|
+
title: seo.title ?? page.data.title,
|
|
33
|
+
description: seo.description,
|
|
34
|
+
openGraph: seo.ogImage ? { images: [{ url: seo.ogImage }] } : undefined,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default async function StaticPage({ params }: PageProps) {
|
|
39
|
+
const { locale, slug } = await params;
|
|
40
|
+
const page = await getServerClient(locale).content.page.getBySlug(slug, locale).catch(() => null);
|
|
41
|
+
if (!page) notFound();
|
|
42
|
+
return (
|
|
43
|
+
<article className="mx-auto max-w-3xl px-4 py-10 sm:px-6 lg:px-8">
|
|
44
|
+
<h1 className="text-foreground mb-6 text-2xl font-semibold sm:text-3xl">
|
|
45
|
+
{page.data.title}
|
|
46
|
+
</h1>
|
|
47
|
+
<div
|
|
48
|
+
className="prose prose-sm dark:prose-invert max-w-none"
|
|
49
|
+
dangerouslySetInnerHTML={{ __html: sanitizeHtml(page.data.html) }}
|
|
50
|
+
/>
|
|
51
|
+
</article>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
<% } else { %>
|
|
55
|
+
type PageProps = {
|
|
56
|
+
params: Promise<{ slug: string }>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
|
|
60
|
+
const { slug } = await params;
|
|
61
|
+
const page = await getServerClient().content.page.getBySlug(slug).catch(() => null);
|
|
62
|
+
if (!page) return { title: slug };
|
|
63
|
+
const seo = page.data.seo ?? {};
|
|
64
|
+
return {
|
|
65
|
+
title: seo.title ?? page.data.title,
|
|
66
|
+
description: seo.description,
|
|
67
|
+
openGraph: seo.ogImage ? { images: [{ url: seo.ogImage }] } : undefined,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default async function StaticPage({ params }: PageProps) {
|
|
72
|
+
const { slug } = await params;
|
|
73
|
+
const page = await getServerClient().content.page.getBySlug(slug).catch(() => null);
|
|
74
|
+
if (!page) notFound();
|
|
75
|
+
return (
|
|
76
|
+
<article className="mx-auto max-w-3xl px-4 py-10 sm:px-6 lg:px-8">
|
|
77
|
+
<h1 className="text-foreground mb-6 text-2xl font-semibold sm:text-3xl">
|
|
78
|
+
{page.data.title}
|
|
79
|
+
</h1>
|
|
80
|
+
<div
|
|
81
|
+
className="prose prose-sm dark:prose-invert max-w-none"
|
|
82
|
+
dangerouslySetInnerHTML={{ __html: sanitizeHtml(page.data.html) }}
|
|
83
|
+
/>
|
|
84
|
+
</article>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
<% } %>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Metadata } from 'next';
|
|
2
2
|
import { notFound } from 'next/navigation';
|
|
3
3
|
import { getServerClient } from '@/lib/brainerce';
|
|
4
|
+
import { buildMetaDescription } from '@/lib/seo';
|
|
4
5
|
import { ProductJsonLd } from '@/components/seo/product-json-ld';
|
|
5
6
|
import { ReviewsSection } from '@/components/reviews/reviews-section';
|
|
6
7
|
import { ProductClientSection } from './product-client-section';
|
|
@@ -16,12 +17,13 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|
|
16
17
|
const client = getServerClient(locale);
|
|
17
18
|
const product = await client.getProductBySlug(slug);
|
|
18
19
|
const imageUrl = product.images?.[0]?.url;
|
|
19
|
-
// Prefer merchant-authored SEO copy; fall back to
|
|
20
|
-
//
|
|
20
|
+
// Prefer merchant-authored SEO copy; fall back to a stripped+truncated
|
|
21
|
+
// version of the visible description, then product name. We must NEVER
|
|
22
|
+
// emit raw HTML or a mid-word cut into <meta name="description">.
|
|
21
23
|
const seoTitle = (product as { seoTitle?: string | null }).seoTitle || product.name;
|
|
22
24
|
const seoDescription =
|
|
23
25
|
(product as { seoDescription?: string | null }).seoDescription ||
|
|
24
|
-
product.description
|
|
26
|
+
buildMetaDescription(product.description) ||
|
|
25
27
|
product.name;
|
|
26
28
|
|
|
27
29
|
return {
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storefront announcement bar — fully driven by the merchant's dashboard.
|
|
3
|
+
*
|
|
4
|
+
* The merchant configures announcements in the Brainerce dashboard under
|
|
5
|
+
* Sell → Content → Announcement
|
|
6
|
+
*
|
|
7
|
+
* Everything below is generic rendering logic — it adapts automatically to
|
|
8
|
+
* any announcement shape returned by the API, so **you should not hardcode
|
|
9
|
+
* the message or severity here**.
|
|
10
|
+
*
|
|
11
|
+
* API contract:
|
|
12
|
+
* GET → client.content.announcement.list(locale) → Content<'ANNOUNCEMENT'>[]
|
|
13
|
+
* Empty array → renders nothing (page layout stays intact).
|
|
14
|
+
*
|
|
15
|
+
* Time-bounded: each announcement may have `startsAt` / `endsAt` ISO
|
|
16
|
+
* timestamps. We filter client-side so the cached server response can be
|
|
17
|
+
* shared across visitors regardless of the current time.
|
|
18
|
+
*/
|
|
19
|
+
'use client';
|
|
20
|
+
|
|
21
|
+
import * as React from 'react';
|
|
22
|
+
import type { Content } from 'brainerce';
|
|
23
|
+
|
|
24
|
+
interface AnnouncementBarProps {
|
|
25
|
+
/** Pre-fetched list from the server. Pass `[]` to render nothing. */
|
|
26
|
+
announcements: Content<'ANNOUNCEMENT'>[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const SEVERITY_STYLES: Record<'info' | 'warning' | 'success', string> = {
|
|
30
|
+
info: 'bg-blue-600 text-white',
|
|
31
|
+
warning: 'bg-amber-500 text-amber-950',
|
|
32
|
+
success: 'bg-emerald-600 text-white',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const STORAGE_KEY = 'brainerce_dismissed_announcements';
|
|
36
|
+
|
|
37
|
+
export function AnnouncementBar({ announcements }: AnnouncementBarProps) {
|
|
38
|
+
const [dismissed, setDismissed] = React.useState<Set<string>>(() => new Set());
|
|
39
|
+
|
|
40
|
+
// Hydrate dismissals from localStorage on mount (avoids SSR/CSR mismatch).
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
if (typeof window === 'undefined') return;
|
|
43
|
+
try {
|
|
44
|
+
const raw = window.localStorage.getItem(STORAGE_KEY);
|
|
45
|
+
if (raw) setDismissed(new Set(JSON.parse(raw) as string[]));
|
|
46
|
+
} catch {
|
|
47
|
+
// ignore malformed storage
|
|
48
|
+
}
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
const dismiss = (id: string) => {
|
|
52
|
+
setDismissed((prev) => {
|
|
53
|
+
const next = new Set(prev);
|
|
54
|
+
next.add(id);
|
|
55
|
+
if (typeof window !== 'undefined') {
|
|
56
|
+
try {
|
|
57
|
+
window.localStorage.setItem(STORAGE_KEY, JSON.stringify([...next]));
|
|
58
|
+
} catch {
|
|
59
|
+
// ignore quota errors
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return next;
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const now = Date.now();
|
|
67
|
+
const visible = announcements.filter((a) => {
|
|
68
|
+
if (dismissed.has(a.id)) return false;
|
|
69
|
+
const startOk = !a.data.startsAt || new Date(a.data.startsAt).getTime() <= now;
|
|
70
|
+
const endOk = !a.data.endsAt || new Date(a.data.endsAt).getTime() >= now;
|
|
71
|
+
return startOk && endOk;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (visible.length === 0) return null;
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div role="region" aria-label="Site announcements">
|
|
78
|
+
{visible.map((announcement) => {
|
|
79
|
+
const severity = announcement.data.severity;
|
|
80
|
+
const tone = SEVERITY_STYLES[severity] ?? SEVERITY_STYLES.info;
|
|
81
|
+
return (
|
|
82
|
+
<div
|
|
83
|
+
key={announcement.id}
|
|
84
|
+
className={`flex items-center justify-center gap-3 px-4 py-2 text-sm ${tone}`}
|
|
85
|
+
>
|
|
86
|
+
<span className="flex-1 text-center">
|
|
87
|
+
{announcement.data.message}
|
|
88
|
+
{announcement.data.ctaHref && announcement.data.ctaLabel ? (
|
|
89
|
+
<>
|
|
90
|
+
{' '}
|
|
91
|
+
<a
|
|
92
|
+
href={announcement.data.ctaHref}
|
|
93
|
+
className="underline underline-offset-2"
|
|
94
|
+
>
|
|
95
|
+
{announcement.data.ctaLabel}
|
|
96
|
+
</a>
|
|
97
|
+
</>
|
|
98
|
+
) : null}
|
|
99
|
+
</span>
|
|
100
|
+
{announcement.data.dismissible ? (
|
|
101
|
+
<button
|
|
102
|
+
type="button"
|
|
103
|
+
onClick={() => dismiss(announcement.id)}
|
|
104
|
+
aria-label="Dismiss announcement"
|
|
105
|
+
className="text-current opacity-80 transition-opacity hover:opacity-100"
|
|
106
|
+
>
|
|
107
|
+
<svg
|
|
108
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
109
|
+
viewBox="0 0 24 24"
|
|
110
|
+
fill="none"
|
|
111
|
+
stroke="currentColor"
|
|
112
|
+
strokeWidth="2"
|
|
113
|
+
className="h-4 w-4"
|
|
114
|
+
aria-hidden="true"
|
|
115
|
+
>
|
|
116
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
|
|
117
|
+
</svg>
|
|
118
|
+
</button>
|
|
119
|
+
) : null}
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
})}
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
}
|