create-brainerce-store 1.65.0 → 1.67.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 +2 -2
- package/messages/en.json +505 -502
- package/messages/he.json +505 -502
- package/package.json +1 -1
- package/templates/nextjs/base/.env.local.ejs +45 -24
- package/templates/nextjs/base/.eslintrc.json +51 -57
- package/templates/nextjs/base/AGENTS.md.ejs +107 -81
- package/templates/nextjs/base/CLAUDE.md.ejs +118 -92
- package/templates/nextjs/base/next.config.ts +103 -86
- package/templates/nextjs/base/scripts/fetch-store-info.mjs +104 -97
- package/templates/nextjs/base/src/app/agents.md/route.ts +4 -3
- package/templates/nextjs/base/src/app/api/auth/me/route.ts +65 -59
- package/templates/nextjs/base/src/app/api/store/[...path]/route.ts +255 -242
- package/templates/nextjs/base/src/app/blog/[slug]/page.tsx.ejs +311 -308
- package/templates/nextjs/base/src/app/blog/page.tsx.ejs +277 -276
- package/templates/nextjs/base/src/app/blog/rss.xml/route.ts +4 -3
- package/templates/nextjs/base/src/app/category/[slug]/page.tsx +6 -5
- package/templates/nextjs/base/src/app/faq/page.tsx.ejs +46 -46
- package/templates/nextjs/base/src/app/indexnow-key.txt/route.ts +25 -26
- package/templates/nextjs/base/src/app/layout.tsx.ejs +273 -257
- package/templates/nextjs/base/src/app/llms.txt/route.ts +4 -3
- package/templates/nextjs/base/src/app/opengraph-image.tsx +1 -1
- package/templates/nextjs/base/src/app/page.tsx +65 -64
- package/templates/nextjs/base/src/app/pages/[slug]/page.tsx.ejs +92 -92
- package/templates/nextjs/base/src/app/products/[slug]/page.tsx +10 -5
- package/templates/nextjs/base/src/app/robots.ts +3 -2
- package/templates/nextjs/base/src/app/sitemap.ts +4 -3
- package/templates/nextjs/base/src/components/checkout/custom-fields-step.tsx +294 -292
- package/templates/nextjs/base/src/components/seo/article-json-ld.tsx +60 -59
- package/templates/nextjs/base/src/components/seo/category-json-ld.tsx +60 -61
- package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +16 -2
- package/templates/nextjs/base/src/core/lib/brainerce.server.ts +81 -0
- package/templates/nextjs/base/src/core/lib/brainerce.ts.ejs +60 -110
- package/templates/nextjs/base/src/core/lib/site-url.ts +197 -0
- package/templates/nextjs/base/src/ui/product/faq-section.tsx.ejs +46 -0
- package/templates/nextjs/base/src/ui/product/review-form.tsx +294 -294
- package/templates/nextjs/base/src/ui/product/reviews-section.tsx.ejs +108 -108
- package/templates/nextjs/designs/atelier/app-overlay/layout.tsx.ejs +301 -285
- package/templates/nextjs/designs/atelier/ui/layout/faq-section.tsx +97 -96
- package/templates/nextjs/designs/atelier/ui/layout/site-footer.tsx.ejs +142 -141
- package/templates/nextjs/designs/atelier/ui/layout/site-header.tsx.ejs +139 -138
- package/templates/nextjs/designs/atelier/ui/product/review-form.tsx +295 -267
- package/templates/nextjs/designs/atelier/ui/product/reviews-section.tsx.ejs +148 -148
- package/templates/nextjs/ui-canvas/layout/faq-section.tsx.ejs +72 -71
- package/templates/nextjs/ui-canvas/layout/site-footer.tsx.ejs +83 -82
- package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +120 -119
- package/templates/nextjs/ui-canvas/product/faq-section.tsx.ejs +54 -0
- package/templates/nextjs/ui-canvas/product/review-form.tsx +267 -266
- package/templates/nextjs/ui-canvas/product/reviews-section.tsx.ejs +96 -96
|
@@ -1,276 +1,277 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Blog listing page — fetches published posts from the Brainerce blog API.
|
|
3
|
-
*
|
|
4
|
-
* Merchants manage posts in the Brainerce dashboard under Sell → Blog.
|
|
5
|
-
* The storefront renders them here. Each post links to /blog/[slug].
|
|
6
|
-
*
|
|
7
|
-
* Posts are only visible when status=PUBLISHED and publishedAt <= NOW().
|
|
8
|
-
* Category and tag filtering available via query params.
|
|
9
|
-
*/
|
|
10
|
-
import * as React from 'react';
|
|
11
|
-
import type { Metadata } from 'next';
|
|
12
|
-
import Link from 'next/link';
|
|
13
|
-
import { CdnImage as Image } from '@/ui/shared/cdn-image';
|
|
14
|
-
|
|
15
|
-
import { getServerClient } from '@/core/lib/brainerce';
|
|
16
|
-
|
|
17
|
-
<% if (i18nEnabled) { %>
|
|
18
|
-
type PageProps = {
|
|
19
|
-
params: Promise<{ locale: string }>;
|
|
20
|
-
searchParams: Promise<{ category?: string; tag?: string; page?: string }>;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
|
|
24
|
-
const { locale } = await params;
|
|
25
|
-
return {
|
|
26
|
-
title: locale === 'he' ? 'בלוג' : 'Blog',
|
|
27
|
-
description: locale === 'he' ? 'מאמרים וסיפורים מהחנות' : 'Articles and stories from our store',
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export default async function BlogListPage({ params, searchParams }: PageProps) {
|
|
32
|
-
const { locale } = await params;
|
|
33
|
-
const { category, tag, page: pageParam } = await searchParams;
|
|
34
|
-
const page = Number(pageParam ?? '1') || 1;
|
|
35
|
-
|
|
36
|
-
const client = getServerClient(locale);
|
|
37
|
-
const { data: posts, meta } = await client.blog
|
|
38
|
-
.getPosts({ category, tag, page, limit: 12 })
|
|
39
|
-
.catch(() => ({ data: [], meta: { page: 1, limit: 12, total: 0, totalPages: 1 } }));
|
|
40
|
-
|
|
41
|
-
const isHe = locale === 'he';
|
|
42
|
-
const dir = isHe ? 'rtl' : 'ltr';
|
|
43
|
-
const emptyLabel = isHe ? 'עדיין אין פוסטים.' : 'No posts yet.';
|
|
44
|
-
const blogLabel = isHe ? 'בלוג' : 'Blog';
|
|
45
|
-
const readMoreLabel = isHe ? 'קרא עוד' : 'Read more';
|
|
46
|
-
const prevLabel = isHe ? 'הקודם' : 'Previous';
|
|
47
|
-
const nextLabel = isHe ? 'הבא' : 'Next';
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<main dir={dir} className="mx-auto max-w-6xl px-4 py-10 sm:px-6 lg:px-8">
|
|
51
|
-
<h1 className="mb-8 text-3xl font-bold tracking-tight text-foreground sm:text-4xl">
|
|
52
|
-
{blogLabel}
|
|
53
|
-
</h1>
|
|
54
|
-
|
|
55
|
-
{posts.length === 0 ? (
|
|
56
|
-
<p className="text-muted-foreground">{emptyLabel}</p>
|
|
57
|
-
) : (
|
|
58
|
-
<>
|
|
59
|
-
<div className="grid gap-8 sm:grid-cols-2 lg:grid-cols-3">
|
|
60
|
-
{posts.map((post) => (
|
|
61
|
-
<article
|
|
62
|
-
key={post.id}
|
|
63
|
-
className="group flex flex-col overflow-hidden rounded-xl border border-border/60 bg-card shadow-sm transition-shadow hover:shadow-md"
|
|
64
|
-
>
|
|
65
|
-
{post.coverImageUrl && (
|
|
66
|
-
<Link href={`/blog/${encodeURIComponent(post.slug)}`} tabIndex={-1}>
|
|
67
|
-
<div className="relative aspect-[16/9] overflow-hidden">
|
|
68
|
-
<Image
|
|
69
|
-
src={post.coverImageUrl}
|
|
70
|
-
alt={post.coverImageAlt ?? post.title}
|
|
71
|
-
fill
|
|
72
|
-
className="object-cover transition-transform duration-300 group-hover:scale-105"
|
|
73
|
-
sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 33vw"
|
|
74
|
-
/>
|
|
75
|
-
</div>
|
|
76
|
-
</Link>
|
|
77
|
-
)}
|
|
78
|
-
|
|
79
|
-
<div className="flex flex-1 flex-col gap-3 p-5">
|
|
80
|
-
{/* Category badge */}
|
|
81
|
-
{post.category && (
|
|
82
|
-
<span className="w-fit rounded-full bg-primary/10 px-2.5 py-0.5 text-xs font-medium text-primary">
|
|
83
|
-
{post.category}
|
|
84
|
-
</span>
|
|
85
|
-
)}
|
|
86
|
-
|
|
87
|
-
{/* Title */}
|
|
88
|
-
<Link href={`/blog/${encodeURIComponent(post.slug)}`}>
|
|
89
|
-
<h2 className="line-clamp-2 text-lg font-semibold leading-snug text-foreground hover:text-primary transition-colors">
|
|
90
|
-
{post.title}
|
|
91
|
-
</h2>
|
|
92
|
-
</Link>
|
|
93
|
-
|
|
94
|
-
{/* Excerpt */}
|
|
95
|
-
{post.excerpt && (
|
|
96
|
-
<p className="line-clamp-3 text-sm text-muted-foreground leading-relaxed">
|
|
97
|
-
{post.excerpt}
|
|
98
|
-
</p>
|
|
99
|
-
)}
|
|
100
|
-
|
|
101
|
-
{/* Meta: author + date */}
|
|
102
|
-
<div className="mt-auto flex items-center gap-2 pt-2 text-xs text-muted-foreground">
|
|
103
|
-
{post.author && <span>{post.author}</span>}
|
|
104
|
-
{post.author && post.publishedAt && <span>·</span>}
|
|
105
|
-
{post.publishedAt && (
|
|
106
|
-
<time dateTime={post.publishedAt}>
|
|
107
|
-
{new Date(post.publishedAt).toLocaleDateString(isHe ? 'he-IL' : 'en-US', {
|
|
108
|
-
year: 'numeric',
|
|
109
|
-
month: 'short',
|
|
110
|
-
day: 'numeric',
|
|
111
|
-
})}
|
|
112
|
-
</time>
|
|
113
|
-
)}
|
|
114
|
-
</div>
|
|
115
|
-
|
|
116
|
-
<Link
|
|
117
|
-
href={`/blog/${encodeURIComponent(post.slug)}`}
|
|
118
|
-
className="mt-1 text-sm font-medium text-primary hover:underline"
|
|
119
|
-
>
|
|
120
|
-
{readMoreLabel} →
|
|
121
|
-
</Link>
|
|
122
|
-
</div>
|
|
123
|
-
</article>
|
|
124
|
-
))}
|
|
125
|
-
</div>
|
|
126
|
-
|
|
127
|
-
{/* Pagination */}
|
|
128
|
-
{meta.totalPages > 1 && (
|
|
129
|
-
<nav className="mt-10 flex items-center justify-center gap-4">
|
|
130
|
-
{page > 1 && (
|
|
131
|
-
<Link
|
|
132
|
-
href={`/blog?page=${page - 1}${category ? `&category=${category}` : ''}${tag ? `&tag=${tag}` : ''}`}
|
|
133
|
-
className="rounded-lg border border-border px-4 py-2 text-sm hover:bg-muted transition-colors"
|
|
134
|
-
>
|
|
135
|
-
{prevLabel}
|
|
136
|
-
</Link>
|
|
137
|
-
)}
|
|
138
|
-
<span className="text-sm text-muted-foreground">
|
|
139
|
-
{page} / {meta.totalPages}
|
|
140
|
-
</span>
|
|
141
|
-
{page < meta.totalPages && (
|
|
142
|
-
<Link
|
|
143
|
-
href={`/blog?page=${page + 1}${category ? `&category=${category}` : ''}${tag ? `&tag=${tag}` : ''}`}
|
|
144
|
-
className="rounded-lg border border-border px-4 py-2 text-sm hover:bg-muted transition-colors"
|
|
145
|
-
>
|
|
146
|
-
{nextLabel}
|
|
147
|
-
</Link>
|
|
148
|
-
)}
|
|
149
|
-
</nav>
|
|
150
|
-
)}
|
|
151
|
-
</>
|
|
152
|
-
)}
|
|
153
|
-
</main>
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
<% } else { %>
|
|
157
|
-
type PageProps = {
|
|
158
|
-
searchParams: Promise<{ category?: string; tag?: string; page?: string }>;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
export const metadata: Metadata = {
|
|
162
|
-
title: 'Blog',
|
|
163
|
-
description: 'Articles and stories from our store',
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
export default async function BlogListPage({ searchParams }: PageProps) {
|
|
167
|
-
const { category, tag, page: pageParam } = await searchParams;
|
|
168
|
-
const page = Number(pageParam ?? '1') || 1;
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
{post.author && post.
|
|
226
|
-
{post.publishedAt &&
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Blog listing page — fetches published posts from the Brainerce blog API.
|
|
3
|
+
*
|
|
4
|
+
* Merchants manage posts in the Brainerce dashboard under Sell → Blog.
|
|
5
|
+
* The storefront renders them here. Each post links to /blog/[slug].
|
|
6
|
+
*
|
|
7
|
+
* Posts are only visible when status=PUBLISHED and publishedAt <= NOW().
|
|
8
|
+
* Category and tag filtering available via query params.
|
|
9
|
+
*/
|
|
10
|
+
import * as React from 'react';
|
|
11
|
+
import type { Metadata } from 'next';
|
|
12
|
+
import Link from 'next/link';
|
|
13
|
+
import { CdnImage as Image } from '@/ui/shared/cdn-image';
|
|
14
|
+
|
|
15
|
+
import { getServerClient } from '@/core/lib/brainerce.server';
|
|
16
|
+
|
|
17
|
+
<% if (i18nEnabled) { %>
|
|
18
|
+
type PageProps = {
|
|
19
|
+
params: Promise<{ locale: string }>;
|
|
20
|
+
searchParams: Promise<{ category?: string; tag?: string; page?: string }>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
|
|
24
|
+
const { locale } = await params;
|
|
25
|
+
return {
|
|
26
|
+
title: locale === 'he' ? 'בלוג' : 'Blog',
|
|
27
|
+
description: locale === 'he' ? 'מאמרים וסיפורים מהחנות' : 'Articles and stories from our store',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default async function BlogListPage({ params, searchParams }: PageProps) {
|
|
32
|
+
const { locale } = await params;
|
|
33
|
+
const { category, tag, page: pageParam } = await searchParams;
|
|
34
|
+
const page = Number(pageParam ?? '1') || 1;
|
|
35
|
+
|
|
36
|
+
const client = await getServerClient(locale);
|
|
37
|
+
const { data: posts, meta } = await client.blog
|
|
38
|
+
.getPosts({ category, tag, page, limit: 12 })
|
|
39
|
+
.catch(() => ({ data: [], meta: { page: 1, limit: 12, total: 0, totalPages: 1 } }));
|
|
40
|
+
|
|
41
|
+
const isHe = locale === 'he';
|
|
42
|
+
const dir = isHe ? 'rtl' : 'ltr';
|
|
43
|
+
const emptyLabel = isHe ? 'עדיין אין פוסטים.' : 'No posts yet.';
|
|
44
|
+
const blogLabel = isHe ? 'בלוג' : 'Blog';
|
|
45
|
+
const readMoreLabel = isHe ? 'קרא עוד' : 'Read more';
|
|
46
|
+
const prevLabel = isHe ? 'הקודם' : 'Previous';
|
|
47
|
+
const nextLabel = isHe ? 'הבא' : 'Next';
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<main dir={dir} className="mx-auto max-w-6xl px-4 py-10 sm:px-6 lg:px-8">
|
|
51
|
+
<h1 className="mb-8 text-3xl font-bold tracking-tight text-foreground sm:text-4xl">
|
|
52
|
+
{blogLabel}
|
|
53
|
+
</h1>
|
|
54
|
+
|
|
55
|
+
{posts.length === 0 ? (
|
|
56
|
+
<p className="text-muted-foreground">{emptyLabel}</p>
|
|
57
|
+
) : (
|
|
58
|
+
<>
|
|
59
|
+
<div className="grid gap-8 sm:grid-cols-2 lg:grid-cols-3">
|
|
60
|
+
{posts.map((post) => (
|
|
61
|
+
<article
|
|
62
|
+
key={post.id}
|
|
63
|
+
className="group flex flex-col overflow-hidden rounded-xl border border-border/60 bg-card shadow-sm transition-shadow hover:shadow-md"
|
|
64
|
+
>
|
|
65
|
+
{post.coverImageUrl && (
|
|
66
|
+
<Link href={`/blog/${encodeURIComponent(post.slug)}`} tabIndex={-1}>
|
|
67
|
+
<div className="relative aspect-[16/9] overflow-hidden">
|
|
68
|
+
<Image
|
|
69
|
+
src={post.coverImageUrl}
|
|
70
|
+
alt={post.coverImageAlt ?? post.title}
|
|
71
|
+
fill
|
|
72
|
+
className="object-cover transition-transform duration-300 group-hover:scale-105"
|
|
73
|
+
sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 33vw"
|
|
74
|
+
/>
|
|
75
|
+
</div>
|
|
76
|
+
</Link>
|
|
77
|
+
)}
|
|
78
|
+
|
|
79
|
+
<div className="flex flex-1 flex-col gap-3 p-5">
|
|
80
|
+
{/* Category badge */}
|
|
81
|
+
{post.category && (
|
|
82
|
+
<span className="w-fit rounded-full bg-primary/10 px-2.5 py-0.5 text-xs font-medium text-primary">
|
|
83
|
+
{post.category}
|
|
84
|
+
</span>
|
|
85
|
+
)}
|
|
86
|
+
|
|
87
|
+
{/* Title */}
|
|
88
|
+
<Link href={`/blog/${encodeURIComponent(post.slug)}`}>
|
|
89
|
+
<h2 className="line-clamp-2 text-lg font-semibold leading-snug text-foreground hover:text-primary transition-colors">
|
|
90
|
+
{post.title}
|
|
91
|
+
</h2>
|
|
92
|
+
</Link>
|
|
93
|
+
|
|
94
|
+
{/* Excerpt */}
|
|
95
|
+
{post.excerpt && (
|
|
96
|
+
<p className="line-clamp-3 text-sm text-muted-foreground leading-relaxed">
|
|
97
|
+
{post.excerpt}
|
|
98
|
+
</p>
|
|
99
|
+
)}
|
|
100
|
+
|
|
101
|
+
{/* Meta: author + date */}
|
|
102
|
+
<div className="mt-auto flex items-center gap-2 pt-2 text-xs text-muted-foreground">
|
|
103
|
+
{post.author && <span>{post.author}</span>}
|
|
104
|
+
{post.author && post.publishedAt && <span>·</span>}
|
|
105
|
+
{post.publishedAt && (
|
|
106
|
+
<time dateTime={post.publishedAt}>
|
|
107
|
+
{new Date(post.publishedAt).toLocaleDateString(isHe ? 'he-IL' : 'en-US', {
|
|
108
|
+
year: 'numeric',
|
|
109
|
+
month: 'short',
|
|
110
|
+
day: 'numeric',
|
|
111
|
+
})}
|
|
112
|
+
</time>
|
|
113
|
+
)}
|
|
114
|
+
</div>
|
|
115
|
+
|
|
116
|
+
<Link
|
|
117
|
+
href={`/blog/${encodeURIComponent(post.slug)}`}
|
|
118
|
+
className="mt-1 text-sm font-medium text-primary hover:underline"
|
|
119
|
+
>
|
|
120
|
+
{readMoreLabel} →
|
|
121
|
+
</Link>
|
|
122
|
+
</div>
|
|
123
|
+
</article>
|
|
124
|
+
))}
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
{/* Pagination */}
|
|
128
|
+
{meta.totalPages > 1 && (
|
|
129
|
+
<nav className="mt-10 flex items-center justify-center gap-4">
|
|
130
|
+
{page > 1 && (
|
|
131
|
+
<Link
|
|
132
|
+
href={`/blog?page=${page - 1}${category ? `&category=${category}` : ''}${tag ? `&tag=${tag}` : ''}`}
|
|
133
|
+
className="rounded-lg border border-border px-4 py-2 text-sm hover:bg-muted transition-colors"
|
|
134
|
+
>
|
|
135
|
+
{prevLabel}
|
|
136
|
+
</Link>
|
|
137
|
+
)}
|
|
138
|
+
<span className="text-sm text-muted-foreground">
|
|
139
|
+
{page} / {meta.totalPages}
|
|
140
|
+
</span>
|
|
141
|
+
{page < meta.totalPages && (
|
|
142
|
+
<Link
|
|
143
|
+
href={`/blog?page=${page + 1}${category ? `&category=${category}` : ''}${tag ? `&tag=${tag}` : ''}`}
|
|
144
|
+
className="rounded-lg border border-border px-4 py-2 text-sm hover:bg-muted transition-colors"
|
|
145
|
+
>
|
|
146
|
+
{nextLabel}
|
|
147
|
+
</Link>
|
|
148
|
+
)}
|
|
149
|
+
</nav>
|
|
150
|
+
)}
|
|
151
|
+
</>
|
|
152
|
+
)}
|
|
153
|
+
</main>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
<% } else { %>
|
|
157
|
+
type PageProps = {
|
|
158
|
+
searchParams: Promise<{ category?: string; tag?: string; page?: string }>;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export const metadata: Metadata = {
|
|
162
|
+
title: 'Blog',
|
|
163
|
+
description: 'Articles and stories from our store',
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export default async function BlogListPage({ searchParams }: PageProps) {
|
|
167
|
+
const { category, tag, page: pageParam } = await searchParams;
|
|
168
|
+
const page = Number(pageParam ?? '1') || 1;
|
|
169
|
+
|
|
170
|
+
const client = await getServerClient();
|
|
171
|
+
const { data: posts, meta } = await client.blog
|
|
172
|
+
.getPosts({ category, tag, page, limit: 12 })
|
|
173
|
+
.catch(() => ({ data: [], meta: { page: 1, limit: 12, total: 0, totalPages: 1 } }));
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<main className="mx-auto max-w-6xl px-4 py-10 sm:px-6 lg:px-8">
|
|
177
|
+
<h1 className="mb-8 text-3xl font-bold tracking-tight text-foreground sm:text-4xl">
|
|
178
|
+
Blog
|
|
179
|
+
</h1>
|
|
180
|
+
|
|
181
|
+
{posts.length === 0 ? (
|
|
182
|
+
<p className="text-muted-foreground">No posts yet.</p>
|
|
183
|
+
) : (
|
|
184
|
+
<>
|
|
185
|
+
<div className="grid gap-8 sm:grid-cols-2 lg:grid-cols-3">
|
|
186
|
+
{posts.map((post) => (
|
|
187
|
+
<article
|
|
188
|
+
key={post.id}
|
|
189
|
+
className="group flex flex-col overflow-hidden rounded-xl border border-border/60 bg-card shadow-sm transition-shadow hover:shadow-md"
|
|
190
|
+
>
|
|
191
|
+
{post.coverImageUrl && (
|
|
192
|
+
<Link href={`/blog/${encodeURIComponent(post.slug)}`} tabIndex={-1}>
|
|
193
|
+
<div className="relative aspect-[16/9] overflow-hidden">
|
|
194
|
+
<Image
|
|
195
|
+
src={post.coverImageUrl}
|
|
196
|
+
alt={post.coverImageAlt ?? post.title}
|
|
197
|
+
fill
|
|
198
|
+
className="object-cover transition-transform duration-300 group-hover:scale-105"
|
|
199
|
+
sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 33vw"
|
|
200
|
+
/>
|
|
201
|
+
</div>
|
|
202
|
+
</Link>
|
|
203
|
+
)}
|
|
204
|
+
|
|
205
|
+
<div className="flex flex-1 flex-col gap-3 p-5">
|
|
206
|
+
{post.category && (
|
|
207
|
+
<span className="w-fit rounded-full bg-primary/10 px-2.5 py-0.5 text-xs font-medium text-primary">
|
|
208
|
+
{post.category}
|
|
209
|
+
</span>
|
|
210
|
+
)}
|
|
211
|
+
|
|
212
|
+
<Link href={`/blog/${encodeURIComponent(post.slug)}`}>
|
|
213
|
+
<h2 className="line-clamp-2 text-lg font-semibold leading-snug text-foreground hover:text-primary transition-colors">
|
|
214
|
+
{post.title}
|
|
215
|
+
</h2>
|
|
216
|
+
</Link>
|
|
217
|
+
|
|
218
|
+
{post.excerpt && (
|
|
219
|
+
<p className="line-clamp-3 text-sm text-muted-foreground leading-relaxed">
|
|
220
|
+
{post.excerpt}
|
|
221
|
+
</p>
|
|
222
|
+
)}
|
|
223
|
+
|
|
224
|
+
<div className="mt-auto flex items-center gap-2 pt-2 text-xs text-muted-foreground">
|
|
225
|
+
{post.author && <span>{post.author}</span>}
|
|
226
|
+
{post.author && post.publishedAt && <span>·</span>}
|
|
227
|
+
{post.publishedAt && (
|
|
228
|
+
<time dateTime={post.publishedAt}>
|
|
229
|
+
{new Date(post.publishedAt).toLocaleDateString('en-US', {
|
|
230
|
+
year: 'numeric',
|
|
231
|
+
month: 'short',
|
|
232
|
+
day: 'numeric',
|
|
233
|
+
})}
|
|
234
|
+
</time>
|
|
235
|
+
)}
|
|
236
|
+
</div>
|
|
237
|
+
|
|
238
|
+
<Link
|
|
239
|
+
href={`/blog/${encodeURIComponent(post.slug)}`}
|
|
240
|
+
className="mt-1 text-sm font-medium text-primary hover:underline"
|
|
241
|
+
>
|
|
242
|
+
Read more →
|
|
243
|
+
</Link>
|
|
244
|
+
</div>
|
|
245
|
+
</article>
|
|
246
|
+
))}
|
|
247
|
+
</div>
|
|
248
|
+
|
|
249
|
+
{meta.totalPages > 1 && (
|
|
250
|
+
<nav className="mt-10 flex items-center justify-center gap-4">
|
|
251
|
+
{page > 1 && (
|
|
252
|
+
<Link
|
|
253
|
+
href={`/blog?page=${page - 1}${category ? `&category=${category}` : ''}${tag ? `&tag=${tag}` : ''}`}
|
|
254
|
+
className="rounded-lg border border-border px-4 py-2 text-sm hover:bg-muted transition-colors"
|
|
255
|
+
>
|
|
256
|
+
Previous
|
|
257
|
+
</Link>
|
|
258
|
+
)}
|
|
259
|
+
<span className="text-sm text-muted-foreground">
|
|
260
|
+
{page} / {meta.totalPages}
|
|
261
|
+
</span>
|
|
262
|
+
{page < meta.totalPages && (
|
|
263
|
+
<Link
|
|
264
|
+
href={`/blog?page=${page + 1}${category ? `&category=${category}` : ''}${tag ? `&tag=${tag}` : ''}`}
|
|
265
|
+
className="rounded-lg border border-border px-4 py-2 text-sm hover:bg-muted transition-colors"
|
|
266
|
+
>
|
|
267
|
+
Next
|
|
268
|
+
</Link>
|
|
269
|
+
)}
|
|
270
|
+
</nav>
|
|
271
|
+
)}
|
|
272
|
+
</>
|
|
273
|
+
)}
|
|
274
|
+
</main>
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
<% } %>
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
* wins over `[locale]` for /blog/rss.xml, while /he/blog/... keeps matching
|
|
14
14
|
* the locale tree. See scaffold.ts.
|
|
15
15
|
*/
|
|
16
|
-
import { getServerClient } from '@/core/lib/brainerce';
|
|
16
|
+
import { getServerClient } from '@/core/lib/brainerce.server';
|
|
17
|
+
import { getCanonicalSiteUrl } from '@/core/lib/site-url';
|
|
17
18
|
|
|
18
19
|
export const revalidate = 3600;
|
|
19
20
|
|
|
@@ -26,8 +27,8 @@ function esc(value: string): string {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export async function GET() {
|
|
29
|
-
const baseUrl =
|
|
30
|
-
const client = getServerClient();
|
|
30
|
+
const baseUrl = await getCanonicalSiteUrl();
|
|
31
|
+
const client = await getServerClient();
|
|
31
32
|
|
|
32
33
|
const [info, posts] = await Promise.all([
|
|
33
34
|
client.getStoreInfo().catch(() => null),
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { Metadata } from 'next';
|
|
2
2
|
import { notFound } from 'next/navigation';
|
|
3
3
|
import type { Product } from 'brainerce';
|
|
4
|
-
import { getServerClient, fetchStoreInfo } from '@/core/lib/brainerce';
|
|
4
|
+
import { getServerClient, fetchStoreInfo } from '@/core/lib/brainerce.server';
|
|
5
5
|
import { buildMetaDescription } from '@/core/lib/seo';
|
|
6
6
|
import { sanitizeHtml } from '@/core/lib/sanitize';
|
|
7
7
|
import { decodeSlug } from '@/core/lib/utils';
|
|
8
8
|
import { CategoryJsonLd } from '@/components/seo/category-json-ld';
|
|
9
|
+
import { getCanonicalSiteUrl } from '@/core/lib/site-url';
|
|
9
10
|
import { Breadcrumbs } from '@/components/seo/breadcrumbs';
|
|
10
11
|
import { ProductGrid } from '@/ui/product/product-grid';
|
|
11
12
|
|
|
@@ -27,7 +28,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|
|
27
28
|
const slug = decodeSlug(rawSlug);
|
|
28
29
|
try {
|
|
29
30
|
const [category, storeInfo] = await Promise.all([
|
|
30
|
-
getServerClient(locale).getCategoryBySlug(slug),
|
|
31
|
+
(await getServerClient(locale)).getCategoryBySlug(slug),
|
|
31
32
|
fetchStoreInfo(locale),
|
|
32
33
|
]);
|
|
33
34
|
const description =
|
|
@@ -42,7 +43,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|
|
42
43
|
// emits, so the alternates always match real, crawlable URLs.
|
|
43
44
|
const supportedLocales = storeInfo?.i18n?.supportedLocales ?? [];
|
|
44
45
|
const defaultLoc = storeInfo?.i18n?.defaultLocale ?? storeInfo?.language ?? '';
|
|
45
|
-
const baseUrl =
|
|
46
|
+
const baseUrl = await getCanonicalSiteUrl();
|
|
46
47
|
const hreflangLanguages =
|
|
47
48
|
supportedLocales.length > 1
|
|
48
49
|
? Object.fromEntries([
|
|
@@ -84,7 +85,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|
|
84
85
|
export default async function CategoryPage({ params }: Props) {
|
|
85
86
|
const { slug: rawSlug, locale } = await params;
|
|
86
87
|
const slug = decodeSlug(rawSlug);
|
|
87
|
-
const client = getServerClient(locale);
|
|
88
|
+
const client = await getServerClient(locale);
|
|
88
89
|
|
|
89
90
|
const category = await client.getCategoryBySlug(slug).catch(() => null);
|
|
90
91
|
if (!category) notFound();
|
|
@@ -95,7 +96,7 @@ export default async function CategoryPage({ params }: Props) {
|
|
|
95
96
|
.getProducts({ categories: [category.id], limit: 48 })
|
|
96
97
|
.catch(() => ({ data: [] as Product[] }));
|
|
97
98
|
|
|
98
|
-
const baseUrl =
|
|
99
|
+
const baseUrl = await getCanonicalSiteUrl();
|
|
99
100
|
const url = `${baseUrl}/category/${category.slug || slug}`;
|
|
100
101
|
const localePrefix = locale ? `/${locale}` : '';
|
|
101
102
|
const breadcrumbItems = [
|