@revenexx/cover 0.22.0 → 0.22.1
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 +7 -2
- 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/layout/header/LocaleSwitcher.vue +7 -9
- 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/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/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/seo.ts +48 -0
- package/app/layouts/default.vue +2 -8
- package/app/layouts/focus.vue +3 -1
- package/app/payments/psp/novalnet.ts +25 -3
- package/app/payments/psp/novalnetStyle.ts +186 -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/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/en/account.json +4 -0
- package/i18n/locales/en/common.json +6 -0
- package/i18n/locales/en/pages.json +109 -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 +1 -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/middleware/missing-media.ts +2 -2
- package/server/plugins/previewHostNoindex.ts +21 -0
- package/server/plugins/seoSiteConfig.ts +62 -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/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
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { MaybeRefOrGetter } from "vue";
|
|
2
|
+
|
|
3
|
+
import { offersApi } from "../api/offers";
|
|
4
|
+
import type { GuestOfferInput } from "../shared/structuredData";
|
|
5
|
+
import { plainText, structuredOffer, structuredProperties } from "../shared/structuredData";
|
|
6
|
+
import type { useProductDetail } from "./useProduct";
|
|
7
|
+
|
|
8
|
+
/** What useProductSeo reads of a product page's useProductDetail(). */
|
|
9
|
+
type ProductSeoDetail = Pick<ReturnType<typeof useProductDetail>,
|
|
10
|
+
"productInfo" | "productCategories" | "categorySlug" | "subcategorySlug" | "longDescription"
|
|
11
|
+
| "mainImages" | "getDetailImageUrl" | "attributes" | "taxRate">;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The product page's SEO from the domain's rules (PE-1235), for every page
|
|
15
|
+
* that renders a product: the blökkli theme's template page, the layer's
|
|
16
|
+
* ProductDetailView and the demo shop's own copy.
|
|
17
|
+
*
|
|
18
|
+
* Three URL shapes reach the same product — the real category path, a
|
|
19
|
+
* shallower one and the `_` placeholder — so the canonical names the real one,
|
|
20
|
+
* on the main domain when the rules canonicalise products there. The first
|
|
21
|
+
* main picture is the link preview's image (PE-1237).
|
|
22
|
+
*
|
|
23
|
+
* Its structured data (PE-1103) is a `Product` with a `BreadcrumbList`. The
|
|
24
|
+
* price in it is the guest's (K4), asked for during the render: the offer the
|
|
25
|
+
* page shows is the buyer's, loaded only in the browser.
|
|
26
|
+
*/
|
|
27
|
+
export function useProductSeo(product: ProductSeoDetail, flags: {
|
|
28
|
+
/**
|
|
29
|
+
* Nothing to describe: a malformed URL, a finished fetch that found
|
|
30
|
+
* nothing, or a URL useProductAnswer() answered for itself (a 301).
|
|
31
|
+
*/
|
|
32
|
+
readonly notFound: MaybeRefOrGetter<boolean>;
|
|
33
|
+
/** A preview or anything else that must not be indexed. */
|
|
34
|
+
readonly noindex?: MaybeRefOrGetter<boolean>;
|
|
35
|
+
/** A preview, whose links must not be followed either. */
|
|
36
|
+
readonly nofollow?: MaybeRefOrGetter<boolean>;
|
|
37
|
+
}): void {
|
|
38
|
+
const localePath = useLocalePath();
|
|
39
|
+
|
|
40
|
+
const canonicalPath = computed(() => {
|
|
41
|
+
const info = product.productInfo.value;
|
|
42
|
+
return info
|
|
43
|
+
? localePath(categoryProductPath(
|
|
44
|
+
[product.categorySlug.value, product.subcategorySlug.value],
|
|
45
|
+
{ id: info.id, name: info.name },
|
|
46
|
+
))
|
|
47
|
+
: undefined;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const mainCategory = computed(() => product.productCategories.value.find(c => c.type === "main")?.name);
|
|
51
|
+
const subcategory = computed(() => product.productCategories.value.find(c => c.type === "subcategory")?.name);
|
|
52
|
+
/** The product's own category, deepest first, for the title pattern's `{category}`. */
|
|
53
|
+
const category = computed(() => subcategory.value ?? mainCategory.value);
|
|
54
|
+
|
|
55
|
+
/** The first main picture as a src: the link preview's image and the structured data's. */
|
|
56
|
+
const image = computed(() => {
|
|
57
|
+
const first = product.mainImages.value[0];
|
|
58
|
+
return first ? product.getDetailImageUrl(first.url) : undefined;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/** The long description is stored as HTML; meta tags need plain text. */
|
|
62
|
+
const description = computed(() => {
|
|
63
|
+
const html = product.longDescription.value;
|
|
64
|
+
return html ? plainText(html) || undefined : undefined;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
useSeoContext({
|
|
68
|
+
type: "product",
|
|
69
|
+
values: () => ({
|
|
70
|
+
name: product.productInfo.value?.name,
|
|
71
|
+
brand: product.productInfo.value?.manufacturer || undefined,
|
|
72
|
+
category: category.value,
|
|
73
|
+
description: description.value,
|
|
74
|
+
}),
|
|
75
|
+
title: () => product.productInfo.value?.name,
|
|
76
|
+
noindex: () => toValue(flags.notFound) || Boolean(toValue(flags.noindex)),
|
|
77
|
+
nofollow: flags.nofollow,
|
|
78
|
+
canonicalPath,
|
|
79
|
+
image: () => image.value,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (toValue(flags.notFound)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const { t } = useI18n();
|
|
87
|
+
const rules = useSeoRules();
|
|
88
|
+
const { taxIncludedPrices } = useShopSettings();
|
|
89
|
+
const currency = useDisplayCurrency();
|
|
90
|
+
const pricesAllowed = rules.value.structured_data.prices;
|
|
91
|
+
|
|
92
|
+
// The guest's offer, within the server's time budget (api/offers/guest).
|
|
93
|
+
// Not asked for at all under the domain's opt-out, and only while
|
|
94
|
+
// rendering on the server: crawlers read the server's HTML, and the
|
|
95
|
+
// browser has no use for the structured data, so an in-app navigation does
|
|
96
|
+
// not ask again. Keyed by product, so hydration reads the server's answer
|
|
97
|
+
// from the payload.
|
|
98
|
+
const info = product.productInfo.value;
|
|
99
|
+
const { data: guest } = useFetch<{ offer: GuestOfferInput | null }>(offersApi.guest(), {
|
|
100
|
+
key: `offer-guest:${info?.id ?? ""}`,
|
|
101
|
+
query: { id: info?.id, ...(info?.sku ? { sku: info.sku } : {}) },
|
|
102
|
+
immediate: import.meta.server && pricesAllowed && Boolean(info?.id),
|
|
103
|
+
default: () => ({ offer: null }),
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const offers = computed(() => structuredOffer({
|
|
107
|
+
offer: guest.value?.offer,
|
|
108
|
+
pricesAllowed,
|
|
109
|
+
currency: currency.value,
|
|
110
|
+
taxRate: product.taxRate.value,
|
|
111
|
+
taxIncludedPrices: taxIncludedPrices.value,
|
|
112
|
+
}));
|
|
113
|
+
|
|
114
|
+
useSchemaOrg([
|
|
115
|
+
defineProduct(computed(() => {
|
|
116
|
+
const current = product.productInfo.value;
|
|
117
|
+
const brand = current?.manufacturer;
|
|
118
|
+
return {
|
|
119
|
+
name: current?.name ?? "",
|
|
120
|
+
sku: current?.sku || undefined,
|
|
121
|
+
brand: brand ? { "@type": "Brand" as const, "name": brand } : undefined,
|
|
122
|
+
description: description.value,
|
|
123
|
+
// The module drops empty strings, so a product without a picture has no `image`.
|
|
124
|
+
image: image.value ?? "",
|
|
125
|
+
additionalProperty: structuredProperties(product.attributes.value),
|
|
126
|
+
offers: offers.value,
|
|
127
|
+
};
|
|
128
|
+
})),
|
|
129
|
+
defineBreadcrumb(computed(() => {
|
|
130
|
+
const categoryPath = `/category/${product.categorySlug.value}`;
|
|
131
|
+
return {
|
|
132
|
+
itemListElement: [
|
|
133
|
+
{ name: t("nav.home"), item: localePath("/") },
|
|
134
|
+
...(mainCategory.value && product.categorySlug.value
|
|
135
|
+
? [{ name: mainCategory.value, item: localePath(categoryPath) }]
|
|
136
|
+
: []),
|
|
137
|
+
...(subcategory.value && product.categorySlug.value && product.subcategorySlug.value
|
|
138
|
+
? [{ name: subcategory.value, item: localePath(`${categoryPath}/${product.subcategorySlug.value}`) }]
|
|
139
|
+
: []),
|
|
140
|
+
{ name: product.productInfo.value?.name ?? "", item: canonicalPath.value },
|
|
141
|
+
],
|
|
142
|
+
};
|
|
143
|
+
})),
|
|
144
|
+
]);
|
|
145
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { productRouteCategorySegments } from "../shared/productLocales";
|
|
1
2
|
import { parseProductIdFromSlug } from "./useProducts";
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -29,14 +30,33 @@ export function productSlugFromSegments(segments: string[]): string {
|
|
|
29
30
|
return marker >= 0 ? (segments[marker + 1] ?? "") : "";
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* The part of a product URL behind `category/[category]`, as `[...rest]` holds
|
|
35
|
+
* it. The demo shop serves two-level product URLs from its own
|
|
36
|
+
* `[category]/[subcategory]/product/[slug]` route, which spells the same tail
|
|
37
|
+
* in two params; off a category URL there is no tail.
|
|
38
|
+
*/
|
|
39
|
+
export function productRouteTail(params: Record<string, unknown>): string[] {
|
|
40
|
+
const rest = routeSegments(params.rest);
|
|
41
|
+
const slug = routeSegments(params.slug);
|
|
42
|
+
if (rest.length || !slug.length || !routeSegments(params.category).length) {
|
|
43
|
+
return rest;
|
|
44
|
+
}
|
|
45
|
+
return [...routeSegments(params.subcategory), "product", ...slug];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The product a `category/[category]/[...rest]` URL (or the demo shop's own route) points at. */
|
|
33
49
|
export function useRouteProductSubject() {
|
|
34
50
|
const route = useRoute();
|
|
35
51
|
|
|
36
|
-
const
|
|
52
|
+
const tail = computed(() => productRouteTail(route.params));
|
|
53
|
+
const slug = computed(() => productSlugFromSegments(tail.value));
|
|
37
54
|
const id = computed(() => parseProductIdFromSlug(slug.value));
|
|
55
|
+
/** The category path the URL names in front of `product` (display only; the product knows its own). */
|
|
56
|
+
const categorySegments = computed(() =>
|
|
57
|
+
productRouteCategorySegments(routeSegments(route.params.category), tail.value));
|
|
38
58
|
|
|
39
|
-
return { slug, id };
|
|
59
|
+
return { slug, id, categorySegments };
|
|
40
60
|
}
|
|
41
61
|
|
|
42
62
|
/** The category (and optional subcategory) a `category/[category]/[[subcategory]]` URL points at. */
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { MaybeRefOrGetter } from "vue";
|
|
2
|
+
|
|
3
|
+
import type { SeoPatternValues } from "../shared/seoRules";
|
|
4
|
+
import { defaultSeoRules, fillSeoPattern, isIndexableRobotsRule, seoPatternTitle, seoRobotsRule } from "../shared/seoRules";
|
|
5
|
+
import type { SeoPageCanonical } from "./useSeoHead";
|
|
6
|
+
import { useSeoPageCanonical } from "./useSeoHead";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* What a page tells the SEO layer about itself (PE-1235).
|
|
10
|
+
*
|
|
11
|
+
* `type` is a page type of the domain's rules: `home`, `product`, `category`,
|
|
12
|
+
* `page` (a CMS page) are indexed and carry title and description patterns;
|
|
13
|
+
* `search`, `cart`, `checkout`, `checkout-confirmation`, `login`, `register`,
|
|
14
|
+
* `forgot-password`, `reset-password`, `account` and `preview` are fixed.
|
|
15
|
+
*/
|
|
16
|
+
export interface SeoContextOptions {
|
|
17
|
+
readonly type: MaybeRefOrGetter<string>;
|
|
18
|
+
/** What the type's patterns are filled from. */
|
|
19
|
+
readonly values?: MaybeRefOrGetter<SeoPatternValues>;
|
|
20
|
+
/**
|
|
21
|
+
* The page's own title, for a type without a pattern, a subject without a
|
|
22
|
+
* name, or a pattern with no place for one (the home page's `{site}`).
|
|
23
|
+
*/
|
|
24
|
+
readonly title?: MaybeRefOrGetter<string | undefined>;
|
|
25
|
+
/** The page's own description, for a type without a description pattern (a home page). */
|
|
26
|
+
readonly description?: MaybeRefOrGetter<string | undefined>;
|
|
27
|
+
/** This URL must not be indexed although its type may be: a preview, a filter, nothing found. */
|
|
28
|
+
readonly noindex?: MaybeRefOrGetter<boolean>;
|
|
29
|
+
/** Nor may its links be followed: a preview. */
|
|
30
|
+
readonly nofollow?: MaybeRefOrGetter<boolean>;
|
|
31
|
+
/** The path that names the subject canonically, when the URL served can differ from it. */
|
|
32
|
+
readonly canonicalPath?: MaybeRefOrGetter<string | undefined>;
|
|
33
|
+
/** The subject's own picture for link previews (a product photo): a src, made absolute here. */
|
|
34
|
+
readonly image?: MaybeRefOrGetter<string | undefined>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The label a generated link preview card carries per page type. The home
|
|
39
|
+
* page and CMS pages carry none ("Page" says nothing), so they share a card.
|
|
40
|
+
*/
|
|
41
|
+
const OG_IMAGE_LABELS: Readonly<Record<string, string>> = {
|
|
42
|
+
home: "",
|
|
43
|
+
page: "",
|
|
44
|
+
product: "seo.ogImage.product",
|
|
45
|
+
category: "seo.ogImage.category",
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Title, description, robots and canonical of a page, from the domain's rules.
|
|
50
|
+
*
|
|
51
|
+
* Reactive throughout, so a page may call it before its data has arrived: the
|
|
52
|
+
* head is resolved when the render ends, and the `X-Robots-Tag` header is set
|
|
53
|
+
* then too, from the same rule as the meta tag. On a host that is not
|
|
54
|
+
* indexable (a preview, a dev server) the robots module's site-wide
|
|
55
|
+
* `noindex` stands and nothing here overrides it.
|
|
56
|
+
*
|
|
57
|
+
* A type the rules lack falls back to the service's defaults for it. A type
|
|
58
|
+
* the rules never index (cart, checkout, login, …) gets no canonical from the
|
|
59
|
+
* rules, only the module's fallback (the path and `page`): its URLs carry
|
|
60
|
+
* secrets and order ids, and nothing is to be consolidated. The canonical is
|
|
61
|
+
* set by the layout's useSeoHead() from what this hands it, so a page has one
|
|
62
|
+
* canonical whatever its layout. When the page
|
|
63
|
+
* ends in an error (a 404 thrown after this was called), robots and canonical
|
|
64
|
+
* are left to the error page.
|
|
65
|
+
*/
|
|
66
|
+
export function useSeoContext(options: SeoContextOptions): void {
|
|
67
|
+
const rules = useSeoRules();
|
|
68
|
+
const siteConfig = useSiteConfig();
|
|
69
|
+
const error = useError();
|
|
70
|
+
const pageCanonical = useSeoPageCanonical();
|
|
71
|
+
|
|
72
|
+
const type = computed(() => toValue(options.type));
|
|
73
|
+
const typeRules = computed(() => rules.value.page_types[type.value]
|
|
74
|
+
?? defaultSeoRules(rules.value.host).page_types[type.value]);
|
|
75
|
+
const patternValues = computed(() => ({ ...toValue(options.values), site: rules.value.site_name }));
|
|
76
|
+
|
|
77
|
+
const ownTitle = computed(() => toValue(options.title));
|
|
78
|
+
const patternTitle = computed(() =>
|
|
79
|
+
seoPatternTitle(typeRules.value?.title, patternValues.value, rules.value.max_length.title, ownTitle.value));
|
|
80
|
+
const title = computed(() => patternTitle.value ?? ownTitle.value);
|
|
81
|
+
|
|
82
|
+
const description = computed(() => {
|
|
83
|
+
const pattern = typeRules.value?.description;
|
|
84
|
+
return (pattern ? fillSeoPattern(pattern, patternValues.value, rules.value.max_length.description) : toValue(options.description))
|
|
85
|
+
|| undefined;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const siteIndexable = computed(() => siteConfig.indexable !== undefined
|
|
89
|
+
? String(siteConfig.indexable) === "true"
|
|
90
|
+
: siteConfig.env === "production");
|
|
91
|
+
const typeRule = computed(() => typeRules.value?.robots ?? "index,follow");
|
|
92
|
+
const robots = computed(() => (siteIndexable.value && !error.value
|
|
93
|
+
? seoRobotsRule(typeRule.value, {
|
|
94
|
+
noindex: Boolean(toValue(options.noindex)),
|
|
95
|
+
nofollow: Boolean(toValue(options.nofollow)),
|
|
96
|
+
})
|
|
97
|
+
: undefined));
|
|
98
|
+
|
|
99
|
+
const canonical: SeoPageCanonical = {
|
|
100
|
+
indexable: () => isIndexableRobotsRule(typeRule.value),
|
|
101
|
+
pageType: () => type.value,
|
|
102
|
+
path: () => toValue(options.canonicalPath),
|
|
103
|
+
};
|
|
104
|
+
pageCanonical.value = canonical;
|
|
105
|
+
// Leaving, a page takes back only its own: on a client navigation the next
|
|
106
|
+
// page may have set its own already, in either order.
|
|
107
|
+
if (getCurrentScope()) {
|
|
108
|
+
onScopeDispose(() => {
|
|
109
|
+
if (pageCanonical.value === canonical) {
|
|
110
|
+
pageCanonical.value = null;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// A pattern carries the site name itself (`{site}`), so nuxt-seo-utils'
|
|
116
|
+
// `%s %separator %siteName` must not add it a second time. A page's own
|
|
117
|
+
// title gets that template spelled out: a template that resolves to
|
|
118
|
+
// undefined renders no title at all.
|
|
119
|
+
useHead({
|
|
120
|
+
title: () => title.value,
|
|
121
|
+
titleTemplate: () => (patternTitle.value ? "%s" : "%s %separator %siteName"),
|
|
122
|
+
meta: () => (robots.value ? [{ name: "robots", content: robots.value }] : []),
|
|
123
|
+
});
|
|
124
|
+
useSeoMeta({
|
|
125
|
+
description: () => description.value,
|
|
126
|
+
ogTitle: () => title.value,
|
|
127
|
+
ogDescription: () => description.value,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Link previews (PE-1237): the subject's own picture where it has one, else
|
|
131
|
+
// a card generated for the page type and the site. The module puts the page
|
|
132
|
+
// path into every image URL, but the card shows only its props, so they are
|
|
133
|
+
// its cache key too: one render per type and site, shared by all its pages
|
|
134
|
+
// (and by any other tenant whose card would read the same). Photo or card
|
|
135
|
+
// is decided at setup, when a page has its data (product pages await it
|
|
136
|
+
// first); the photo itself follows the data. Only an indexed page gets a
|
|
137
|
+
// card: a missing product, a noindex URL, a preview host or a dev server
|
|
138
|
+
// would only make `/_og/` render one nobody shares.
|
|
139
|
+
const requestUrl = useRequestURL();
|
|
140
|
+
const origin = computed(() => new URL(siteConfig.url || requestUrl.origin).origin);
|
|
141
|
+
const image = computed(() => toValue(options.image));
|
|
142
|
+
const label = OG_IMAGE_LABELS[type.value];
|
|
143
|
+
const indexed = Boolean(robots.value && isIndexableRobotsRule(robots.value));
|
|
144
|
+
if (image.value) {
|
|
145
|
+
useSeoMeta({
|
|
146
|
+
ogImage: () => (image.value ? new URL(image.value, origin.value).href : undefined),
|
|
147
|
+
twitterCard: "summary_large_image",
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
else if (label !== undefined && indexed && useOgImageReady().value) {
|
|
151
|
+
const { t } = useI18n();
|
|
152
|
+
const props = { site: rules.value.site_name, label: label ? t(label) : "" };
|
|
153
|
+
defineOgImage("CoverPage", props, { cacheKey: JSON.stringify(["CoverPage", props.site, props.label]) });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (import.meta.server) {
|
|
157
|
+
const header = useResponseHeader("X-Robots-Tag");
|
|
158
|
+
useNuxtApp().hooks.hook("app:rendered", () => {
|
|
159
|
+
if (robots.value) {
|
|
160
|
+
header.value = robots.value;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type { Ref, ShallowRef } from "vue";
|
|
2
|
+
|
|
3
|
+
import { CONTENT_LOCALE_COOKIE, localeLanguage, pickMarketLocale } from "../shared/locale";
|
|
4
|
+
import { filterLocaleHeadAlternates, localizeLocaleHeadAlternates } from "../shared/productLocales";
|
|
5
|
+
import { applySeoRulesToLocaleHead, marketHreflangAlternates, seoCanonicalUrl } from "../shared/seoRules";
|
|
6
|
+
|
|
7
|
+
/** What a page's useSeoContext() tells the layout about its canonical. */
|
|
8
|
+
export interface SeoPageCanonical {
|
|
9
|
+
/** False for a type the rules never index: no canonical at all. */
|
|
10
|
+
readonly indexable: () => boolean;
|
|
11
|
+
/** The page type, for the rules' canonical on the main domain. */
|
|
12
|
+
readonly pageType: () => string;
|
|
13
|
+
/** The path that names the subject; undefined for the URL served. */
|
|
14
|
+
readonly path: () => string | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The canonical of the page being shown, as its useSeoContext() states it;
|
|
19
|
+
* null for a page that says nothing about itself. One per app (per request on
|
|
20
|
+
* the server); not shared state, as it holds getters a payload cannot carry.
|
|
21
|
+
*/
|
|
22
|
+
export function useSeoPageCanonical(): ShallowRef<SeoPageCanonical | null> {
|
|
23
|
+
const host = useNuxtApp() as unknown as { _coverSeoPageCanonical?: ShallowRef<SeoPageCanonical | null> };
|
|
24
|
+
host._coverSeoPageCanonical ??= shallowRef(null);
|
|
25
|
+
return host._coverSeoPageCanonical;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The document head a layout renders: html `lang`/`dir`, absolute hreflang
|
|
30
|
+
* alternates and `og:locale`, under the domain's SEO rules (PE-1235). It is
|
|
31
|
+
* also the one place the canonical is set: from the page's useSeoContext()
|
|
32
|
+
* where it has one (its subject's path, its type's rules, none for a type
|
|
33
|
+
* never indexed), from the URL served and the rules otherwise.
|
|
34
|
+
*
|
|
35
|
+
* `lang` and `og:locale` name the market locale the page's catalogue is read
|
|
36
|
+
* in (PE-1237) — `de-CH` in a Swiss market, where the i18n language alone
|
|
37
|
+
* would say `de-DE` — picked as the BFF picks it for search; the regional
|
|
38
|
+
* hreflang alternates name each language's market locale the same way. A crawler sends
|
|
39
|
+
* no cookies, so it gets the default market's locale for the page language.
|
|
40
|
+
*
|
|
41
|
+
* `productLocales` narrows the alternates to the languages a product has a
|
|
42
|
+
* page in (PE-859); null leaves every language.
|
|
43
|
+
*
|
|
44
|
+
* `localizePath` puts each alternate into its language's product slug
|
|
45
|
+
* (useProductLocales), so hreflang never points at an outdated-slug 301.
|
|
46
|
+
*
|
|
47
|
+
* `canonical: false` leaves the URL's canonical out for pages that say nothing
|
|
48
|
+
* about themselves, for layouts whose pages are never indexed and whose URLs
|
|
49
|
+
* carry one-time secrets or order ids (login links, password resets, the
|
|
50
|
+
* checkout): nothing there is to be consolidated. The module's fallback (the
|
|
51
|
+
* path and `page` only) stands there.
|
|
52
|
+
*/
|
|
53
|
+
export function useSeoHead(
|
|
54
|
+
productLocales?: Ref<readonly string[] | null>,
|
|
55
|
+
options: {
|
|
56
|
+
readonly canonical?: boolean;
|
|
57
|
+
readonly localizePath?: (path: string, code: string) => string;
|
|
58
|
+
} = {},
|
|
59
|
+
) {
|
|
60
|
+
const localeHead = useLocaleHead({ seo: true });
|
|
61
|
+
const lang = useMarketLanguageTag();
|
|
62
|
+
const rules = useSeoRules();
|
|
63
|
+
const siteConfig = useSiteConfig();
|
|
64
|
+
const requestUrl = useRequestURL();
|
|
65
|
+
const route = useRoute();
|
|
66
|
+
const error = useError();
|
|
67
|
+
const page = useSeoPageCanonical();
|
|
68
|
+
const withCanonical = options.canonical !== false;
|
|
69
|
+
const i18nConfig = useRuntimeConfig().public as { i18n?: { defaultLocale?: string } };
|
|
70
|
+
const defaultLocale = i18nConfig.i18n?.defaultLocale ?? "";
|
|
71
|
+
|
|
72
|
+
const origin = computed(() => new URL(siteConfig.url || requestUrl.origin).origin);
|
|
73
|
+
|
|
74
|
+
// nuxt-seo-utils sets `lang` too, from the site config's i18n locale, in a
|
|
75
|
+
// `low` entry. Unhead merges html attributes in priority order and the
|
|
76
|
+
// later entry wins (unhead 3, dedupeTags: sorted by weight, then each
|
|
77
|
+
// next entry's props override), so the layout's <Html :lang> at normal
|
|
78
|
+
// priority loses to the module's. A `low` entry made after the module's
|
|
79
|
+
// (a layout's setup runs after its plugin) is the one that wins.
|
|
80
|
+
useHead({ htmlAttrs: { lang: () => lang.value ?? undefined } }, { tagPriority: "low" });
|
|
81
|
+
|
|
82
|
+
// Into the payload on every server render, for client navigations to a
|
|
83
|
+
// page that generates a link preview card (useSeoContext).
|
|
84
|
+
if (import.meta.server) {
|
|
85
|
+
useOgImageReady();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// The business behind the site (PE-1103), from the domain's rules; the
|
|
89
|
+
// module's own WebSite and WebPage name it as publisher. Without
|
|
90
|
+
// organisation data there is none rather than one named after a host.
|
|
91
|
+
const organisation = rules.value.organisation;
|
|
92
|
+
if (organisation) {
|
|
93
|
+
useSchemaOrg([defineOrganization({
|
|
94
|
+
// The module drops what is undefined, as for a product's sku or brand.
|
|
95
|
+
name: organisation.name,
|
|
96
|
+
logo: organisation.logo || undefined,
|
|
97
|
+
sameAs: organisation.same_as.length ? [...organisation.same_as] : undefined,
|
|
98
|
+
})]);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const canonical = computed(() => {
|
|
102
|
+
const source = page.value;
|
|
103
|
+
if (error.value || (source ? !source.indexable() : !withCanonical)) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
const path = source?.path();
|
|
107
|
+
return seoCanonicalUrl({
|
|
108
|
+
origin: origin.value,
|
|
109
|
+
path: path ?? route.path,
|
|
110
|
+
query: path ? {} : route.query,
|
|
111
|
+
rules: rules.value,
|
|
112
|
+
pageType: source?.pageType(),
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
useHead({
|
|
117
|
+
link: () => (canonical.value ? [{ rel: "canonical", href: canonical.value }] : []),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return computed(() => {
|
|
121
|
+
const head = localeHead.value;
|
|
122
|
+
const localized = options.localizePath
|
|
123
|
+
? localizeLocaleHeadAlternates(head, options.localizePath, defaultLocale)
|
|
124
|
+
: head;
|
|
125
|
+
const narrowed = filterLocaleHeadAlternates(localized, productLocales?.value ?? null);
|
|
126
|
+
const ruled = applySeoRulesToLocaleHead(narrowed, { origin: origin.value, rules: rules.value });
|
|
127
|
+
const tag = lang.value;
|
|
128
|
+
return {
|
|
129
|
+
...head,
|
|
130
|
+
...ruled,
|
|
131
|
+
link: marketHreflangAlternates(ruled.link, lang.forLanguage),
|
|
132
|
+
meta: ruled.meta.map((entry) => {
|
|
133
|
+
if (entry.property === "og:locale" && tag) {
|
|
134
|
+
return { ...entry, content: ogLocale(tag) };
|
|
135
|
+
}
|
|
136
|
+
if (entry.property === "og:locale:alternate" && entry.content) {
|
|
137
|
+
return { ...entry, content: ogLocale(lang.forLanguage(entry.content) ?? entry.content) };
|
|
138
|
+
}
|
|
139
|
+
return entry;
|
|
140
|
+
}),
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** A locale code as Open Graph writes it: `de_CH`, `zh_Hant_TW`. */
|
|
146
|
+
function ogLocale(code: string): string {
|
|
147
|
+
return code.replace(/-/g, "_");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* The market locale the page speaks, or null while the shop's markets carry
|
|
152
|
+
* none (the i18n language then stands, as before markets had locales).
|
|
153
|
+
*
|
|
154
|
+
* The buyer's content locale counts only where it speaks the language the
|
|
155
|
+
* page chrome is written in: a French catalogue choice (`fr-CH`) on German
|
|
156
|
+
* UI strings leaves `lang` German, so a screen reader reads the interface
|
|
157
|
+
* as what it is. `forLanguage` answers the same for another UI language,
|
|
158
|
+
* for the og:locale alternates.
|
|
159
|
+
*/
|
|
160
|
+
function useMarketLanguageTag() {
|
|
161
|
+
const { locale, locales } = useI18n();
|
|
162
|
+
const defaultUiLanguage = useDefaultUiLanguage();
|
|
163
|
+
const { markets } = useMarkets();
|
|
164
|
+
const { market } = useLocalePreferences(markets);
|
|
165
|
+
const contentLocale = useCookie<string>(CONTENT_LOCALE_COOKIE, { default: () => "", watch: true });
|
|
166
|
+
|
|
167
|
+
function pick(uiLanguage: string, chosen: string): string | null {
|
|
168
|
+
const marketLocales = market.value?.locales;
|
|
169
|
+
if (!marketLocales?.length) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
return pickMarketLocale({
|
|
173
|
+
locales: marketLocales,
|
|
174
|
+
chosen,
|
|
175
|
+
uiLanguage,
|
|
176
|
+
uiLanguages: locales.value.map(entry => entry.code),
|
|
177
|
+
defaultUiLanguage: defaultUiLanguage.value,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const tag = computed(() => {
|
|
182
|
+
const picked = pick(locale.value, contentLocale.value);
|
|
183
|
+
return picked && localeLanguage(picked) !== localeLanguage(locale.value) ? pick(locale.value, "") : picked;
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
return Object.assign(tag, {
|
|
187
|
+
forLanguage: (code: string): string | null => pick(localeLanguage(code), ""),
|
|
188
|
+
});
|
|
189
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ComputedRef } from "vue";
|
|
2
|
+
|
|
3
|
+
import type { SeoRules } from "../interfaces/seo";
|
|
4
|
+
import { defaultSeoRules } from "../shared/seoRules";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The SEO rules of the domain this page is served on, synchronous everywhere.
|
|
8
|
+
*
|
|
9
|
+
* The server read them before rendering began (server/plugins/seoSiteConfig.ts
|
|
10
|
+
* puts them on the request context); the shared state takes them from there
|
|
11
|
+
* and hands them to the client in the payload. A domain's rules do not change
|
|
12
|
+
* while a buyer navigates it, so the client never reads again.
|
|
13
|
+
*
|
|
14
|
+
* Without an answer (a page rendered outside a request, a test) they are the
|
|
15
|
+
* service's defaults for the host, the same thing the server falls back to:
|
|
16
|
+
* the host without its port and in lower case, as the server keys it.
|
|
17
|
+
*/
|
|
18
|
+
export function useSeoRules(): ComputedRef<SeoRules> {
|
|
19
|
+
const state = useState<SeoRules | null>("cover:seo-rules", () =>
|
|
20
|
+
(import.meta.server ? useRequestEvent()?.context.seoRules as SeoRules | undefined : undefined) ?? null);
|
|
21
|
+
const host = useRequestURL().hostname.toLowerCase();
|
|
22
|
+
return computed(() => state.value ?? defaultSeoRules(host));
|
|
23
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A domain's SEO rules, as the seo service publishes them for storefronts
|
|
3
|
+
* (`GET /v1/seo/storefront/rules?host=…`, schema 1). The storefront applies
|
|
4
|
+
* them per request; it does not own them. Defaults are filled in by the
|
|
5
|
+
* service, so a domain nobody configured still gets a complete bundle.
|
|
6
|
+
*/
|
|
7
|
+
export interface SeoPageTypeRules {
|
|
8
|
+
/** Pattern with placeholders such as `{name} | {site}`; indexed types only. */
|
|
9
|
+
readonly title?: string;
|
|
10
|
+
readonly description?: string | null;
|
|
11
|
+
/** `index,follow`, `noindex,follow`, … */
|
|
12
|
+
readonly robots: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface SeoRules {
|
|
16
|
+
readonly schema: number;
|
|
17
|
+
readonly host: string;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the host is one of the tenant's (rules of its own, or announced
|
|
20
|
+
* by Console). A made-up host gets the defaults too, with `false`. Older
|
|
21
|
+
* services leave it out.
|
|
22
|
+
*/
|
|
23
|
+
readonly known?: boolean;
|
|
24
|
+
/** The organisation's name, or the host. */
|
|
25
|
+
readonly site_name: string;
|
|
26
|
+
readonly canonical: {
|
|
27
|
+
/** The main domain product and category pages canonicalise to; null for this one. */
|
|
28
|
+
readonly host: string | null;
|
|
29
|
+
readonly cross_domain_page_types: readonly string[];
|
|
30
|
+
/** Query parameters a canonical leaves out; `utm_*` is a prefix. */
|
|
31
|
+
readonly strip_params: readonly string[];
|
|
32
|
+
};
|
|
33
|
+
readonly hreflang: {
|
|
34
|
+
readonly x_default: string | null;
|
|
35
|
+
/** null leaves the alternates to the storefront's own locales. */
|
|
36
|
+
readonly locales: readonly string[] | null;
|
|
37
|
+
};
|
|
38
|
+
readonly max_length: { readonly title: number; readonly description: number };
|
|
39
|
+
readonly page_types: Readonly<Record<string, SeoPageTypeRules>>;
|
|
40
|
+
readonly organisation: { readonly name: string; readonly logo: string | null; readonly same_as: readonly string[] } | null;
|
|
41
|
+
readonly structured_data: { readonly prices: boolean };
|
|
42
|
+
/**
|
|
43
|
+
* A product URL whose product cannot be found: a 301 to the category the
|
|
44
|
+
* URL names, or 410 Gone. Absent in bundles from before the field (the
|
|
45
|
+
* default then, `category`).
|
|
46
|
+
*/
|
|
47
|
+
readonly removed_products?: "category" | "gone";
|
|
48
|
+
}
|
package/app/layouts/default.vue
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { filterLocaleHeadAlternates } from "../shared/productLocales";
|
|
3
|
-
|
|
4
|
-
const localeHead = useLocaleHead({ seo: true });
|
|
5
2
|
// A product page links only the languages the product has a page in
|
|
6
3
|
// (PE-859 hides untranslated products); every other page is unchanged.
|
|
7
|
-
const { available: productLocales } = useProductLocales();
|
|
8
|
-
const head =
|
|
9
|
-
...localeHead.value,
|
|
10
|
-
...filterLocaleHeadAlternates(localeHead.value, productLocales.value),
|
|
11
|
-
}));
|
|
4
|
+
const { available: productLocales, localizePath } = useProductLocales();
|
|
5
|
+
const head = useSeoHead(productLocales, { localizePath });
|
|
12
6
|
const { navigateToSearch } = useSearch();
|
|
13
7
|
const route = useRoute();
|
|
14
8
|
const cart = useCartStore();
|
package/app/layouts/focus.vue
CHANGED
|
@@ -13,7 +13,9 @@ const shopContact = computed<ShopContact>(() => (appConfig.shopContact as ShopCo
|
|
|
13
13
|
const legalLinks = computed(() => (appConfig.legalLinks as typeof defaultLegalLinks | undefined) ?? defaultLegalLinks);
|
|
14
14
|
const { t } = useI18n();
|
|
15
15
|
const localePath = useLocalePath();
|
|
16
|
-
|
|
16
|
+
// Login, registration, recovery and the checkout are never indexed, and their
|
|
17
|
+
// URLs carry secrets and order ids that a canonical would repeat.
|
|
18
|
+
const head = useSeoHead(undefined, { canonical: false });
|
|
17
19
|
const year = new Date().getFullYear();
|
|
18
20
|
|
|
19
21
|
// Checkout gets a subtly tinted page background so the white section
|