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
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FAQ accordion — 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
|
+
* Each FAQ row has a `key` (e.g. 'main', 'shipping', 'returns'). Pass the
|
|
8
|
+
* pre-fetched payload as `faq`; this component knows nothing about which
|
|
9
|
+
* key it came from.
|
|
10
|
+
*
|
|
11
|
+
* Security: FAQ answers may contain merchant-authored HTML — we sanitize
|
|
12
|
+
* via `sanitizeHtml` before injecting via dangerouslySetInnerHTML.
|
|
13
|
+
*/
|
|
14
|
+
'use client';
|
|
15
|
+
|
|
16
|
+
import * as React from 'react';
|
|
17
|
+
import type { Content } from 'brainerce';
|
|
18
|
+
import { sanitizeHtml } from '@/lib/sanitize';
|
|
19
|
+
|
|
20
|
+
interface FaqSectionProps {
|
|
21
|
+
/** Pre-fetched FAQ row. `null` triggers a minimal empty-state message. */
|
|
22
|
+
faq: Content<'FAQ'> | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function FaqSection({ faq }: FaqSectionProps) {
|
|
26
|
+
const [openIdx, setOpenIdx] = React.useState<number | null>(0);
|
|
27
|
+
|
|
28
|
+
if (!faq || !faq.data.items?.length) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<section className="mx-auto max-w-3xl px-4 py-10 sm:px-6 lg:px-8">
|
|
34
|
+
<h1 className="text-foreground mb-6 text-2xl font-semibold sm:text-3xl">{faq.name}</h1>
|
|
35
|
+
<ul className="border-border divide-border divide-y rounded-lg border">
|
|
36
|
+
{faq.data.items.map((item, idx) => {
|
|
37
|
+
const open = openIdx === idx;
|
|
38
|
+
return (
|
|
39
|
+
<li key={idx}>
|
|
40
|
+
<button
|
|
41
|
+
type="button"
|
|
42
|
+
onClick={() => setOpenIdx(open ? null : idx)}
|
|
43
|
+
aria-expanded={open}
|
|
44
|
+
className="hover:bg-muted/40 flex w-full items-center justify-between gap-4 p-4 text-start transition-colors"
|
|
45
|
+
>
|
|
46
|
+
<span className="text-foreground text-sm font-medium sm:text-base">
|
|
47
|
+
{item.question}
|
|
48
|
+
</span>
|
|
49
|
+
<svg
|
|
50
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
51
|
+
viewBox="0 0 24 24"
|
|
52
|
+
fill="none"
|
|
53
|
+
stroke="currentColor"
|
|
54
|
+
strokeWidth="2"
|
|
55
|
+
className={`text-muted-foreground h-4 w-4 transition-transform ${
|
|
56
|
+
open ? 'rotate-180' : ''
|
|
57
|
+
}`}
|
|
58
|
+
aria-hidden="true"
|
|
59
|
+
>
|
|
60
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
|
|
61
|
+
</svg>
|
|
62
|
+
</button>
|
|
63
|
+
{open ? (
|
|
64
|
+
<div
|
|
65
|
+
className="text-muted-foreground prose prose-sm dark:prose-invert max-w-none px-4 pb-4 text-sm leading-relaxed"
|
|
66
|
+
dangerouslySetInnerHTML={{ __html: sanitizeHtml(item.answer) }}
|
|
67
|
+
/>
|
|
68
|
+
) : null}
|
|
69
|
+
</li>
|
|
70
|
+
);
|
|
71
|
+
})}
|
|
72
|
+
</ul>
|
|
73
|
+
</section>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline rich-text block — fully driven by the merchant's dashboard.
|
|
3
|
+
*
|
|
4
|
+
* The merchant configures rich-text blocks in the Brainerce dashboard
|
|
5
|
+
* under Sell → Content → Rich Text. Use this component anywhere on a page
|
|
6
|
+
* to drop a merchant-editable HTML block (intro copy, banner descriptions,
|
|
7
|
+
* inline announcements that aren't tied to the top-of-page Announcement
|
|
8
|
+
* bar, etc.).
|
|
9
|
+
*
|
|
10
|
+
* Security: HTML is sanitized via `sanitizeHtml` (isomorphic-dompurify)
|
|
11
|
+
* before injecting via dangerouslySetInnerHTML.
|
|
12
|
+
*/
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
import type { Content } from 'brainerce';
|
|
15
|
+
import { sanitizeHtml } from '@/lib/sanitize';
|
|
16
|
+
|
|
17
|
+
interface RichTextBlockProps {
|
|
18
|
+
/** Pre-fetched RICH_TEXT row, e.g. via `client.content.richText.get(key, locale)`. */
|
|
19
|
+
block: Content<'RICH_TEXT'> | null;
|
|
20
|
+
/** Optional wrapper className for layout positioning. */
|
|
21
|
+
className?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function RichTextBlock({ block, className }: RichTextBlockProps) {
|
|
25
|
+
if (!block?.data?.html) return null;
|
|
26
|
+
return (
|
|
27
|
+
<div
|
|
28
|
+
className={className ?? 'prose prose-sm dark:prose-invert max-w-none'}
|
|
29
|
+
dangerouslySetInnerHTML={{ __html: sanitizeHtml(block.data.html) }}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storefront footer — fully driven by the merchant's dashboard configuration.
|
|
3
|
+
*
|
|
4
|
+
* The merchant configures the footer in the Brainerce dashboard under
|
|
5
|
+
* Sell → Content → Footer
|
|
6
|
+
*
|
|
7
|
+
* Renders a brand block (store-name + social icons), the merchant's link
|
|
8
|
+
* columns, and a copyright bar. Social icons are inline SVGs so the
|
|
9
|
+
* scaffold stays dependency-free; unknown platforms fall back to a
|
|
10
|
+
* letter avatar.
|
|
11
|
+
*
|
|
12
|
+
* API contract:
|
|
13
|
+
* GET → client.content.footer.get('main', locale) → Content<'FOOTER'> | null
|
|
14
|
+
* Returns null on 404 — we render a minimal fallback so the layout never
|
|
15
|
+
* crashes when the merchant hasn't seeded the footer yet.
|
|
16
|
+
*/
|
|
17
|
+
import * as React from 'react';
|
|
18
|
+
import type { Content } from 'brainerce';
|
|
19
|
+
|
|
20
|
+
interface SiteFooterProps {
|
|
21
|
+
/** Pre-fetched footer payload (server-side). `null` triggers fallback rendering. */
|
|
22
|
+
footer: Content<'FOOTER'> | null;
|
|
23
|
+
/** Store name shown in the brand block + fallback copyright. */
|
|
24
|
+
storeName?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type SvgComponent = React.ComponentType<React.SVGProps<SVGSVGElement>>;
|
|
28
|
+
|
|
29
|
+
const InstagramIcon: SvgComponent = (props) => (
|
|
30
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" {...props}>
|
|
31
|
+
<rect x="2" y="2" width="20" height="20" rx="5" ry="5" />
|
|
32
|
+
<path d="M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z" />
|
|
33
|
+
<line x1="17.5" y1="6.5" x2="17.51" y2="6.5" />
|
|
34
|
+
</svg>
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const FacebookIcon: SvgComponent = (props) => (
|
|
38
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" {...props}>
|
|
39
|
+
<path d="M18 2h-3a5 5 0 0 0-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 0 1 1-1h3z" />
|
|
40
|
+
</svg>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const XIcon: SvgComponent = (props) => (
|
|
44
|
+
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" {...props}>
|
|
45
|
+
<path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z" />
|
|
46
|
+
</svg>
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const LinkedInIcon: SvgComponent = (props) => (
|
|
50
|
+
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" {...props}>
|
|
51
|
+
<path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.852 3.37-1.852 3.601 0 4.267 2.37 4.267 5.455v6.288zM5.337 7.433a2.062 2.062 0 1 1 0-4.125 2.063 2.063 0 0 1 0 4.125zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.225 0z" />
|
|
52
|
+
</svg>
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const YouTubeIcon: SvgComponent = (props) => (
|
|
56
|
+
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" {...props}>
|
|
57
|
+
<path d="M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z" />
|
|
58
|
+
</svg>
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const TikTokIcon: SvgComponent = (props) => (
|
|
62
|
+
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" {...props}>
|
|
63
|
+
<path d="M19.59 6.69a4.83 4.83 0 0 1-3.77-4.25V2h-3.45v13.67a2.89 2.89 0 0 1-5.2 1.74 2.89 2.89 0 0 1 2.31-4.64 2.93 2.93 0 0 1 .88.13V9.4a6.84 6.84 0 0 0-1-.05A6.33 6.33 0 0 0 5.8 20.1a6.34 6.34 0 0 0 10.86-4.43v-7a8.16 8.16 0 0 0 4.77 1.52v-3.4a4.85 4.85 0 0 1-1.84-.1z" />
|
|
64
|
+
</svg>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const SOCIAL_ICONS: Record<string, SvgComponent> = {
|
|
68
|
+
instagram: InstagramIcon,
|
|
69
|
+
facebook: FacebookIcon,
|
|
70
|
+
x: XIcon,
|
|
71
|
+
twitter: XIcon,
|
|
72
|
+
linkedin: LinkedInIcon,
|
|
73
|
+
youtube: YouTubeIcon,
|
|
74
|
+
tiktok: TikTokIcon,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export function SiteFooter({ footer, storeName }: SiteFooterProps) {
|
|
78
|
+
const data = footer?.data;
|
|
79
|
+
const columns = data?.columns ?? [];
|
|
80
|
+
const social = data?.social ?? [];
|
|
81
|
+
const year = new Date().getFullYear();
|
|
82
|
+
const brandLabel = storeName ?? 'Store';
|
|
83
|
+
|
|
84
|
+
if (!data || (columns.length === 0 && !data.copyright && social.length === 0)) {
|
|
85
|
+
return (
|
|
86
|
+
<footer className="border-border bg-muted/30 text-muted-foreground mt-16 border-t py-8 text-sm">
|
|
87
|
+
<div className="mx-auto max-w-7xl px-4 text-center sm:px-6 lg:px-8">
|
|
88
|
+
© {year} {brandLabel}. All rights reserved.
|
|
89
|
+
</div>
|
|
90
|
+
</footer>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<footer className="border-border bg-muted/30 mt-16 border-t">
|
|
96
|
+
<div className="mx-auto max-w-7xl px-4 py-12 sm:px-6 lg:px-8">
|
|
97
|
+
<div className="grid grid-cols-1 gap-10 md:grid-cols-12">
|
|
98
|
+
<div className="md:col-span-4">
|
|
99
|
+
<a
|
|
100
|
+
href="/"
|
|
101
|
+
className="text-foreground text-lg font-semibold tracking-tight"
|
|
102
|
+
>
|
|
103
|
+
{brandLabel}
|
|
104
|
+
</a>
|
|
105
|
+
{social.length > 0 ? (
|
|
106
|
+
<div className="mt-4 flex flex-wrap items-center gap-2">
|
|
107
|
+
{social.map((entry, idx) => {
|
|
108
|
+
const key = entry.platform.toLowerCase();
|
|
109
|
+
const Icon = SOCIAL_ICONS[key];
|
|
110
|
+
return (
|
|
111
|
+
<a
|
|
112
|
+
key={`${entry.platform}-${idx}`}
|
|
113
|
+
href={entry.url}
|
|
114
|
+
target="_blank"
|
|
115
|
+
rel="noopener noreferrer"
|
|
116
|
+
aria-label={entry.platform}
|
|
117
|
+
className="border-border hover:border-foreground/40 hover:text-foreground text-muted-foreground inline-flex h-9 w-9 items-center justify-center rounded-full border transition-colors"
|
|
118
|
+
>
|
|
119
|
+
{Icon ? (
|
|
120
|
+
<Icon className="h-4 w-4" />
|
|
121
|
+
) : (
|
|
122
|
+
<span className="text-xs font-medium uppercase">
|
|
123
|
+
{entry.platform.charAt(0)}
|
|
124
|
+
</span>
|
|
125
|
+
)}
|
|
126
|
+
</a>
|
|
127
|
+
);
|
|
128
|
+
})}
|
|
129
|
+
</div>
|
|
130
|
+
) : null}
|
|
131
|
+
</div>
|
|
132
|
+
|
|
133
|
+
{columns.length > 0 ? (
|
|
134
|
+
<div className="grid grid-cols-2 gap-8 sm:grid-cols-3 md:col-span-8">
|
|
135
|
+
{columns.map((col, idx) => (
|
|
136
|
+
<div key={`${col.title}-${idx}`}>
|
|
137
|
+
<h3 className="text-foreground mb-3 text-sm font-semibold tracking-wide">
|
|
138
|
+
{col.title}
|
|
139
|
+
</h3>
|
|
140
|
+
<ul className="space-y-2">
|
|
141
|
+
{col.links.map((link, linkIdx) => (
|
|
142
|
+
<li key={`${link.url}-${linkIdx}`}>
|
|
143
|
+
<a
|
|
144
|
+
href={link.url}
|
|
145
|
+
className="text-muted-foreground hover:text-foreground text-sm transition-colors"
|
|
146
|
+
>
|
|
147
|
+
{link.label}
|
|
148
|
+
</a>
|
|
149
|
+
</li>
|
|
150
|
+
))}
|
|
151
|
+
</ul>
|
|
152
|
+
</div>
|
|
153
|
+
))}
|
|
154
|
+
</div>
|
|
155
|
+
) : null}
|
|
156
|
+
</div>
|
|
157
|
+
|
|
158
|
+
<div className="border-border text-muted-foreground mt-10 flex flex-col items-center justify-between gap-2 border-t pt-6 text-xs sm:flex-row">
|
|
159
|
+
<span>{data.copyright ?? `© ${year} ${brandLabel}. All rights reserved.`}</span>
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
</footer>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merchant-controlled site header.
|
|
3
|
+
*
|
|
4
|
+
* The merchant configures the header in the Brainerce dashboard under
|
|
5
|
+
* Sell → Content → Header
|
|
6
|
+
*
|
|
7
|
+
* Renders brand (logo or store-name fallback) + nav items + CTA + cart link,
|
|
8
|
+
* with a `<details>` mobile menu that works without client-side JS. Everything
|
|
9
|
+
* is generic — do NOT hardcode nav labels or logo paths here; the merchant
|
|
10
|
+
* edits them in the dashboard and the change propagates within ~5 minutes.
|
|
11
|
+
*
|
|
12
|
+
* Returns null on 404. New stores ship with a seeded HEADER row from the
|
|
13
|
+
* backend (StoresService.seedDefaultContent), so this should be populated
|
|
14
|
+
* out of the box.
|
|
15
|
+
*/
|
|
16
|
+
import * as React from 'react';
|
|
17
|
+
import type { Content } from 'brainerce';
|
|
18
|
+
|
|
19
|
+
interface SiteHeaderProps {
|
|
20
|
+
/** Pre-fetched header payload (server-side). `null` renders nothing. */
|
|
21
|
+
header: Content<'HEADER'> | null;
|
|
22
|
+
/** Fallback brand label when the merchant hasn't uploaded a logo yet. */
|
|
23
|
+
storeName?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const MenuIcon = (props: React.SVGProps<SVGSVGElement>) => (
|
|
27
|
+
<svg
|
|
28
|
+
viewBox="0 0 24 24"
|
|
29
|
+
fill="none"
|
|
30
|
+
stroke="currentColor"
|
|
31
|
+
strokeWidth={2}
|
|
32
|
+
strokeLinecap="round"
|
|
33
|
+
strokeLinejoin="round"
|
|
34
|
+
aria-hidden="true"
|
|
35
|
+
{...props}
|
|
36
|
+
>
|
|
37
|
+
<line x1="4" y1="6" x2="20" y2="6" />
|
|
38
|
+
<line x1="4" y1="12" x2="20" y2="12" />
|
|
39
|
+
<line x1="4" y1="18" x2="20" y2="18" />
|
|
40
|
+
</svg>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const CartIcon = (props: React.SVGProps<SVGSVGElement>) => (
|
|
44
|
+
<svg
|
|
45
|
+
viewBox="0 0 24 24"
|
|
46
|
+
fill="none"
|
|
47
|
+
stroke="currentColor"
|
|
48
|
+
strokeWidth={2}
|
|
49
|
+
strokeLinecap="round"
|
|
50
|
+
strokeLinejoin="round"
|
|
51
|
+
aria-hidden="true"
|
|
52
|
+
{...props}
|
|
53
|
+
>
|
|
54
|
+
<circle cx="9" cy="21" r="1" />
|
|
55
|
+
<circle cx="20" cy="21" r="1" />
|
|
56
|
+
<path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6" />
|
|
57
|
+
</svg>
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
export function SiteHeader({ header, storeName }: SiteHeaderProps) {
|
|
61
|
+
if (!header) return null;
|
|
62
|
+
const data = header.data;
|
|
63
|
+
const logo = data.logo;
|
|
64
|
+
const navItems = data.navItems ?? [];
|
|
65
|
+
const cta = data.cta;
|
|
66
|
+
const brandLabel = logo?.alt || storeName || 'Store';
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<header className="border-border bg-background/95 supports-[backdrop-filter]:bg-background/70 sticky top-0 z-40 border-b backdrop-blur">
|
|
70
|
+
<div className="mx-auto flex h-16 max-w-7xl items-center justify-between gap-4 px-4 sm:px-6 lg:px-8">
|
|
71
|
+
<a
|
|
72
|
+
href="/"
|
|
73
|
+
className="flex items-center gap-2 font-semibold tracking-tight"
|
|
74
|
+
aria-label={brandLabel}
|
|
75
|
+
>
|
|
76
|
+
{logo ? (
|
|
77
|
+
// eslint-disable-next-line @next/next/no-img-element -- merchant-supplied URL, dynamic optimization handled by CDN
|
|
78
|
+
<img src={logo.src} alt={logo.alt} className="h-8 w-auto" />
|
|
79
|
+
) : (
|
|
80
|
+
<span className="text-lg">{brandLabel}</span>
|
|
81
|
+
)}
|
|
82
|
+
</a>
|
|
83
|
+
|
|
84
|
+
{navItems.length > 0 ? (
|
|
85
|
+
<nav className="hidden items-center gap-8 md:flex">
|
|
86
|
+
{navItems.map((item, idx) => (
|
|
87
|
+
<a
|
|
88
|
+
key={`${item.url}-${idx}`}
|
|
89
|
+
href={item.url}
|
|
90
|
+
className="text-foreground/80 hover:text-foreground text-sm font-medium transition-colors"
|
|
91
|
+
>
|
|
92
|
+
{item.label}
|
|
93
|
+
</a>
|
|
94
|
+
))}
|
|
95
|
+
</nav>
|
|
96
|
+
) : null}
|
|
97
|
+
|
|
98
|
+
<div className="flex items-center gap-2">
|
|
99
|
+
{cta ? (
|
|
100
|
+
<a
|
|
101
|
+
href={cta.url}
|
|
102
|
+
className="bg-primary text-primary-foreground hidden items-center justify-center rounded-md px-4 py-2 text-sm font-medium transition-colors hover:opacity-90 sm:inline-flex"
|
|
103
|
+
>
|
|
104
|
+
{cta.label}
|
|
105
|
+
</a>
|
|
106
|
+
) : null}
|
|
107
|
+
|
|
108
|
+
<a
|
|
109
|
+
href="/cart"
|
|
110
|
+
aria-label="Cart"
|
|
111
|
+
className="text-foreground/80 hover:text-foreground hover:bg-muted/60 inline-flex h-9 w-9 items-center justify-center rounded-md transition-colors"
|
|
112
|
+
>
|
|
113
|
+
<CartIcon className="h-5 w-5" />
|
|
114
|
+
</a>
|
|
115
|
+
|
|
116
|
+
{navItems.length > 0 ? (
|
|
117
|
+
<details className="group relative md:hidden">
|
|
118
|
+
<summary className="text-foreground/80 hover:text-foreground hover:bg-muted/60 inline-flex h-9 w-9 cursor-pointer list-none items-center justify-center rounded-md transition-colors [&::-webkit-details-marker]:hidden">
|
|
119
|
+
<MenuIcon className="h-5 w-5" />
|
|
120
|
+
<span className="sr-only">Menu</span>
|
|
121
|
+
</summary>
|
|
122
|
+
<nav className="border-border bg-background absolute end-0 top-full z-50 mt-2 w-56 overflow-hidden rounded-lg border shadow-lg">
|
|
123
|
+
<ul className="py-1">
|
|
124
|
+
{navItems.map((item, idx) => (
|
|
125
|
+
<li key={`m-${item.url}-${idx}`}>
|
|
126
|
+
<a
|
|
127
|
+
href={item.url}
|
|
128
|
+
className="text-foreground/80 hover:text-foreground hover:bg-muted block px-4 py-2 text-sm transition-colors"
|
|
129
|
+
>
|
|
130
|
+
{item.label}
|
|
131
|
+
</a>
|
|
132
|
+
</li>
|
|
133
|
+
))}
|
|
134
|
+
</ul>
|
|
135
|
+
</nav>
|
|
136
|
+
</details>
|
|
137
|
+
) : null}
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
</header>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { StoreInfo } from 'brainerce';
|
|
2
|
+
import { getNonce } from '@/lib/nonce';
|
|
3
|
+
import { stripHtmlForSeo } from '@/lib/seo';
|
|
4
|
+
|
|
5
|
+
interface OrganizationJsonLdProps {
|
|
6
|
+
storeInfo: StoreInfo;
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Emits Organization + WebSite JSON-LD on the storefront homepage.
|
|
11
|
+
//
|
|
12
|
+
// Why these two specifically:
|
|
13
|
+
// - Organization → feeds the Google Knowledge Panel (store name, logo,
|
|
14
|
+
// description) and is the primary signal AI Overviews / ChatGPT /
|
|
15
|
+
// Perplexity ingest when citing the store.
|
|
16
|
+
// - WebSite → enables Sitelinks Searchbox (Google) and tells crawlers
|
|
17
|
+
// the canonical site URL. The `potentialAction` block is what makes
|
|
18
|
+
// the search box appear in branded SERP results.
|
|
19
|
+
export async function OrganizationJsonLd({ storeInfo, baseUrl }: OrganizationJsonLdProps) {
|
|
20
|
+
const nonce = await getNonce();
|
|
21
|
+
|
|
22
|
+
const cleanDescription = stripHtmlForSeo(storeInfo.metaDescription ?? undefined);
|
|
23
|
+
const logo =
|
|
24
|
+
typeof storeInfo.logo === 'string' && storeInfo.logo.trim() ? storeInfo.logo : undefined;
|
|
25
|
+
const contactEmail =
|
|
26
|
+
typeof storeInfo.contactEmail === 'string' && storeInfo.contactEmail.trim()
|
|
27
|
+
? storeInfo.contactEmail.trim()
|
|
28
|
+
: undefined;
|
|
29
|
+
const contactPhone =
|
|
30
|
+
typeof storeInfo.contactPhone === 'string' && storeInfo.contactPhone.trim()
|
|
31
|
+
? storeInfo.contactPhone.trim()
|
|
32
|
+
: undefined;
|
|
33
|
+
// sameAs is the JSON-LD property Google uses to associate a brand with its
|
|
34
|
+
// social profiles. Order doesn't matter; we just filter out empties.
|
|
35
|
+
const sameAs = storeInfo.socialLinks
|
|
36
|
+
? Object.values(storeInfo.socialLinks).filter(
|
|
37
|
+
(url): url is string => typeof url === 'string' && url.trim().length > 0,
|
|
38
|
+
)
|
|
39
|
+
: [];
|
|
40
|
+
|
|
41
|
+
const organizationJsonLd: Record<string, unknown> = {
|
|
42
|
+
'@context': 'https://schema.org',
|
|
43
|
+
'@type': 'Organization',
|
|
44
|
+
name: storeInfo.name,
|
|
45
|
+
url: baseUrl,
|
|
46
|
+
...(logo ? { logo } : {}),
|
|
47
|
+
...(cleanDescription ? { description: cleanDescription } : {}),
|
|
48
|
+
...(contactEmail ? { email: contactEmail } : {}),
|
|
49
|
+
...(contactPhone ? { telephone: contactPhone } : {}),
|
|
50
|
+
...(sameAs.length > 0 ? { sameAs } : {}),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const websiteJsonLd: Record<string, unknown> = {
|
|
54
|
+
'@context': 'https://schema.org',
|
|
55
|
+
'@type': 'WebSite',
|
|
56
|
+
name: storeInfo.name,
|
|
57
|
+
url: baseUrl,
|
|
58
|
+
potentialAction: {
|
|
59
|
+
'@type': 'SearchAction',
|
|
60
|
+
target: {
|
|
61
|
+
'@type': 'EntryPoint',
|
|
62
|
+
urlTemplate: `${baseUrl}/products?q={search_term_string}`,
|
|
63
|
+
},
|
|
64
|
+
'query-input': 'required name=search_term_string',
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<script
|
|
71
|
+
type="application/ld+json"
|
|
72
|
+
nonce={nonce}
|
|
73
|
+
suppressHydrationWarning
|
|
74
|
+
dangerouslySetInnerHTML={{ __html: serializeJsonLd(organizationJsonLd) }}
|
|
75
|
+
/>
|
|
76
|
+
<script
|
|
77
|
+
type="application/ld+json"
|
|
78
|
+
nonce={nonce}
|
|
79
|
+
suppressHydrationWarning
|
|
80
|
+
dangerouslySetInnerHTML={{ __html: serializeJsonLd(websiteJsonLd) }}
|
|
81
|
+
/>
|
|
82
|
+
</>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Escape `<`, `>`, `&` to \uXXXX so seller-controlled fields can't break out
|
|
87
|
+
// of the <script> with `</script>` or inject HTML. Same approach as
|
|
88
|
+
// product-json-ld.tsx — keep the two in sync.
|
|
89
|
+
function serializeJsonLd(value: unknown): string {
|
|
90
|
+
return JSON.stringify(value)
|
|
91
|
+
.replace(/</g, '\\u003c')
|
|
92
|
+
.replace(/>/g, '\\u003e')
|
|
93
|
+
.replace(/&/g, '\\u0026');
|
|
94
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Product } from 'brainerce';
|
|
2
2
|
import { getProductPriceInfo } from 'brainerce';
|
|
3
3
|
import { getNonce } from '@/lib/nonce';
|
|
4
|
+
import { stripHtmlForSeo } from '@/lib/seo';
|
|
4
5
|
|
|
5
6
|
interface ProductJsonLdProps {
|
|
6
7
|
product: Product;
|
|
@@ -39,11 +40,15 @@ export async function ProductJsonLd({ product, url, currency = 'USD' }: ProductJ
|
|
|
39
40
|
url,
|
|
40
41
|
};
|
|
41
42
|
|
|
43
|
+
// schema.org/Product.description must be plain text — Google's Rich Results
|
|
44
|
+
// and AI Overviews ingest this field directly and reject markup. Strip HTML
|
|
45
|
+
// first; if the description is empty after stripping, fall back to the name.
|
|
46
|
+
const cleanDescription = stripHtmlForSeo(product.description) || product.name;
|
|
42
47
|
const productJsonLd: Record<string, unknown> = {
|
|
43
48
|
'@context': 'https://schema.org',
|
|
44
49
|
'@type': 'Product',
|
|
45
50
|
name: product.name,
|
|
46
|
-
description:
|
|
51
|
+
description: cleanDescription,
|
|
47
52
|
image: imageUrl,
|
|
48
53
|
url,
|
|
49
54
|
sku: product.sku || product.id,
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
<% if (i18nEnabled) { %>
|
|
2
2
|
// Multi-language store — locales loaded dynamically
|
|
3
|
+
import { getDirectionForLocale } from 'brainerce';
|
|
4
|
+
|
|
3
5
|
export const defaultLocale = '<%= defaultLocale %>';
|
|
4
6
|
export const supportedLocales = <%- supportedLocales %> as const;
|
|
5
7
|
export type Locale = (typeof supportedLocales)[number];
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Resolve script direction. Delegates to the SDK so the storefront stays in
|
|
11
|
+
* sync as Brainerce adds support for new RTL locales — never maintain a
|
|
12
|
+
* local RTL locale set here.
|
|
13
|
+
*/
|
|
9
14
|
export function getDirection(locale: string): 'ltr' | 'rtl' {
|
|
10
|
-
return
|
|
15
|
+
return getDirectionForLocale(locale);
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
export async function getMessages(locale: string): Promise<Record<string, Record<string, string>>> {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single-source HTML sanitizer for merchant-authored content.
|
|
3
|
+
*
|
|
4
|
+
* Brainerce returns RICH_TEXT.html, PAGE.html, and FAQ answer values as raw
|
|
5
|
+
* HTML — the server does NOT pre-sanitize because some merchants embed
|
|
6
|
+
* iframes (e.g. YouTube). Run every merchant-authored HTML string through
|
|
7
|
+
* this wrapper before injecting via `dangerouslySetInnerHTML`.
|
|
8
|
+
*
|
|
9
|
+
* const safe = sanitizeHtml(rawHtml);
|
|
10
|
+
* <div dangerouslySetInnerHTML={{ __html: safe }} />
|
|
11
|
+
*
|
|
12
|
+
* Uses isomorphic-dompurify so the same call works in Server Components and
|
|
13
|
+
* Client Components.
|
|
14
|
+
*/
|
|
15
|
+
import DOMPurify from 'isomorphic-dompurify';
|
|
16
|
+
|
|
17
|
+
const DEFAULT_CONFIG: DOMPurify.Config = {
|
|
18
|
+
// Allow iframes for embedded videos/maps the merchant may include.
|
|
19
|
+
ADD_TAGS: ['iframe'],
|
|
20
|
+
ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling', 'target', 'rel'],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function sanitizeHtml(html: string | null | undefined): string {
|
|
24
|
+
if (!html) return '';
|
|
25
|
+
return DOMPurify.sanitize(html, DEFAULT_CONFIG) as unknown as string;
|
|
26
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// SEO helpers for meta tags and JSON-LD. Strips HTML and decodes common
|
|
2
|
+
// entities so seller-authored rich-text descriptions don't leak markup into
|
|
3
|
+
// <meta name="description">, og:description, twitter:description, or
|
|
4
|
+
// schema.org Product.description.
|
|
5
|
+
|
|
6
|
+
const NAMED_ENTITIES: Record<string, string> = {
|
|
7
|
+
nbsp: ' ',
|
|
8
|
+
amp: '&',
|
|
9
|
+
lt: '<',
|
|
10
|
+
gt: '>',
|
|
11
|
+
quot: '"',
|
|
12
|
+
apos: "'",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function decodeEntities(text: string): string {
|
|
16
|
+
return text
|
|
17
|
+
.replace(/&(nbsp|amp|lt|gt|quot|apos);/g, (_, name: string) => NAMED_ENTITIES[name] ?? '')
|
|
18
|
+
.replace(/&#(\d+);/g, (_, code: string) => String.fromCodePoint(Number(code)))
|
|
19
|
+
.replace(/&#x([0-9a-f]+);/gi, (_, code: string) => String.fromCodePoint(parseInt(code, 16)));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Strip HTML tags, decode entities, collapse whitespace. Idempotent on plain text.
|
|
23
|
+
export function stripHtmlForSeo(input: string | null | undefined): string {
|
|
24
|
+
if (!input) return '';
|
|
25
|
+
return decodeEntities(input.replace(/<[^>]*>/g, ' '))
|
|
26
|
+
.replace(/\s+/g, ' ')
|
|
27
|
+
.trim();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Build a meta description from raw HTML/text.
|
|
31
|
+
// Truncates at the nearest word boundary so we never cut mid-word, and
|
|
32
|
+
// appends a Unicode ellipsis. Returns '' for null/empty input so callers
|
|
33
|
+
// can fall back cleanly.
|
|
34
|
+
export function buildMetaDescription(
|
|
35
|
+
input: string | null | undefined,
|
|
36
|
+
maxLength = 160
|
|
37
|
+
): string {
|
|
38
|
+
const stripped = stripHtmlForSeo(input);
|
|
39
|
+
if (!stripped) return '';
|
|
40
|
+
if (stripped.length <= maxLength) return stripped;
|
|
41
|
+
|
|
42
|
+
const room = maxLength - 1; // leave room for ellipsis
|
|
43
|
+
const cut = stripped.slice(0, room);
|
|
44
|
+
const lastSpace = cut.lastIndexOf(' ');
|
|
45
|
+
// Only break on word boundary when it's reasonably close to the cap — otherwise
|
|
46
|
+
// a single very long word would shrink the description to almost nothing.
|
|
47
|
+
const safeCut = lastSpace > room * 0.7 ? cut.slice(0, lastSpace) : cut;
|
|
48
|
+
return `${safeCut.trim()}…`;
|
|
49
|
+
}
|