@revenexx/cover 0.22.0 → 0.23.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/app/api/categories.ts +1 -0
- package/app/api/offers.ts +1 -0
- package/app/app.config.ts +13 -0
- package/app/components/OgImage/CoverPage.takumi.vue +37 -0
- package/app/components/RevenexxForm.vue +21 -6
- package/app/components/account/approvals/AccountPendingApprovals.vue +19 -1
- package/app/components/account/approvals/AccountPendingOrderDetail.vue +3 -0
- package/app/components/account/carts/AccountCartsTable.vue +11 -1
- package/app/components/account/orderlists/AccountOrderListDetail.vue +32 -3
- package/app/components/account/organization/AccountOrganization.vue +1 -1
- package/app/components/auth/AuthForgotPasswordPanel.vue +7 -2
- package/app/components/auth/AuthLoginPanel.vue +23 -8
- package/app/components/auth/AuthRegisterTeaser.vue +1 -1
- package/app/components/cart/position/CartPosition.vue +11 -4
- package/app/components/cart/quickadd/CartQuickAdd.vue +4 -2
- package/app/components/cart/recommend/CartRecommendCard.vue +1 -0
- package/app/components/cart/switcher/CartSwitcher.vue +1 -0
- package/app/components/cart/view/CartListHeader.vue +5 -0
- package/app/components/cart/view/CartSummaryPanel.vue +20 -8
- package/app/components/cart/view/CartView.vue +4 -2
- package/app/components/checkout/onepage/CheckoutGate.vue +4 -2
- package/app/components/checkout/onepage/CheckoutGuestDetailsSection.vue +2 -1
- package/app/components/checkout/onepage/CheckoutPaymentSection.vue +1 -1
- package/app/components/checkout/onepage/CheckoutSummarySection.vue +8 -0
- package/app/components/checkout/return/CheckoutPaymentReturn.vue +7 -0
- package/app/components/layout/footer/Footer.vue +21 -4
- package/app/components/layout/header/AppBar.vue +5 -2
- package/app/components/layout/header/LocaleSwitcher.vue +7 -9
- package/app/components/layout/header/MobileMenu.vue +4 -1
- package/app/components/product/detail/ProductDetailAddToCart.vue +17 -11
- package/app/components/product/detail/ProductDetailImageGallery.vue +101 -8
- package/app/components/product/detail/ProductDetailVariantRow.vue +84 -4
- package/app/components/product/detail/ProductDetailVariants.vue +75 -11
- package/app/components/product/detail/ProductDetailView.vue +64 -69
- package/app/components/punchout/action/PunchoutTransferAction.vue +4 -3
- package/app/composables/useAuthStore.ts +21 -4
- package/app/composables/useCategories.ts +24 -0
- package/app/composables/useCategoryAnswer.ts +30 -0
- package/app/composables/useCategorySeo.ts +62 -0
- package/app/composables/useDefaultUiLanguage.ts +14 -0
- package/app/composables/useOgImageReady.ts +16 -0
- package/app/composables/useProductAnswer.ts +121 -0
- package/app/composables/useProductLocales.ts +21 -10
- package/app/composables/useProductSeo.ts +145 -0
- package/app/composables/usePunchoutVisit.ts +36 -1
- package/app/composables/useRouteSubject.ts +23 -3
- package/app/composables/useSeoContext.ts +164 -0
- package/app/composables/useSeoHead.ts +189 -0
- package/app/composables/useSeoRules.ts +23 -0
- package/app/interfaces/punchout.ts +11 -0
- package/app/interfaces/seo.ts +48 -0
- package/app/layouts/default.vue +2 -8
- package/app/layouts/focus.vue +3 -1
- package/app/middleware/punchout-exits.global.ts +25 -0
- package/app/payments/psp/novalnet.ts +25 -3
- package/app/payments/psp/novalnetStyle.ts +186 -0
- package/app/plugins/punchout-links.client.ts +46 -0
- package/app/shared/categoryTree.ts +7 -0
- package/app/shared/locale.ts +8 -0
- package/app/shared/productLocales.ts +62 -1
- package/app/shared/punchoutExits.ts +156 -0
- package/app/shared/seoRules.ts +297 -0
- package/app/shared/structuredData.ts +104 -0
- package/i18n/locales/de/account.json +4 -0
- package/i18n/locales/de/common.json +6 -0
- package/i18n/locales/de/pages.json +109 -0
- package/i18n/locales/de/punchout.json +3 -0
- package/i18n/locales/en/account.json +4 -0
- package/i18n/locales/en/common.json +6 -0
- package/i18n/locales/en/pages.json +109 -0
- package/i18n/locales/en/punchout.json +3 -0
- package/nuxt.config.ts +140 -1
- package/package.json +10 -3
- package/server/api/auth/otp.post.ts +4 -8
- package/server/api/auth/otp.put.ts +20 -11
- package/server/api/categories/[slug]/exists.get.ts +28 -0
- package/server/api/offers/guest.get.ts +53 -0
- package/server/api/orders/index.post.ts +18 -11
- package/server/api/payment/methods.post.ts +2 -33
- package/server/api/product/[id]/locales.get.ts +9 -3
- package/server/data/product-detail.json +0 -20
- package/server/dev/errorHandler.ts +9 -5
- package/server/dev/typesense/autoSeed.ts +63 -0
- package/server/dev/typesense/seed.ts +4 -43
- package/server/dev/typesense/seedProducts.ts +87 -0
- package/server/interfaces/category.ts +5 -0
- package/server/interfaces/product.ts +13 -6
- package/server/interfaces/punchout.ts +20 -1
- package/server/middleware/missing-media.ts +2 -2
- package/server/middleware/punchout-exits.ts +45 -0
- package/server/middleware/punchout-visit-csp.ts +35 -0
- package/server/plugins/previewHostNoindex.ts +21 -0
- package/server/plugins/punchout-cookies.ts +48 -0
- package/server/plugins/seoSiteConfig.ts +62 -0
- package/server/routes/punchout/start.get.ts +7 -0
- package/server/routes/robots.txt.ts +21 -0
- package/server/services/ApiCategoryService.ts +6 -0
- package/server/services/ApiProductService.ts +2 -2
- package/server/services/LocalFileCategoryService.ts +6 -0
- package/server/utils/liveCatalog.ts +83 -18
- package/server/utils/livePrices.ts +12 -3
- package/server/utils/locale.ts +3 -8
- package/server/utils/offerService.ts +8 -3
- package/server/utils/paymentOptions.ts +49 -0
- package/server/utils/promotionsService.ts +25 -0
- package/server/utils/punchoutFrame.ts +131 -0
- package/server/utils/punchoutOrder.ts +40 -0
- package/server/utils/punchoutVisit.ts +41 -8
- package/server/utils/revenexxSdk.ts +7 -1
- package/server/utils/seoRequestHost.ts +21 -0
- package/server/utils/storefrontMessages.ts +5 -5
- package/server/utils/storefrontSeoRules.ts +298 -0
- package/server/middleware/punchout-hand-back-csp.ts +0 -17
|
@@ -32,6 +32,44 @@ export function languagesWithDocuments(
|
|
|
32
32
|
searchLocaleKeys(language).some(key => present.has(key)));
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* The product's name in each language (of `languages`) it has a document in:
|
|
37
|
+
* the document the product page would find, under the first of the
|
|
38
|
+
* language's search keys that has one (PE-1236). A product's slug carries its
|
|
39
|
+
* name, so a link into another language needs that language's name, or it
|
|
40
|
+
* lands on the outdated-slug 301.
|
|
41
|
+
*/
|
|
42
|
+
export function namesByLanguage(
|
|
43
|
+
docs: readonly { readonly locale: string; readonly name?: string }[],
|
|
44
|
+
languages: readonly string[],
|
|
45
|
+
): Record<string, string> {
|
|
46
|
+
const byLocale = new Map(docs
|
|
47
|
+
.filter(doc => doc.locale && doc.name)
|
|
48
|
+
.map(doc => [normalizeLocaleCode(doc.locale), doc.name as string]));
|
|
49
|
+
const names: Record<string, string> = {};
|
|
50
|
+
for (const language of languages) {
|
|
51
|
+
const key = searchLocaleKeys(language).find(candidate => byLocale.has(candidate));
|
|
52
|
+
if (key) {
|
|
53
|
+
names[language] = byLocale.get(key) as string;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return names;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A product page's path with its slug swapped for another language's. The
|
|
61
|
+
* slug is the path's last segment; a path that does not end in `current` is
|
|
62
|
+
* returned as it is.
|
|
63
|
+
*/
|
|
64
|
+
export function withProductSlug(path: string, current: string, target: string): string {
|
|
65
|
+
const [pathname = "", ...rest] = path.split(/(?=[?#])/);
|
|
66
|
+
const suffix = `/${encodeURIComponent(current)}`;
|
|
67
|
+
if (!current || !target || current === target || !pathname.endsWith(suffix)) {
|
|
68
|
+
return path;
|
|
69
|
+
}
|
|
70
|
+
return `${pathname.slice(0, -suffix.length)}/${encodeURIComponent(target)}${rest.join("")}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
35
73
|
/**
|
|
36
74
|
* The listing a language without the product sends the buyer to: the
|
|
37
75
|
* product's own category, as deep as a listing URL goes
|
|
@@ -41,10 +79,15 @@ export function languagesWithDocuments(
|
|
|
41
79
|
* translated, so the same path exists in every language.
|
|
42
80
|
*/
|
|
43
81
|
export function productFallbackPath(categorySegments: readonly string[]): string {
|
|
44
|
-
const path = categorySegments
|
|
82
|
+
const path = productListingSegments(categorySegments);
|
|
45
83
|
return path.length ? `/category/${path.map(encodeURIComponent).join("/")}` : "/";
|
|
46
84
|
}
|
|
47
85
|
|
|
86
|
+
/** The category and subcategory of productFallbackPath(), none for `_` or a URL without a category. */
|
|
87
|
+
export function productListingSegments(categorySegments: readonly string[]): string[] {
|
|
88
|
+
return categorySegments.filter(segment => segment && segment !== "_").slice(0, 2);
|
|
89
|
+
}
|
|
90
|
+
|
|
48
91
|
/** The category segments of a `/category/<…>/product/<slug>` route. */
|
|
49
92
|
export function productRouteCategorySegments(category: readonly string[], rest: readonly string[]): string[] {
|
|
50
93
|
const marker = rest.lastIndexOf("product");
|
|
@@ -67,6 +110,24 @@ export interface LocaleHeadMeta {
|
|
|
67
110
|
[key: string]: unknown;
|
|
68
111
|
}
|
|
69
112
|
|
|
113
|
+
/**
|
|
114
|
+
* The locale head with each alternate's href put through `localize` for its
|
|
115
|
+
* language (`x-default` for `defaultLocale`): a product page's alternates
|
|
116
|
+
* carry the slug of the language they link (PE-1236).
|
|
117
|
+
*/
|
|
118
|
+
export function localizeLocaleHeadAlternates<L extends LocaleHeadLink, M extends LocaleHeadMeta>(
|
|
119
|
+
head: { link?: L[]; meta?: M[] },
|
|
120
|
+
localize: (href: string, code: string) => string,
|
|
121
|
+
defaultLocale: string,
|
|
122
|
+
): { link: L[]; meta: M[] } {
|
|
123
|
+
return {
|
|
124
|
+
link: (head.link ?? []).map(entry => (entry.rel === "alternate" && entry.hreflang && entry.href
|
|
125
|
+
? { ...entry, href: localize(entry.href, entry.hreflang === "x-default" ? defaultLocale : entry.hreflang) }
|
|
126
|
+
: entry)),
|
|
127
|
+
meta: head.meta ?? [],
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
70
131
|
/**
|
|
71
132
|
* The locale head with alternates only for the languages that have the page.
|
|
72
133
|
*
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { PunchoutPurchaseMode } from "../interfaces/punchout";
|
|
2
|
+
|
|
3
|
+
/** What the rules read off a visit — the server's record and the browser's view alike. */
|
|
4
|
+
export interface PunchoutExitVisit {
|
|
5
|
+
readonly purchaseMode?: PunchoutPurchaseMode | null;
|
|
6
|
+
/** The checkout placed this visit's order. */
|
|
7
|
+
readonly ordered?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The exits a punchout visit has, and the routes it may not reach (RAD-226).
|
|
12
|
+
*
|
|
13
|
+
* A punchout visit runs inside the buyer's procurement system and has one way
|
|
14
|
+
* out: the one its account's purchase mode names. Everything a storefront
|
|
15
|
+
* session offers besides — the account area, signing in or out, registering,
|
|
16
|
+
* the checkout of a visit that only hands its cart back — is hidden in the
|
|
17
|
+
* shop AND refused here, because a buyer can type an address.
|
|
18
|
+
*
|
|
19
|
+
* Shared by the BFF (a typed address, a full page load) and the shop's route
|
|
20
|
+
* middleware (a link followed inside the app), so the two cannot disagree.
|
|
21
|
+
*
|
|
22
|
+
* The rule holds only while the visit is live. A visit that was handed back,
|
|
23
|
+
* or that ran out, is over, and the shop is an ordinary shop again.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** A purchase mode the claim did not answer is `transfer` (punchout's own default). */
|
|
27
|
+
export function purchaseModeOf(value: unknown): PunchoutPurchaseMode {
|
|
28
|
+
return value === "order" || value === "order_and_transfer" ? value : "transfer";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface PunchoutExits {
|
|
32
|
+
/** The shop's checkout places an order. */
|
|
33
|
+
readonly checkout: boolean;
|
|
34
|
+
/** The cart can be handed back to the procurement system. */
|
|
35
|
+
readonly handBack: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Which exits a visit offers.
|
|
40
|
+
*
|
|
41
|
+
* `order_and_transfer` offers both, as ONE step: the checkout, and then the
|
|
42
|
+
* hand-back of the ordered cart, which the punchout app refuses without the
|
|
43
|
+
* order. A visit already ordered in `order` mode has no exit left.
|
|
44
|
+
*/
|
|
45
|
+
export function punchoutExits(visit: PunchoutExitVisit): PunchoutExits {
|
|
46
|
+
const mode = purchaseModeOf(visit.purchaseMode);
|
|
47
|
+
if (mode === "order") {
|
|
48
|
+
return { checkout: visit.ordered !== true, handBack: false };
|
|
49
|
+
}
|
|
50
|
+
if (mode === "order_and_transfer") {
|
|
51
|
+
return { checkout: visit.ordered !== true, handBack: true };
|
|
52
|
+
}
|
|
53
|
+
return { checkout: false, handBack: true };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A path without its locale prefix (`/de/account` → `/account`) and query. */
|
|
57
|
+
export function unprefixedPath(path: string): { readonly prefix: string; readonly rest: string } {
|
|
58
|
+
const bare = (path.split("?")[0] ?? "/").replace(/\/+$/, "") || "/";
|
|
59
|
+
const match = /^\/([a-z]{2}(?:-[a-z]{2})?)(\/.*|$)/i.exec(bare);
|
|
60
|
+
// `/de` alone is the home page in that locale, not a page called `de`.
|
|
61
|
+
if (match && !/^\/(api|_nuxt|punchout)\b/.test(bare)) {
|
|
62
|
+
return { prefix: `/${match[1]}`, rest: match[2] || "/" };
|
|
63
|
+
}
|
|
64
|
+
return { prefix: "", rest: bare };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Pages a live visit never shows: the account area and everything about signing in. */
|
|
68
|
+
const PAGES_NEVER = [
|
|
69
|
+
/^\/account(?:\/|$)/,
|
|
70
|
+
/^\/login(?:\/|$)/,
|
|
71
|
+
/^\/register(?:\/|$)/,
|
|
72
|
+
/^\/forgot-password$/,
|
|
73
|
+
/^\/reset-password$/,
|
|
74
|
+
/^\/callback$/,
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
/** The checkout pages — only for a visit that may order. */
|
|
78
|
+
const CHECKOUT_PAGES = /^\/checkout(?:\/|$)/;
|
|
79
|
+
/** The hand-back page — only for a visit that may hand back. */
|
|
80
|
+
const HAND_BACK_PAGE = /^\/punchout\/transfer$/;
|
|
81
|
+
|
|
82
|
+
/** BFF routes a live visit never calls: signing in or out, registering, recovering a password. */
|
|
83
|
+
const API_NEVER = [
|
|
84
|
+
/^\/api\/auth\/(?:login|logout|register|recovery|magic-link|otp)$/,
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
/** BFF routes that place an order. */
|
|
88
|
+
const CHECKOUT_API = [
|
|
89
|
+
/^\/api\/orders$/,
|
|
90
|
+
/^\/api\/checkout\/session$/,
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
/** The BFF route that hands the cart back. */
|
|
94
|
+
const HAND_BACK_API = /^\/api\/punchout\/return$/;
|
|
95
|
+
|
|
96
|
+
export type PunchoutRefusal =
|
|
97
|
+
| { readonly kind: "redirect"; readonly to: string }
|
|
98
|
+
| { readonly kind: "refuse"; readonly type: "punchout_exit_not_offered" | "punchout_session_closed" };
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* What a live visit does with this request: nothing (null), send the page back
|
|
102
|
+
* to the visit's cart, or refuse the call.
|
|
103
|
+
*
|
|
104
|
+
* Only state-changing calls are refused on the BFF side: what a buyer READS
|
|
105
|
+
* about their own account is theirs to read, and a product page that asks
|
|
106
|
+
* for an order list should not break because the visit has no account area.
|
|
107
|
+
*/
|
|
108
|
+
export function punchoutRefusal(
|
|
109
|
+
path: string,
|
|
110
|
+
method: string,
|
|
111
|
+
visit: PunchoutExitVisit,
|
|
112
|
+
): PunchoutRefusal | null {
|
|
113
|
+
const { prefix, rest } = unprefixedPath(path);
|
|
114
|
+
const exits = punchoutExits(visit);
|
|
115
|
+
const back: PunchoutRefusal = { kind: "redirect", to: `${prefix}/cart` };
|
|
116
|
+
|
|
117
|
+
if (rest.startsWith("/api/")) {
|
|
118
|
+
const writes = method.toUpperCase() !== "GET" && method.toUpperCase() !== "HEAD";
|
|
119
|
+
if (!writes) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
if (API_NEVER.some(rule => rule.test(rest))) {
|
|
123
|
+
return { kind: "refuse", type: "punchout_exit_not_offered" };
|
|
124
|
+
}
|
|
125
|
+
if (!exits.checkout && CHECKOUT_API.some(rule => rule.test(rest))) {
|
|
126
|
+
return { kind: "refuse", type: "punchout_exit_not_offered" };
|
|
127
|
+
}
|
|
128
|
+
if (!exits.handBack && HAND_BACK_API.test(rest)) {
|
|
129
|
+
return { kind: "refuse", type: "punchout_exit_not_offered" };
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (PAGES_NEVER.some(rule => rule.test(rest))) {
|
|
135
|
+
return back;
|
|
136
|
+
}
|
|
137
|
+
// The confirmation of the order this visit placed stays reachable: the
|
|
138
|
+
// buyer has to be able to read what they ordered.
|
|
139
|
+
if (!exits.checkout && CHECKOUT_PAGES.test(rest) && !(visit.ordered === true && rest === "/checkout/confirmation")) {
|
|
140
|
+
return back;
|
|
141
|
+
}
|
|
142
|
+
if (!exits.handBack && HAND_BACK_PAGE.test(rest)) {
|
|
143
|
+
return back;
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The checkout calls a visit that RAN OUT may not make: an order created after
|
|
150
|
+
* the visit's expiry does not count for it, and the buyer would have placed
|
|
151
|
+
* an order their procurement system never hears of.
|
|
152
|
+
*/
|
|
153
|
+
export function isCheckoutCall(path: string, method: string): boolean {
|
|
154
|
+
const { rest } = unprefixedPath(path);
|
|
155
|
+
return method.toUpperCase() === "POST" && CHECKOUT_API.some(rule => rule.test(rest));
|
|
156
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import type { SeoRules } from "../interfaces/seo";
|
|
2
|
+
import { localeLanguage } from "./locale";
|
|
3
|
+
import type { LocaleHeadLink, LocaleHeadMeta } from "./productLocales";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The seo service's defaults for a domain nobody configured — the same values
|
|
7
|
+
* its bundle carries then. The storefront falls back to these when the rules
|
|
8
|
+
* cannot be read, so a page never waits on SEO and never renders without it.
|
|
9
|
+
*/
|
|
10
|
+
const DEFAULT_STRIP_PARAMS: readonly string[] = ["utm_*", "gclid", "fbclid", "msclkid", "sort", "order"];
|
|
11
|
+
|
|
12
|
+
export function defaultSeoRules(host: string): SeoRules {
|
|
13
|
+
return {
|
|
14
|
+
schema: 1,
|
|
15
|
+
host,
|
|
16
|
+
site_name: host,
|
|
17
|
+
canonical: { host: null, cross_domain_page_types: ["product", "category"], strip_params: DEFAULT_STRIP_PARAMS },
|
|
18
|
+
hreflang: { x_default: null, locales: null },
|
|
19
|
+
max_length: { title: 60, description: 160 },
|
|
20
|
+
page_types: {
|
|
21
|
+
home: { title: "{site}", description: null, robots: "index,follow" },
|
|
22
|
+
product: { title: "{name} | {site}", description: "{description}", robots: "index,follow" },
|
|
23
|
+
category: { title: "{name} | {site}", description: "{description}", robots: "index,follow" },
|
|
24
|
+
page: { title: "{name} | {site}", description: "{description}", robots: "index,follow" },
|
|
25
|
+
search: { robots: "noindex,follow" },
|
|
26
|
+
cart: { robots: "noindex,nofollow" },
|
|
27
|
+
checkout: { robots: "noindex,nofollow" },
|
|
28
|
+
"checkout-confirmation": { robots: "noindex,nofollow" },
|
|
29
|
+
login: { robots: "noindex,nofollow" },
|
|
30
|
+
register: { robots: "noindex,nofollow" },
|
|
31
|
+
"forgot-password": { robots: "noindex,nofollow" },
|
|
32
|
+
"reset-password": { robots: "noindex,nofollow" },
|
|
33
|
+
account: { robots: "noindex,nofollow" },
|
|
34
|
+
preview: { robots: "noindex,nofollow" },
|
|
35
|
+
},
|
|
36
|
+
organisation: null,
|
|
37
|
+
structured_data: { prices: true },
|
|
38
|
+
removed_products: "category",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Hosts the theme editor and previews render on (`<tenant>.theme.rvnxx.site`).
|
|
44
|
+
* Never indexable, whatever the rules of the tenant's domains say.
|
|
45
|
+
*/
|
|
46
|
+
export function isPreviewHost(host: string): boolean {
|
|
47
|
+
return host.toLowerCase().endsWith(".theme.rvnxx.site");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Whether a query parameter is one the canonical leaves out (`utm_*` matches by prefix). */
|
|
51
|
+
function isStrippedParam(name: string, stripParams: readonly string[]): boolean {
|
|
52
|
+
const lower = name.toLowerCase();
|
|
53
|
+
return stripParams.some(rule => rule.endsWith("*")
|
|
54
|
+
? lower.startsWith(rule.slice(0, -1).toLowerCase())
|
|
55
|
+
: lower === rule.toLowerCase());
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The only query parameters a canonical carries, each with the values it
|
|
60
|
+
* carries them with. Any other parameter (a tracking id the rules do not know,
|
|
61
|
+
* a session id, one made up) would make each URL its own canonical and write
|
|
62
|
+
* foreign values into `canonical` and `og:url`; facets and searches name the
|
|
63
|
+
* clean listing instead. `page` only from 2: page 1 is the listing itself,
|
|
64
|
+
* and `?page=abc` no page at all.
|
|
65
|
+
*/
|
|
66
|
+
const CANONICAL_PARAMS: ReadonlyMap<string, (value: string) => boolean> = new Map([
|
|
67
|
+
["page", value => /^[1-9]\d*$/.test(value) && value !== "1"],
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* `path` (or an href) on `origin`, never on another host: `new URL(path, base)`
|
|
72
|
+
* would read a protocol-relative `//other.example/x` as that host.
|
|
73
|
+
*/
|
|
74
|
+
function onOrigin(path: string, origin: string): URL {
|
|
75
|
+
return path.startsWith("/") ? new URL(`${origin}${path}`) : new URL(path, origin);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The canonical URL of a page: the site's origin (or the main domain for a
|
|
80
|
+
* page type that canonicalises across domains), the path as served, and of
|
|
81
|
+
* the query only `page`, from 2 on, so every page of a listing is its own
|
|
82
|
+
* canonical; `page=1` and a page that is no page number at all name the
|
|
83
|
+
* listing itself. A parameter the rules strip is left out even then.
|
|
84
|
+
*/
|
|
85
|
+
export function seoCanonicalUrl(options: {
|
|
86
|
+
readonly origin: string;
|
|
87
|
+
readonly path: string;
|
|
88
|
+
readonly query: Readonly<Record<string, unknown>>;
|
|
89
|
+
readonly rules: SeoRules;
|
|
90
|
+
readonly pageType?: string;
|
|
91
|
+
}): string {
|
|
92
|
+
const { rules, pageType } = options;
|
|
93
|
+
const crossDomain = rules.canonical.host && pageType && rules.canonical.cross_domain_page_types.includes(pageType);
|
|
94
|
+
const url = onOrigin(options.path, crossDomain ? `https://${rules.canonical.host}` : options.origin);
|
|
95
|
+
const kept = Object.entries(options.query)
|
|
96
|
+
.filter(([name]) => CANONICAL_PARAMS.has(name) && !isStrippedParam(name, rules.canonical.strip_params))
|
|
97
|
+
.sort(([a], [b]) => a.localeCompare(b));
|
|
98
|
+
for (const [name, value] of kept) {
|
|
99
|
+
// One value per parameter: `?page=2&page=3` is not two pages.
|
|
100
|
+
const carried = (Array.isArray(value) ? value : [value])
|
|
101
|
+
.map(item => (item === null || item === undefined ? "" : String(item)))
|
|
102
|
+
.find(item => CANONICAL_PARAMS.get(name)?.(item));
|
|
103
|
+
if (carried !== undefined) {
|
|
104
|
+
url.searchParams.set(name, carried);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return url.href;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* An x-default link from another hreflang link. i18n keys its head links by
|
|
112
|
+
* `id` or, under strict SEO, `key`; whichever the source carries becomes
|
|
113
|
+
* i18n's x-default key, so the copy never replaces the alternate it came from.
|
|
114
|
+
*/
|
|
115
|
+
function xDefaultEntry<L extends LocaleHeadLink>(source: L, href: string): L {
|
|
116
|
+
const entry: L = { ...source, hreflang: "x-default", href };
|
|
117
|
+
for (const attribute of ["id", "key"] as const) {
|
|
118
|
+
if (attribute in entry) {
|
|
119
|
+
(entry as LocaleHeadLink)[attribute] = "i18n-xd";
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return entry;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* `useLocaleHead({ seo: true })` with the domain's rules applied.
|
|
127
|
+
*
|
|
128
|
+
* @nuxtjs/i18n writes every URL without a host (it has no per-request
|
|
129
|
+
* `baseUrl`), and search engines ignore relative hreflang links. So:
|
|
130
|
+
*
|
|
131
|
+
* - alternates become absolute on the request's origin;
|
|
132
|
+
* - with `hreflang.locales` set, only those languages are linked (matched by
|
|
133
|
+
* language subtag, as i18n writes both `de` and `de-DE`);
|
|
134
|
+
* - with `hreflang.x_default` set, `x-default` points at that language's URL,
|
|
135
|
+
* and is dropped when that language is not linked;
|
|
136
|
+
* - the canonical and `og:url` go: the page's canonical follows the rules
|
|
137
|
+
* (seoCanonicalUrl), and nuxt-seo-utils derives `og:url` from it.
|
|
138
|
+
*/
|
|
139
|
+
export function applySeoRulesToLocaleHead<L extends LocaleHeadLink, M extends LocaleHeadMeta>(
|
|
140
|
+
head: { link?: L[]; meta?: M[] },
|
|
141
|
+
options: { readonly origin: string; readonly rules: SeoRules },
|
|
142
|
+
): { link: L[]; meta: M[] } {
|
|
143
|
+
const { locales, x_default: xDefault } = options.rules.hreflang;
|
|
144
|
+
const languages = locales ? new Set(locales.map(localeLanguage)) : null;
|
|
145
|
+
const linked = (code: string): boolean => !languages || languages.has(localeLanguage(code));
|
|
146
|
+
const absolute = (href: string | undefined): string | undefined =>
|
|
147
|
+
href === undefined ? undefined : onOrigin(href, options.origin).href;
|
|
148
|
+
|
|
149
|
+
const alternates = (head.link ?? [])
|
|
150
|
+
.filter(entry => entry.rel === "alternate" && entry.hreflang && entry.hreflang !== "x-default")
|
|
151
|
+
.filter(entry => linked(entry.hreflang as string))
|
|
152
|
+
.map(entry => ({ ...entry, href: absolute(entry.href) }));
|
|
153
|
+
|
|
154
|
+
// i18n's own x-default is gone where the default language has no page
|
|
155
|
+
// (filterLocaleHeadAlternates, PE-859); the rules' x-default then grows out
|
|
156
|
+
// of the alternate it points at, under i18n's x-default identity.
|
|
157
|
+
const defaultLink = (head.link ?? []).find(entry => entry.rel === "alternate" && entry.hreflang === "x-default");
|
|
158
|
+
const xDefaultTarget = xDefault
|
|
159
|
+
? alternates.find(entry => localeLanguage(entry.hreflang as string) === localeLanguage(xDefault))
|
|
160
|
+
: undefined;
|
|
161
|
+
const defaultHref = xDefault ? xDefaultTarget?.href : absolute(defaultLink?.href);
|
|
162
|
+
const keptHrefs = new Set(alternates.map(entry => entry.href));
|
|
163
|
+
const xDefaultBase = defaultLink ?? xDefaultTarget;
|
|
164
|
+
const xDefaultLink = xDefaultBase && defaultHref && keptHrefs.has(defaultHref)
|
|
165
|
+
? [xDefaultEntry(xDefaultBase, defaultHref)]
|
|
166
|
+
: [];
|
|
167
|
+
|
|
168
|
+
const others = (head.link ?? []).filter(entry => entry.rel !== "alternate" && entry.rel !== "canonical");
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
link: [...others, ...xDefaultLink, ...alternates],
|
|
172
|
+
meta: (head.meta ?? []).filter(entry => entry.property !== "og:url"
|
|
173
|
+
&& (entry.property !== "og:locale:alternate" || !entry.content || linked(entry.content))),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The regional hreflang alternates in the region the shop's market speaks
|
|
179
|
+
* each language in: i18n writes its own config's codes (`de-DE`, `en-US`),
|
|
180
|
+
* so a Swiss market gets `de-CH` instead, the same locale `<html lang>`
|
|
181
|
+
* names (PE-1237). `marketLocale` answers the market's locale for a code's
|
|
182
|
+
* language, or null while the markets carry none; the i18n code then stands.
|
|
183
|
+
* The bare language alternates (`de`) and `x-default` stay as they are, and
|
|
184
|
+
* an alternate whose new code is already linked goes.
|
|
185
|
+
*/
|
|
186
|
+
export function marketHreflangAlternates<L extends LocaleHeadLink>(
|
|
187
|
+
links: readonly L[],
|
|
188
|
+
marketLocale: (code: string) => string | null,
|
|
189
|
+
): L[] {
|
|
190
|
+
const linked = new Set<string>();
|
|
191
|
+
return links
|
|
192
|
+
.map((entry) => {
|
|
193
|
+
const code = entry.rel === "alternate" ? entry.hreflang : undefined;
|
|
194
|
+
if (!code || code === "x-default" || !code.includes("-")) {
|
|
195
|
+
return entry;
|
|
196
|
+
}
|
|
197
|
+
const market = marketLocale(code);
|
|
198
|
+
return market ? { ...entry, hreflang: market } : entry;
|
|
199
|
+
})
|
|
200
|
+
.filter((entry) => {
|
|
201
|
+
if (entry.rel !== "alternate" || !entry.hreflang) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
const code = entry.hreflang.toLowerCase();
|
|
205
|
+
if (linked.has(code)) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
linked.add(code);
|
|
209
|
+
return true;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** What a page's title and description patterns are filled from. */
|
|
214
|
+
export interface SeoPatternValues {
|
|
215
|
+
readonly name?: string;
|
|
216
|
+
readonly category?: string;
|
|
217
|
+
readonly brand?: string;
|
|
218
|
+
readonly parent?: string;
|
|
219
|
+
readonly description?: string;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* A title or description pattern of the rules (`{name} | {site}`) filled in
|
|
224
|
+
* and cut at its maximum length. A placeholder without a value is left empty
|
|
225
|
+
* and a separator left dangling at either end goes with it; the service
|
|
226
|
+
* refuses unknown placeholders, so none reach here.
|
|
227
|
+
*/
|
|
228
|
+
export function fillSeoPattern(pattern: string, values: SeoPatternValues & { readonly site: string }, maxLength: number): string {
|
|
229
|
+
const filled = pattern
|
|
230
|
+
.replace(/\{(\w+)\}/g, (_, key: string) => (values as Record<string, string | undefined>)[key]?.trim() ?? "")
|
|
231
|
+
.replace(/^\s*[|–—-]\s*|\s*[|–—-]\s*$/g, "")
|
|
232
|
+
.replace(/\s{2,}/g, " ")
|
|
233
|
+
.trim();
|
|
234
|
+
return filled.length > maxLength ? `${filled.slice(0, maxLength - 1).trimEnd()}…` : filled;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* A page's title from its type's pattern, or undefined where the page's own
|
|
239
|
+
* title stands instead: the type has no pattern, the subject the pattern names
|
|
240
|
+
* (`{name}`) is not known yet, or the pattern is the bare `{site}` (the home
|
|
241
|
+
* page's default) and the page brings a title of its own — the shop's curated
|
|
242
|
+
* home title, or the one the home page's author stored. A pattern a tenant
|
|
243
|
+
* wrote for the home page (`{site} – Werkzeug online`) is used as written.
|
|
244
|
+
*/
|
|
245
|
+
export function seoPatternTitle(
|
|
246
|
+
pattern: string | undefined,
|
|
247
|
+
values: SeoPatternValues & { readonly site: string },
|
|
248
|
+
maxLength: number,
|
|
249
|
+
ownTitle?: string,
|
|
250
|
+
): string | undefined {
|
|
251
|
+
const ownTitleStands = pattern?.includes("{name}")
|
|
252
|
+
? !values.name
|
|
253
|
+
: pattern?.trim() === "{site}" && Boolean(ownTitle);
|
|
254
|
+
if (!pattern || ownTitleStands) {
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
257
|
+
return fillSeoPattern(pattern, values, maxLength) || undefined;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** The directives of a robots rule, lower-cased, with `none` and `all` spelled out. */
|
|
261
|
+
function robotsDirectives(rule: string): string[] {
|
|
262
|
+
return rule.split(",").map(d => d.trim().toLowerCase()).filter(Boolean)
|
|
263
|
+
.flatMap(d => (d === "none" ? ["noindex", "nofollow"] : d === "all" ? ["index", "follow"] : [d]));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Whether a robots rule lets the page into the index. */
|
|
267
|
+
export function isIndexableRobotsRule(rule: string): boolean {
|
|
268
|
+
return !robotsDirectives(rule).includes("noindex");
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* The robots directive for a page: its type's rule from the rules, turned to
|
|
273
|
+
* `noindex` when this URL must not be indexed although its type may be (a
|
|
274
|
+
* filtered listing, an empty category, a missing product), and to `nofollow`
|
|
275
|
+
* when its links must not be followed either (a preview). Any other directive
|
|
276
|
+
* of the rule (`noarchive`, `max-image-preview:large`, …) is kept.
|
|
277
|
+
*/
|
|
278
|
+
export function seoRobotsRule(typeRule: string, flags: { readonly noindex?: boolean; readonly nofollow?: boolean } = {}): string {
|
|
279
|
+
const directives = robotsDirectives(typeRule);
|
|
280
|
+
const index = flags.noindex || directives.includes("noindex") ? "noindex" : "index";
|
|
281
|
+
const follow = flags.nofollow || directives.includes("nofollow") ? "nofollow" : "follow";
|
|
282
|
+
const others = directives.filter(d => !["index", "noindex", "follow", "nofollow"].includes(d));
|
|
283
|
+
return [index, follow, ...others].join(", ");
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Whether a listing URL is filtered, searched within or priced — anything the
|
|
288
|
+
* clean listing is not, apart from paging and the parameters the canonical
|
|
289
|
+
* strips anyway. Such a URL is a near-duplicate of its listing and stays out
|
|
290
|
+
* of the index until filter pages can be released (phase 3).
|
|
291
|
+
*/
|
|
292
|
+
export function hasListingFilters(query: Readonly<Record<string, unknown>>, rules: SeoRules): boolean {
|
|
293
|
+
return Object.entries(query).some(([name, value]) =>
|
|
294
|
+
value !== undefined && value !== null && value !== ""
|
|
295
|
+
&& name !== "page"
|
|
296
|
+
&& !isStrippedParam(name, rules.canonical.strip_params));
|
|
297
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { Offer } from "../composables/useOffers";
|
|
2
|
+
import { getBaseUnitPrice, getPriceWithOptionalTax } from "../composables/useProducts";
|
|
3
|
+
import type { ProductDetailAttribute } from "../interfaces/product-detail";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The parts of a product's Schema.org data that follow shop rules rather than
|
|
7
|
+
* the catalogue (PE-1103). Pure, so the rules are tested without a page.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** What a guest's offer says: the tier map and whether the item can be ordered. */
|
|
11
|
+
export type GuestOfferInput = Readonly<Pick<Offer, "prices" | "isOutOfStock">>;
|
|
12
|
+
|
|
13
|
+
// A type, not an interface: nuxt-schema-org's Offer has an index signature,
|
|
14
|
+
// which only a type literal satisfies.
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
16
|
+
export type StructuredOffer = {
|
|
17
|
+
price: string;
|
|
18
|
+
priceCurrency: string;
|
|
19
|
+
availability: "InStock" | "OutOfStock";
|
|
20
|
+
priceSpecification: {
|
|
21
|
+
"@type": "UnitPriceSpecification";
|
|
22
|
+
"price": string;
|
|
23
|
+
"priceCurrency": string;
|
|
24
|
+
"valueAddedTaxIncluded": boolean;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The `offers` of a product, or undefined for none (K4, PE-1047): a price only
|
|
30
|
+
* from the guest's offer, net or gross as the page shows it, in the currency it
|
|
31
|
+
* shows. No price (on request, refused to strangers, too slow) or the domain's
|
|
32
|
+
* opt-out gives no offer at all, never an offer without a price.
|
|
33
|
+
*/
|
|
34
|
+
export function structuredOffer(input: {
|
|
35
|
+
readonly offer: GuestOfferInput | null | undefined;
|
|
36
|
+
/** The domain's rules allow prices in the structured data (`structured_data.prices`). */
|
|
37
|
+
readonly pricesAllowed: boolean;
|
|
38
|
+
readonly currency: string;
|
|
39
|
+
readonly taxRate: number;
|
|
40
|
+
readonly taxIncludedPrices: boolean;
|
|
41
|
+
}): StructuredOffer | undefined {
|
|
42
|
+
if (!input.pricesAllowed || !input.offer || !input.currency) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
// The price of one unit at the smallest quantity, as the product page shows it.
|
|
46
|
+
const unitPrice = getBaseUnitPrice([...input.offer.prices]);
|
|
47
|
+
if (unitPrice === null || unitPrice <= 0) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const price = getPriceWithOptionalTax(unitPrice, input.taxRate, input.taxIncludedPrices).toFixed(2);
|
|
51
|
+
return {
|
|
52
|
+
price,
|
|
53
|
+
priceCurrency: input.currency,
|
|
54
|
+
availability: input.offer.isOutOfStock ? "OutOfStock" : "InStock",
|
|
55
|
+
priceSpecification: {
|
|
56
|
+
"@type": "UnitPriceSpecification",
|
|
57
|
+
"price": price,
|
|
58
|
+
"priceCurrency": input.currency,
|
|
59
|
+
"valueAddedTaxIncluded": input.taxIncludedPrices,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The product's specifications as Schema.org `additionalProperty`, empty ones left out. */
|
|
65
|
+
export function structuredProperties(attributes: readonly ProductDetailAttribute[]): { "@type": "PropertyValue"; name: string; value: string }[] {
|
|
66
|
+
return attributes
|
|
67
|
+
.filter(attribute => attribute.name?.trim() && attribute.value?.trim())
|
|
68
|
+
.map(attribute => ({ "@type": "PropertyValue", "name": attribute.name.trim(), "value": attribute.value.trim() }));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** One entry of an accordion: its label and its HTML content. */
|
|
72
|
+
export interface FaqItemInput {
|
|
73
|
+
readonly label?: unknown;
|
|
74
|
+
readonly content?: unknown;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The questions of an accordion marked as FAQ (PE-1327), for `defineQuestion`:
|
|
79
|
+
* the label as the question, the content as the answer. Google reads a small
|
|
80
|
+
* set of HTML tags in an answer (`p`, `a`, lists, emphasis), so the content
|
|
81
|
+
* stays as authored. An entry without a question or without answer text (an
|
|
82
|
+
* empty paragraph counts as none) is left out.
|
|
83
|
+
*/
|
|
84
|
+
export function faqQuestions(items: readonly FaqItemInput[]): { name: string; acceptedAnswer: string }[] {
|
|
85
|
+
return items.flatMap((item) => {
|
|
86
|
+
const name = typeof item.label === "string" ? item.label.trim() : "";
|
|
87
|
+
const answer = typeof item.content === "string" ? item.content.trim() : "";
|
|
88
|
+
return name && plainText(answer) ? [{ name, acceptedAnswer: answer }] : [];
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Authored HTML as plain text, for meta tags and for telling an empty answer
|
|
94
|
+
* from a real one: tags become spaces, so do non-breaking spaces however the
|
|
95
|
+
* editor wrote them (` `, ` `, ` `, the character itself), and
|
|
96
|
+
* whitespace collapses.
|
|
97
|
+
*/
|
|
98
|
+
export function plainText(html: string): string {
|
|
99
|
+
return html
|
|
100
|
+
.replace(/<[^>]*>/g, " ")
|
|
101
|
+
.replace(/&(?:nbsp|#160|#x0*a0);/gi, " ")
|
|
102
|
+
.replace(/\s+/g, " ")
|
|
103
|
+
.trim();
|
|
104
|
+
}
|
|
@@ -537,6 +537,10 @@
|
|
|
537
537
|
"title": "Keine Bestelllisten",
|
|
538
538
|
"description": "Legen Sie Ihre erste Bestellliste über „Hinzufügen“ an."
|
|
539
539
|
},
|
|
540
|
+
"noPositions": {
|
|
541
|
+
"title": "Noch keine Positionen",
|
|
542
|
+
"description": "Artikel kommen von der Produktseite oder aus dem Warenkorb auf diese Liste — über „Auf Bestellliste“."
|
|
543
|
+
},
|
|
540
544
|
"saveTo": {
|
|
541
545
|
"button": "Auf Bestellliste",
|
|
542
546
|
"onLists": "Auf {count} Liste | Auf {count} Listen",
|