@sgflabs/storefront-core 0.1.18 → 0.1.19
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/package.json +9 -7
- package/src/components/cells/CartDropdown/CartDropdown.tsx +1 -1
- package/src/components/cells/CartItemsProducts/CartItemsProducts.tsx +4 -2
- package/src/components/cells/UserDropdown/UserDropdown.tsx +2 -2
- package/src/components/molecules/CartDropdownItem/CartDropdownItem.tsx +5 -2
- package/src/components/molecules/LoginReturnLink/LoginReturnLink.tsx +2 -2
- package/src/components/molecules/NativeSelect/NativeSelect.tsx +2 -0
- package/src/components/molecules/ProductImage/ProductImage.tsx +1 -1
- package/src/components/organisms/CartEmpty/CartEmpty.tsx +1 -1
- package/src/components/organisms/Header/Header.tsx +5 -1
- package/src/components/organisms/Header/HeaderAccountControls.tsx +6 -5
- package/src/components/organisms/Header/HeaderMessages.tsx +14 -0
- package/src/components/organisms/ListingToolbar/ListingToolbar.tsx +8 -2
- package/src/components/organisms/OrderItems/Item.tsx +5 -2
- package/src/components/organisms/ProductCard/ProductCard.tsx +8 -3
- package/src/components/organisms/ProductListingHeader/ProductListingHeader.tsx +7 -3
- package/src/components/sections/Cart/Cart.tsx +1 -0
- package/src/lib/data/bidding.ts +5 -1
- package/src/lib/data/seller.ts +17 -2
- package/src/lib/helpers/build-product-gallery-slides.ts +25 -0
- package/src/lib/helpers/resolve-image-alt.ts +14 -0
- package/src/lib/helpers/seo.ts +140 -65
- package/src/lib/helpers/store-image-alt.ts +8 -0
- package/src/lib/seo/indexing.ts +11 -0
- package/src/lib/seo/locale-redirect.ts +11 -0
- package/src/lib/seo/seo-config.d.ts +9 -0
- package/src/lib/seo/seo-config.js +42 -0
- package/src/pages/auth/forgot-password/page.tsx +2 -0
- package/src/pages/auth/login/page.tsx +12 -0
- package/src/pages/auth/register/page.tsx +11 -0
- package/src/pages/invite/page.tsx +2 -2
- package/src/pages/main/applications/[handle]/page.tsx +2 -1
- package/src/pages/main/auctions/page.tsx +30 -2
- package/src/pages/main/best-sellers/page.tsx +2 -1
- package/src/pages/main/categories/[category]/page.tsx +4 -2
- package/src/pages/main/categories/page.tsx +2 -1
- package/src/pages/main/legal/[type]/page.tsx +23 -9
- package/src/pages/main/legal/page.tsx +16 -4
- package/src/pages/main/sellers/[handle]/page.tsx +23 -2
- package/src/pages/main/user/layout.tsx +3 -0
- package/src/pages/robots.ts +25 -2
- package/src/pages/sitemap.ts +21 -3
- package/src/pages/sitemap.xml/route.ts +5 -1
package/src/lib/helpers/seo.ts
CHANGED
|
@@ -5,10 +5,21 @@ import { getSiteName } from "../data/brand"
|
|
|
5
5
|
import { getSiteBaseUrl } from "./get-site-base-url"
|
|
6
6
|
import { getRequestBaseUrl } from "./request-base-url"
|
|
7
7
|
import { getProductPrice, isPriceOnRequestAmount } from "./get-product-price"
|
|
8
|
+
import { resolveStoreImageAlt } from "./store-image-alt"
|
|
8
9
|
import { getStorefrontRegionCodes, toHreflang } from "./hreflang"
|
|
10
|
+
import { rootRobotsMetadata } from "../seo/indexing"
|
|
9
11
|
import { SellerProps } from "../../types/seller"
|
|
10
12
|
|
|
11
13
|
const META_DESCRIPTION_MAX_LENGTH = 155
|
|
14
|
+
const TEMPLATE_DESCRIPTION_MAX_LENGTH = 160
|
|
15
|
+
const TEMPLATE_DESCRIPTION_MIN_LENGTH = 140
|
|
16
|
+
const MIN_REAL_DESCRIPTION_LENGTH = 70
|
|
17
|
+
const SEO_TITLE_MAX_LENGTH = 60
|
|
18
|
+
const DEFAULT_OG_IMAGE_PATH = "/images/og-default.jpg"
|
|
19
|
+
|
|
20
|
+
/** Social and rich-result crawlers reject SVG, so the fallback share image must be a raster file. */
|
|
21
|
+
export const getDefaultOgImagePath = () =>
|
|
22
|
+
process.env.NEXT_PUBLIC_OG_DEFAULT_IMAGE?.trim() || DEFAULT_OG_IMAGE_PATH
|
|
12
23
|
|
|
13
24
|
/**
|
|
14
25
|
* The heading `formatProductDescriptionMarkdown` writes above the imported
|
|
@@ -79,6 +90,79 @@ export function truncateForMetaDescription(
|
|
|
79
90
|
return `${cut}…`
|
|
80
91
|
}
|
|
81
92
|
|
|
93
|
+
/** Collapses a title that is exactly two identical copies: "LOX 386S LOX 386S" becomes "LOX 386S". */
|
|
94
|
+
export function collapseDoubledTitle(text: string): string {
|
|
95
|
+
const words = text.trim().split(/\s+/).filter(Boolean)
|
|
96
|
+
const half = words.length / 2
|
|
97
|
+
if (!Number.isInteger(half) || half === 0) return text
|
|
98
|
+
const first = words.slice(0, half).join(" ")
|
|
99
|
+
return first === words.slice(half).join(" ") ? first : text
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** `<name> - <type>`, dropping the type, then truncating the name, to stay within the title budget. */
|
|
103
|
+
export function buildProductSeoTitle(
|
|
104
|
+
title: string,
|
|
105
|
+
type?: string | null,
|
|
106
|
+
{ collapseDoubledTitle: collapse = true }: { collapseDoubledTitle?: boolean } = {}
|
|
107
|
+
): string {
|
|
108
|
+
const name = collapse ? collapseDoubledTitle(title) : title
|
|
109
|
+
const withType = type && !name.toLowerCase().includes(type.toLowerCase()) ? `${name} - ${type}` : name
|
|
110
|
+
if (withType.length <= SEO_TITLE_MAX_LENGTH) return withType
|
|
111
|
+
if (name.length <= SEO_TITLE_MAX_LENGTH) return name
|
|
112
|
+
const window = name.slice(0, SEO_TITLE_MAX_LENGTH)
|
|
113
|
+
const wordEnd = window.lastIndexOf(" ")
|
|
114
|
+
return wordEnd > 0 ? window.slice(0, wordEnd) : window
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const nonBlank = (value: unknown): value is string => typeof value === "string" && value.trim().length > 0
|
|
118
|
+
|
|
119
|
+
/** Cuts at a word boundary within the budget and closes with a period, never leaving a partial word. */
|
|
120
|
+
function fitTemplateDescription(text: string): string {
|
|
121
|
+
if (text.length <= TEMPLATE_DESCRIPTION_MAX_LENGTH) return text
|
|
122
|
+
const room = TEMPLATE_DESCRIPTION_MAX_LENGTH - 1
|
|
123
|
+
const wordEnd = text.lastIndexOf(" ", room)
|
|
124
|
+
const cut = /\s/.test(text[room]) || wordEnd <= 0 ? text.slice(0, room) : text.slice(0, wordEnd)
|
|
125
|
+
return `${cut.replace(/[\s,;:.-]+$/, "")}.`
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Call-to-action sentences for a generated product description, given the site name. */
|
|
129
|
+
export type DescriptionCallToAction = (siteName: string) => string[]
|
|
130
|
+
|
|
131
|
+
/** Opt-in for chemicals storefronts: quote, TDS/SDS and bulk-supply copy. Not part of the neutral default. */
|
|
132
|
+
export const CHEMICAL_QUOTE_CTA: DescriptionCallToAction = (siteName) =>
|
|
133
|
+
[
|
|
134
|
+
siteName ? `Request a quote, TDS and SDS from ${siteName}.` : "",
|
|
135
|
+
"Bulk supply for industrial buyers.",
|
|
136
|
+
].filter(Boolean)
|
|
137
|
+
|
|
138
|
+
const siteNameOnly: DescriptionCallToAction = (siteName) => (siteName ? [`${siteName}.`] : [])
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Real description text of at least 70 characters wins. Anything shorter, or beginning
|
|
142
|
+
* "Product:" (a scraped label), is replaced by a title, category and packaging line, extended
|
|
143
|
+
* with the call-to-action pieces (the site name unless the caller opts into others) while it is
|
|
144
|
+
* under 140 characters, then fitted to 160.
|
|
145
|
+
*/
|
|
146
|
+
function buildProductMetaDescription(
|
|
147
|
+
product: HttpTypes.StoreProduct,
|
|
148
|
+
siteName: string,
|
|
149
|
+
callToAction: DescriptionCallToAction
|
|
150
|
+
): string {
|
|
151
|
+
const plain = product.description ? markdownToPlainText(product.description) : ""
|
|
152
|
+
if (plain.length >= MIN_REAL_DESCRIPTION_LENGTH && !/^product:/i.test(plain)) {
|
|
153
|
+
return truncateForMetaDescription(product.description as string)
|
|
154
|
+
}
|
|
155
|
+
const packaging = (product.metadata as { packaging?: unknown } | null | undefined)?.packaging
|
|
156
|
+
const detail = [product.categories?.[0]?.name, packaging].filter(nonBlank).join(", ")
|
|
157
|
+
|
|
158
|
+
let text = detail ? `${product.title} - ${detail}.` : `${product.title}.`
|
|
159
|
+
for (const piece of callToAction(siteName)) {
|
|
160
|
+
if (text.length >= TEMPLATE_DESCRIPTION_MIN_LENGTH) break
|
|
161
|
+
text = `${text} ${piece}`
|
|
162
|
+
}
|
|
163
|
+
return fitTemplateDescription(text)
|
|
164
|
+
}
|
|
165
|
+
|
|
82
166
|
/**
|
|
83
167
|
* hreflang alternates for a locale-prefixed path, one per storefront country.
|
|
84
168
|
* Degrades to the current locale when regions can't be fetched.
|
|
@@ -114,7 +198,7 @@ function toAbsoluteOpenGraphImageUrl(
|
|
|
114
198
|
): string {
|
|
115
199
|
const trimmedBase = siteBase.replace(/\/+$/, "")
|
|
116
200
|
if (url == null || typeof url !== "string" || url.trim().length === 0) {
|
|
117
|
-
return `${trimmedBase}${fallbackPath}`
|
|
201
|
+
return /^https?:\/\//.test(fallbackPath) ? fallbackPath : `${trimmedBase}${fallbackPath}`
|
|
118
202
|
}
|
|
119
203
|
const trimmed = url.trim()
|
|
120
204
|
if (trimmed.startsWith("https://") || trimmed.startsWith("http://")) {
|
|
@@ -127,30 +211,30 @@ function toAbsoluteOpenGraphImageUrl(
|
|
|
127
211
|
}
|
|
128
212
|
|
|
129
213
|
export const generateProductMetadata = async (
|
|
130
|
-
product: HttpTypes.StoreProduct,
|
|
131
|
-
locale: string
|
|
214
|
+
product: HttpTypes.StoreProduct | undefined,
|
|
215
|
+
locale: string,
|
|
216
|
+
options: { descriptionCallToAction?: DescriptionCallToAction; collapseDoubledTitle?: boolean } = {}
|
|
132
217
|
): Promise<Metadata> => {
|
|
218
|
+
// An unknown handle resolves no product; the page renders the 404, so metadata must not throw.
|
|
219
|
+
if (!product) return noIndexMetadata()
|
|
133
220
|
const base = await getRequestBaseUrl()
|
|
134
221
|
const siteName = await getSiteName("")
|
|
135
222
|
const thumb = toAbsoluteOpenGraphImageUrl(
|
|
136
223
|
base,
|
|
137
|
-
product?.
|
|
138
|
-
|
|
224
|
+
product.thumbnail || product.images?.[0]?.url,
|
|
225
|
+
getDefaultOgImagePath()
|
|
139
226
|
)
|
|
140
227
|
|
|
141
|
-
const path = `/products/${product
|
|
228
|
+
const path = `/products/${product.handle}`
|
|
142
229
|
const canonical = `${base}/${locale}${path}`
|
|
143
230
|
const languages = await buildLanguageAlternates(base, locale, path)
|
|
144
|
-
const description = product
|
|
145
|
-
|
|
146
|
-
: siteName
|
|
147
|
-
? `${product?.title} - ${siteName}`
|
|
148
|
-
: `${product?.title}`
|
|
231
|
+
const description = buildProductMetaDescription(product, siteName, options.descriptionCallToAction ?? siteNameOnly)
|
|
232
|
+
const title = buildProductSeoTitle(product.title, product.type?.value, options)
|
|
149
233
|
|
|
150
234
|
return {
|
|
151
|
-
title
|
|
235
|
+
title,
|
|
152
236
|
description,
|
|
153
|
-
robots:
|
|
237
|
+
robots: rootRobotsMetadata(),
|
|
154
238
|
alternates: {
|
|
155
239
|
canonical,
|
|
156
240
|
languages: {
|
|
@@ -158,9 +242,9 @@ export const generateProductMetadata = async (
|
|
|
158
242
|
"x-default": `${base}${path}`,
|
|
159
243
|
},
|
|
160
244
|
},
|
|
161
|
-
|
|
162
245
|
openGraph: {
|
|
163
|
-
|
|
246
|
+
type: "website",
|
|
247
|
+
title,
|
|
164
248
|
description,
|
|
165
249
|
url: canonical,
|
|
166
250
|
siteName: siteName || undefined,
|
|
@@ -169,14 +253,13 @@ export const generateProductMetadata = async (
|
|
|
169
253
|
url: thumb,
|
|
170
254
|
width: 1200,
|
|
171
255
|
height: 630,
|
|
172
|
-
alt: product?.title,
|
|
256
|
+
alt: resolveStoreImageAlt(product?.images?.[0], product.title, 0),
|
|
173
257
|
},
|
|
174
258
|
],
|
|
175
|
-
type: "website",
|
|
176
259
|
},
|
|
177
260
|
twitter: {
|
|
178
261
|
card: "summary_large_image",
|
|
179
|
-
title
|
|
262
|
+
title,
|
|
180
263
|
description,
|
|
181
264
|
images: [thumb],
|
|
182
265
|
},
|
|
@@ -202,6 +285,26 @@ export const generateBreadcrumbJsonLd = (
|
|
|
202
285
|
})),
|
|
203
286
|
})
|
|
204
287
|
|
|
288
|
+
/**
|
|
289
|
+
* schema.org Organization JSON-LD for a seller page. Deliberately name, url and logo only:
|
|
290
|
+
* seller ratings rate the seller, and are not asserted here (see generateProductJsonLd).
|
|
291
|
+
*/
|
|
292
|
+
export const generateOrganizationJsonLd = ({
|
|
293
|
+
name,
|
|
294
|
+
url,
|
|
295
|
+
logo,
|
|
296
|
+
}: {
|
|
297
|
+
name: string
|
|
298
|
+
url: string
|
|
299
|
+
logo?: string | null
|
|
300
|
+
}): Record<string, unknown> => ({
|
|
301
|
+
"@context": "https://schema.org",
|
|
302
|
+
"@type": "Organization",
|
|
303
|
+
name,
|
|
304
|
+
url,
|
|
305
|
+
...(logo ? { logo } : {}),
|
|
306
|
+
})
|
|
307
|
+
|
|
205
308
|
export type ItemListEntry = { name: string; url: string }
|
|
206
309
|
|
|
207
310
|
/** schema.org ItemList JSON-LD for a small "sample of this listing" block. */
|
|
@@ -258,11 +361,14 @@ export const generateProductJsonLd = (
|
|
|
258
361
|
const base = site?.base ?? getSiteBaseUrl()
|
|
259
362
|
const siteName = site?.siteName ?? (process.env.NEXT_PUBLIC_SITE_NAME || "Storefront")
|
|
260
363
|
const url = `${base}/${locale}/products/${product.handle}`
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
364
|
+
const imageUrls = [product.thumbnail, ...(product.images ?? []).map((entry) => entry.url)].filter(nonBlank)
|
|
365
|
+
const image = [
|
|
366
|
+
...new Set(
|
|
367
|
+
(imageUrls.length > 0 ? imageUrls : [""]).map((url) =>
|
|
368
|
+
toAbsoluteOpenGraphImageUrl(base, url, getDefaultOgImagePath())
|
|
369
|
+
)
|
|
370
|
+
),
|
|
371
|
+
]
|
|
266
372
|
|
|
267
373
|
const { cheapestPrice, cheapestVariant } = getProductPrice({ product })
|
|
268
374
|
const hasValidPrice =
|
|
@@ -365,46 +471,15 @@ export const generateProductJsonLd = (
|
|
|
365
471
|
export const toSafeJsonLdString = (data: unknown): string =>
|
|
366
472
|
JSON.stringify(data).replace(/</g, "\\u003c")
|
|
367
473
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
const categoryDescription = siteName ? `${category.name} Category - ${siteName}` : `${category.name} Category`
|
|
374
|
-
|
|
375
|
-
return {
|
|
376
|
-
robots: "index, follow",
|
|
377
|
-
metadataBase: new URL(
|
|
378
|
-
`${base}/categories/${category.handle}`
|
|
379
|
-
),
|
|
380
|
-
title: `${category.name} Category`,
|
|
381
|
-
description: categoryDescription,
|
|
474
|
+
/** Metadata for pages that must stay out of search results (search, auth, cart). */
|
|
475
|
+
export const noIndexMetadata = (canonical?: string): Metadata => ({
|
|
476
|
+
robots: { index: false, follow: false },
|
|
477
|
+
...(canonical ? { alternates: { canonical } } : {}),
|
|
478
|
+
})
|
|
382
479
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
{
|
|
390
|
-
url:
|
|
391
|
-
`${base}/images/categories/${category.handle}.png` ||
|
|
392
|
-
`${base}/images/placeholder.svg`,
|
|
393
|
-
width: 1200,
|
|
394
|
-
height: 630,
|
|
395
|
-
alt: category.name,
|
|
396
|
-
},
|
|
397
|
-
],
|
|
398
|
-
type: "website",
|
|
399
|
-
},
|
|
400
|
-
twitter: {
|
|
401
|
-
card: "summary_large_image",
|
|
402
|
-
title: category.name,
|
|
403
|
-
description: categoryDescription,
|
|
404
|
-
images: [
|
|
405
|
-
`${base}/images/categories/${category.handle}.png` ||
|
|
406
|
-
`${base}/images/placeholder.svg`,
|
|
407
|
-
],
|
|
408
|
-
},
|
|
409
|
-
}
|
|
410
|
-
}
|
|
480
|
+
/** The cart is per-visitor state: unique title and description, never indexed. */
|
|
481
|
+
export const generateCartMetadata = async (locale: string): Promise<Metadata> => ({
|
|
482
|
+
title: "Shopping cart",
|
|
483
|
+
description: "Review the products in your cart, then check out or request a quote.",
|
|
484
|
+
...noIndexMetadata(`${await getRequestBaseUrl()}/${locale}/cart`),
|
|
485
|
+
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { resolveImageAlt } from "./resolve-image-alt"
|
|
2
|
+
|
|
3
|
+
/** `resolveImageAlt` for Medusa store images, whose `metadata` may be null. */
|
|
4
|
+
export const resolveStoreImageAlt = (
|
|
5
|
+
image: { metadata?: Record<string, unknown> | null } | null | undefined,
|
|
6
|
+
productTitle: string,
|
|
7
|
+
index: number
|
|
8
|
+
) => resolveImageAlt({ metadata: image?.metadata ?? undefined }, productTitle, index)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isIndexingAllowed } from "./seo-config.js"
|
|
2
|
+
|
|
3
|
+
// Next's ProcessEnv type requires NODE_ENV, which would reject plain objects in callers and tests.
|
|
4
|
+
type EnvLike = Record<string, string | undefined>
|
|
5
|
+
|
|
6
|
+
export { isIndexingAllowed, seoHeaders } from "./seo-config.js"
|
|
7
|
+
|
|
8
|
+
export const rootRobotsMetadata = (env?: EnvLike) => {
|
|
9
|
+
const allowed = isIndexingAllowed(env)
|
|
10
|
+
return { index: allowed, follow: allowed }
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NextResponse } from "next/server"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Permanent redirect for locale normalisation. 308 keeps the request method,
|
|
5
|
+
* so it is the default; pass 301 only where a legacy client needs it. Pass 307
|
|
6
|
+
* when the target depends on the visitor (a geo-resolved region), so caches and
|
|
7
|
+
* crawlers do not pin one country's locale for everyone. Auth redirects stay
|
|
8
|
+
* temporary and do not use this.
|
|
9
|
+
*/
|
|
10
|
+
export const localeRedirect = (url: URL, status: 301 | 307 | 308 = 308) =>
|
|
11
|
+
NextResponse.redirect(url, status)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type EnvLike = Record<string, string | undefined>
|
|
2
|
+
|
|
3
|
+
type HeaderRule = {
|
|
4
|
+
source: string
|
|
5
|
+
headers: { key: string; value: string }[]
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export declare const isIndexingAllowed: (env?: EnvLike) => boolean
|
|
9
|
+
export declare const seoHeaders: (env?: EnvLike) => HeaderRule[]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Plain ESM JavaScript on purpose: next.config.ts is loaded by Node before transpilePackages applies,
|
|
2
|
+
// so anything it imports through the package specifier must run without a TypeScript compile step.
|
|
3
|
+
|
|
4
|
+
/** @typedef {Record<string, string | undefined>} EnvLike Next's ProcessEnv type requires NODE_ENV, which would reject plain objects in callers and tests. */
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Indexing is opt-in: anything other than the exact string "true" keeps the
|
|
8
|
+
* site out of search engines, so a missing or mistyped variable fails safe.
|
|
9
|
+
* The default reads the spelled-out `process.env.NEXT_PUBLIC_ALLOW_INDEXING`: Next only inlines
|
|
10
|
+
* that literal at build time, so a read through a parameter would see the runtime value instead
|
|
11
|
+
* and could disagree with what the build baked into next.config headers.
|
|
12
|
+
* @param {EnvLike} [env]
|
|
13
|
+
*/
|
|
14
|
+
export const isIndexingAllowed = (env) =>
|
|
15
|
+
(env ? env.NEXT_PUBLIC_ALLOW_INDEXING : process.env.NEXT_PUBLIC_ALLOW_INDEXING) === "true"
|
|
16
|
+
|
|
17
|
+
/** Auth and cart pages carry per-user state and must never be cached by a shared cache. */
|
|
18
|
+
const NO_STORE_SOURCES = [
|
|
19
|
+
"/:locale/login",
|
|
20
|
+
"/:locale/register",
|
|
21
|
+
"/:locale/forgot-password",
|
|
22
|
+
"/:locale/cart",
|
|
23
|
+
"/:locale/user/:path*",
|
|
24
|
+
"/:locale/checkout/:path*",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
const NOINDEX_RULE = {
|
|
28
|
+
source: "/:path*",
|
|
29
|
+
headers: [{ key: "X-Robots-Tag", value: "noindex, nofollow" }],
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Rules for next.config.ts `headers()`.
|
|
34
|
+
* @param {EnvLike} [env]
|
|
35
|
+
*/
|
|
36
|
+
export const seoHeaders = (env) => [
|
|
37
|
+
...(isIndexingAllowed(env) ? [] : [NOINDEX_RULE]),
|
|
38
|
+
...NO_STORE_SOURCES.map((source) => ({
|
|
39
|
+
source,
|
|
40
|
+
headers: [{ key: "Cache-Control", value: "no-store" }],
|
|
41
|
+
})),
|
|
42
|
+
]
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { ForgotPasswordForm } from "../../../components/molecules/ForgotPasswordForm/ForgotPasswordForm"
|
|
2
|
+
import { noIndexMetadata } from "../../../lib/helpers/seo"
|
|
2
3
|
import { Metadata } from "next"
|
|
3
4
|
|
|
4
5
|
export const metadata: Metadata = {
|
|
5
6
|
title: "Forgot password",
|
|
6
7
|
description: "Create a new password",
|
|
8
|
+
...noIndexMetadata(),
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
export default function ForgotPasswordPage() {
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { LoginForm } from "../../../components/molecules"
|
|
2
2
|
import { retrieveCustomer } from "../../../lib/data/customer"
|
|
3
|
+
import { noIndexMetadata } from "../../../lib/helpers/seo"
|
|
4
|
+
import { getRequestBaseUrl } from "../../../lib/helpers/request-base-url"
|
|
3
5
|
import { unstable_noStore } from "next/cache"
|
|
4
6
|
import { redirect } from "next/navigation"
|
|
5
7
|
|
|
6
8
|
export const dynamic = "force-dynamic"
|
|
7
9
|
|
|
10
|
+
/** Every `?redirect=` variant canonicalises to the bare login URL. */
|
|
11
|
+
export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }) {
|
|
12
|
+
const { locale } = await params
|
|
13
|
+
return {
|
|
14
|
+
title: "Log in",
|
|
15
|
+
description: "Sign in to your account to request quotes, track orders and manage your company.",
|
|
16
|
+
...noIndexMetadata(`${await getRequestBaseUrl()}/${locale}/login`),
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
8
20
|
function isTokenExpiredParam(value: string | string[] | undefined): boolean {
|
|
9
21
|
if (!value) return false
|
|
10
22
|
const v = Array.isArray(value) ? value[0] : value
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { RegisterForm } from "../../../components/molecules"
|
|
2
2
|
import { retrieveCustomer } from "../../../lib/data/customer"
|
|
3
3
|
import { getUnlinkedSignupPrefill } from "../../../lib/data/unlinked-signup-prefill"
|
|
4
|
+
import { noIndexMetadata } from "../../../lib/helpers/seo"
|
|
5
|
+
import { getRequestBaseUrl } from "../../../lib/helpers/request-base-url"
|
|
4
6
|
import { redirect } from "next/navigation"
|
|
5
7
|
|
|
8
|
+
export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }) {
|
|
9
|
+
const { locale } = await params
|
|
10
|
+
return {
|
|
11
|
+
title: "Create an account",
|
|
12
|
+
description: "Register a buyer account to request quotes, order samples and track orders.",
|
|
13
|
+
...noIndexMetadata(`${await getRequestBaseUrl()}/${locale}/register`),
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
6
17
|
/**
|
|
7
18
|
* Register page. `?redirect=` cookie seeding happens in storefront middleware
|
|
8
19
|
* (Server Components cannot mutate cookies in Next.js 15).
|
|
@@ -87,12 +87,12 @@ function InviteAccept() {
|
|
|
87
87
|
<Panel state="logged_out" title="Sign in to join your company">
|
|
88
88
|
<Body>Sign in or create an account with the email address this invitation was sent to.</Body>
|
|
89
89
|
<div className="flex flex-col gap-2 sm:flex-row">
|
|
90
|
-
<Link href={`/${locale}/login?redirect=${back}`} className="w-full sm:w-auto">
|
|
90
|
+
<Link href={`/${locale}/login?redirect=${back}`} rel="nofollow" className="w-full sm:w-auto">
|
|
91
91
|
<Button variant="filled" className="w-full sm:w-auto">
|
|
92
92
|
Sign in
|
|
93
93
|
</Button>
|
|
94
94
|
</Link>
|
|
95
|
-
<Link href={`/${locale}/register?redirect=${back}`} className="w-full sm:w-auto">
|
|
95
|
+
<Link href={`/${locale}/register?redirect=${back}`} rel="nofollow" className="w-full sm:w-auto">
|
|
96
96
|
<Button variant="tonal" className="w-full sm:w-auto">
|
|
97
97
|
Create an account
|
|
98
98
|
</Button>
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
toSafeJsonLdString,
|
|
19
19
|
} from "../../../../lib/helpers/seo"
|
|
20
20
|
import { buildHreflangAlternates } from "../../../../lib/helpers/hreflang"
|
|
21
|
+
import { rootRobotsMetadata } from "../../../../lib/seo/indexing"
|
|
21
22
|
import {
|
|
22
23
|
listingSuspenseKey,
|
|
23
24
|
parseListingControls,
|
|
@@ -65,7 +66,7 @@ export async function generateMetadata({
|
|
|
65
66
|
canonical,
|
|
66
67
|
languages,
|
|
67
68
|
},
|
|
68
|
-
robots:
|
|
69
|
+
robots: rootRobotsMetadata(),
|
|
69
70
|
openGraph: {
|
|
70
71
|
title: `${title} | ${(await getSiteName("Storefront"))}`,
|
|
71
72
|
description,
|
|
@@ -5,17 +5,45 @@ import { ProductListingSkeleton } from "../../../components/organisms/ProductLis
|
|
|
5
5
|
import { AuctionListing } from "../../../components/sections/AuctionListing/AuctionListing"
|
|
6
6
|
import {
|
|
7
7
|
type AuctionListingQuery,
|
|
8
|
+
auctionListingFilters,
|
|
8
9
|
auctionListingSuspenseKey,
|
|
9
10
|
parseAuctionListingControls,
|
|
10
11
|
} from "../../../lib/auction/parse-auction-listing-controls"
|
|
12
|
+
import { listAuctions } from "../../../lib/data/bidding"
|
|
13
|
+
import { reportError } from "../../../lib/helpers/report-error"
|
|
14
|
+
import { noIndexMetadata } from "../../../lib/helpers/seo"
|
|
15
|
+
import { isIndexingAllowed } from "../../../lib/seo/indexing"
|
|
11
16
|
import { auctionSkinPageClassNames } from "../../../lib/storefront/auction-ui-skin"
|
|
12
17
|
import { cn } from "../../../lib/utils"
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
// The root layout's title template already appends the site name.
|
|
20
|
+
const baseMetadata: Metadata = {
|
|
21
|
+
title: "Browse Live Auctions",
|
|
16
22
|
description: "Discover and bid on exclusive items in our live auctions. Find unique products at competitive prices.",
|
|
17
23
|
}
|
|
18
24
|
|
|
25
|
+
/** An empty listing is a thin page: keep it out of the index. Metadata cannot see the page's data, so count here. */
|
|
26
|
+
export async function generateMetadata({
|
|
27
|
+
searchParams,
|
|
28
|
+
}: {
|
|
29
|
+
searchParams: Promise<AuctionListingQuery>
|
|
30
|
+
}): Promise<Metadata> {
|
|
31
|
+
const controls = parseAuctionListingControls(await searchParams)
|
|
32
|
+
// The root metadata already noindexes the whole site, so counting auctions would be a wasted backend call.
|
|
33
|
+
if (!isIndexingAllowed()) return baseMetadata
|
|
34
|
+
try {
|
|
35
|
+
const { count } = await listAuctions(
|
|
36
|
+
{ pageParam: 1, limit: 1, filters: auctionListingFilters(controls) },
|
|
37
|
+
{ throwOnError: true }
|
|
38
|
+
)
|
|
39
|
+
return count === 0 ? { ...baseMetadata, ...noIndexMetadata() } : baseMetadata
|
|
40
|
+
} catch (error) {
|
|
41
|
+
// The page itself surfaces the failure through its error boundary; metadata must not mask it.
|
|
42
|
+
reportError(error)
|
|
43
|
+
return baseMetadata
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
19
47
|
// Query-driven listing (reads searchParams in RSC): rendered per request,
|
|
20
48
|
// never ISR — see nextjs-static-dynamic-boundaries.mdc.
|
|
21
49
|
export default async function AuctionsPage({
|
|
@@ -2,6 +2,7 @@ import { getSiteName } from "../../../lib/data/brand"
|
|
|
2
2
|
import type { Metadata } from "next"
|
|
3
3
|
import { BestSellersListing } from "../../../components/sections"
|
|
4
4
|
import { buildHreflangAlternates } from "../../../lib/helpers/hreflang"
|
|
5
|
+
import { rootRobotsMetadata } from "../../../lib/seo/indexing"
|
|
5
6
|
import { parseListingPage } from "../../../lib/helpers/parse-listing-page"
|
|
6
7
|
|
|
7
8
|
// Query-driven listing (reads searchParams in RSC) — incompatible with ISR;
|
|
@@ -25,7 +26,7 @@ export async function generateMetadata({
|
|
|
25
26
|
title,
|
|
26
27
|
description,
|
|
27
28
|
alternates: { canonical, languages },
|
|
28
|
-
robots:
|
|
29
|
+
robots: rootRobotsMetadata(),
|
|
29
30
|
openGraph: {
|
|
30
31
|
title: `${title} | ${(await getSiteName("Storefront"))}`,
|
|
31
32
|
description,
|
|
@@ -11,11 +11,12 @@ import { getRequestBaseUrl } from "../../../../lib/helpers/request-base-url"
|
|
|
11
11
|
import Script from "next/script"
|
|
12
12
|
import { loadCategoryItemListJsonLd } from "../../../../lib/helpers/listing-item-list-json-ld"
|
|
13
13
|
import { buildHreflangAlternates } from "../../../../lib/helpers/hreflang"
|
|
14
|
+
import { rootRobotsMetadata } from "../../../../lib/seo/indexing"
|
|
14
15
|
import {
|
|
15
16
|
listingSuspenseKey,
|
|
16
17
|
parseListingControls,
|
|
17
18
|
} from "../../../../lib/helpers/parse-listing-controls"
|
|
18
|
-
import { generateBreadcrumbJsonLd, toSafeJsonLdString } from "../../../../lib/helpers/seo"
|
|
19
|
+
import { generateBreadcrumbJsonLd, getDefaultOgImagePath, toSafeJsonLdString } from "../../../../lib/helpers/seo"
|
|
19
20
|
import { parseApplicationIds } from "../../../../lib/helpers/parse-application-ids"
|
|
20
21
|
|
|
21
22
|
// Query-driven listing (reads searchParams in RSC) — incompatible with ISR;
|
|
@@ -51,12 +52,13 @@ export async function generateMetadata({
|
|
|
51
52
|
canonical,
|
|
52
53
|
languages,
|
|
53
54
|
},
|
|
54
|
-
robots:
|
|
55
|
+
robots: rootRobotsMetadata(),
|
|
55
56
|
openGraph: {
|
|
56
57
|
title: `${title} | ${(await getSiteName("Storefront"))}`,
|
|
57
58
|
description,
|
|
58
59
|
url: canonical,
|
|
59
60
|
siteName: (await getSiteName("Storefront")),
|
|
61
|
+
images: [{ url: getDefaultOgImagePath(), width: 1200, height: 630, alt: cat.name }],
|
|
60
62
|
type: "website",
|
|
61
63
|
},
|
|
62
64
|
}
|
|
@@ -8,6 +8,7 @@ import type { Metadata } from "next"
|
|
|
8
8
|
import Script from "next/script"
|
|
9
9
|
import { listProducts } from "../../../lib/data/products"
|
|
10
10
|
import { buildHreflangAlternates } from "../../../lib/helpers/hreflang"
|
|
11
|
+
import { rootRobotsMetadata } from "../../../lib/seo/indexing"
|
|
11
12
|
import { getTenantOrigin } from "../../../lib/helpers/request-base-url"
|
|
12
13
|
import {
|
|
13
14
|
listingSuspenseKey,
|
|
@@ -47,7 +48,7 @@ export async function generateMetadata({
|
|
|
47
48
|
canonical,
|
|
48
49
|
languages,
|
|
49
50
|
},
|
|
50
|
-
robots:
|
|
51
|
+
robots: rootRobotsMetadata(),
|
|
51
52
|
openGraph: {
|
|
52
53
|
title: `${title} | ${(await getSiteName("Storefront"))}`,
|
|
53
54
|
description,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Metadata } from "next"
|
|
2
2
|
import { notFound } from "next/navigation"
|
|
3
|
-
import Link from "next/link"
|
|
4
3
|
|
|
5
4
|
import { getPlatformLegal, getStoreLegal } from "../../../../lib/data/legal"
|
|
5
|
+
import LocalizedClientLink from "../../../../components/molecules/LocalizedLink/LocalizedLink"
|
|
6
|
+
import { getRequestBaseUrl } from "../../../../lib/helpers/request-base-url"
|
|
7
|
+
import { generateBreadcrumbJsonLd, toSafeJsonLdString } from "../../../../lib/helpers/seo"
|
|
6
8
|
import { LegalDocument } from "../../../../components/molecules/LegalDocument/LegalDocument"
|
|
7
9
|
import { docForSlug, isLegalSlug, LEGAL_SLUG_LABELS, type LegalSlug } from "../legal-docs"
|
|
8
10
|
|
|
@@ -42,7 +44,7 @@ export async function generateMetadata({ params }: { params: Params }): Promise<
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
export default async function LegalPolicyPage({ params }: { params: Params }) {
|
|
45
|
-
const { type } = await params
|
|
47
|
+
const { locale, type } = await params
|
|
46
48
|
if (!isLegalSlug(type)) {
|
|
47
49
|
notFound()
|
|
48
50
|
}
|
|
@@ -55,25 +57,37 @@ export default async function LegalPolicyPage({ params }: { params: Params }) {
|
|
|
55
57
|
<p className="text-neutral-600 mb-8" data-testid="legal-unpublished">
|
|
56
58
|
This store has not published a {LEGAL_SLUG_LABELS[type].toLowerCase()} yet.
|
|
57
59
|
</p>
|
|
58
|
-
<
|
|
60
|
+
<LocalizedClientLink href="/legal" className="text-sm text-neutral-500 hover:text-neutral-700">
|
|
59
61
|
← Back to Legal Information
|
|
60
|
-
</
|
|
62
|
+
</LocalizedClientLink>
|
|
61
63
|
</div>
|
|
62
64
|
</main>
|
|
63
65
|
)
|
|
64
66
|
}
|
|
65
67
|
|
|
68
|
+
const base = await getRequestBaseUrl()
|
|
69
|
+
const docTitle = doc.title?.trim() || LEGAL_SLUG_LABELS[type]
|
|
70
|
+
const breadcrumb = generateBreadcrumbJsonLd([
|
|
71
|
+
{ name: "Home", url: `${base}/${locale}` },
|
|
72
|
+
{ name: "Legal", url: `${base}/${locale}/legal` },
|
|
73
|
+
{ name: docTitle },
|
|
74
|
+
])
|
|
75
|
+
|
|
66
76
|
return (
|
|
67
77
|
<main className="container py-8 md:py-12">
|
|
78
|
+
<script
|
|
79
|
+
type="application/ld+json"
|
|
80
|
+
dangerouslySetInnerHTML={{ __html: toSafeJsonLdString(breadcrumb) }}
|
|
81
|
+
/>
|
|
68
82
|
<div className="max-w-4xl mx-auto">
|
|
69
83
|
<nav aria-label="Breadcrumb" className="mb-6 text-sm">
|
|
70
|
-
<
|
|
84
|
+
<LocalizedClientLink href="/legal" className="text-neutral-500 hover:text-neutral-700">
|
|
71
85
|
Legal
|
|
72
|
-
</
|
|
86
|
+
</LocalizedClientLink>
|
|
73
87
|
<span className="mx-2 text-neutral-400" aria-hidden="true">
|
|
74
88
|
/
|
|
75
89
|
</span>
|
|
76
|
-
<span className="text-neutral-900">{
|
|
90
|
+
<span className="text-neutral-900">{docTitle}</span>
|
|
77
91
|
</nav>
|
|
78
92
|
|
|
79
93
|
<LegalDocument
|
|
@@ -87,9 +101,9 @@ export default async function LegalPolicyPage({ params }: { params: Params }) {
|
|
|
87
101
|
/>
|
|
88
102
|
|
|
89
103
|
<div className="mt-12 pt-6 border-t border-neutral-200">
|
|
90
|
-
<
|
|
104
|
+
<LocalizedClientLink href="/legal" className="text-sm text-neutral-500 hover:text-neutral-700">
|
|
91
105
|
← Back to Legal Information
|
|
92
|
-
</
|
|
106
|
+
</LocalizedClientLink>
|
|
93
107
|
</div>
|
|
94
108
|
</div>
|
|
95
109
|
</main>
|