@revenexx/cover 0.21.2 → 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 +18 -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/CheckoutDeliverySection.vue +3 -0
- 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/components/ui/forms/FormKitDatePicker.vue +8 -2
- 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/useCheckoutOnePage.ts +15 -4
- 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/formkit.config.ts +1 -1
- 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/requestedDate.ts +49 -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/checkout.json +1 -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/checkout.json +1 -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 +18 -12
- 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,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether this Site can serve generated link preview images (PE-1237).
|
|
3
|
+
*
|
|
4
|
+
* nuxt-og-image signs its image URLs with a key derived from the app secret,
|
|
5
|
+
* and in production a missing or short secret (`NUXT_APP_SECRET`, at least 32
|
|
6
|
+
* characters) makes every image request a 500 — a broken preview in every
|
|
7
|
+
* share. Without one a page names no generated image at all. Decided on the
|
|
8
|
+
* server, where the secret is, and carried to the client in the payload so a
|
|
9
|
+
* client navigation decides the same way: useSeoHead() reads it on every
|
|
10
|
+
* server render (every layout calls it), so the state is in the payload even
|
|
11
|
+
* when the first page served generated no card.
|
|
12
|
+
*/
|
|
13
|
+
export function useOgImageReady() {
|
|
14
|
+
return useState("cover:og-image-ready", () =>
|
|
15
|
+
import.meta.server && (import.meta.dev || String(useRuntimeConfig().appSecret ?? "").length >= 32));
|
|
16
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { Ref } from "vue";
|
|
2
|
+
|
|
3
|
+
import { productApi } from "../api/product";
|
|
4
|
+
import type { ProductDetailProduct } from "../interfaces/product-detail";
|
|
5
|
+
import { productFallbackPath, productListingSegments } from "../shared/productLocales";
|
|
6
|
+
import type { Product } from "./useProducts";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The HTTP answer of a product URL (PE-1236), decided on the server once the
|
|
10
|
+
* product fetch has settled. A page awaits it in place of setting a 404:
|
|
11
|
+
*
|
|
12
|
+
* - **Outdated slug.** The page finds the product by the id in front of the
|
|
13
|
+
* slug, so an old name still reached it with a 200 and a duplicate of the
|
|
14
|
+
* page (the gap ADR-0031 left). It now answers 301 to the product's current
|
|
15
|
+
* path, query kept. A shallower category path or the `_` placeholder keep
|
|
16
|
+
* their 200 and the canonical: internal links are built that way, and each
|
|
17
|
+
* would otherwise cost a hop.
|
|
18
|
+
* - **No answer.** A product fetch that failed for any reason but a 404 (the
|
|
19
|
+
* catalogue down, a timeout) says nothing about the product: 503 with a
|
|
20
|
+
* Retry-After, so crawlers come back instead of dropping or moving a live URL.
|
|
21
|
+
* - **No product.** The catalogue cannot tell a deleted product from one that
|
|
22
|
+
* never existed, so the domain's seo rules decide (`removed_products`):
|
|
23
|
+
* `category` sends the buyer to the category the URL names with a 301,
|
|
24
|
+
* `gone` answers 410. A URL that names no category, or one the catalogue
|
|
25
|
+
* does not have, or no product at all, is a 404: otherwise any made-up
|
|
26
|
+
* product URL would be a 301 to whatever it names. So is one whose
|
|
27
|
+
* category could not be checked.
|
|
28
|
+
* - **Not in this language.** A catalogue that hides untranslated products
|
|
29
|
+
* (`search_untranslated=hide`) has no document for a product in a language
|
|
30
|
+
* it is not translated into, and the fetch says 404 there too. When the
|
|
31
|
+
* product has a page in another language it is a 404, which crawlers ask
|
|
32
|
+
* again, never a 301 or 410 that writes the URL off before the translation
|
|
33
|
+
* comes. A lookup that fails or a catalogue that cannot tell treats the
|
|
34
|
+
* product as missing everywhere, as before.
|
|
35
|
+
*
|
|
36
|
+
* @returns Whether the page answers with itself (`true`), or this answered
|
|
37
|
+
* for it: a 301, 404, 410 or 503.
|
|
38
|
+
*/
|
|
39
|
+
export async function useProductAnswer(product: {
|
|
40
|
+
/** The `<id>-<name>` segment as requested. */
|
|
41
|
+
readonly slug: Readonly<Ref<string>>;
|
|
42
|
+
/** The category segments the URL names before `product`. */
|
|
43
|
+
readonly requestedCategory: Readonly<Ref<readonly string[]>>;
|
|
44
|
+
readonly productInfo: Readonly<Ref<ProductDetailProduct | undefined>>;
|
|
45
|
+
/** The product fetch's error, if it failed. */
|
|
46
|
+
readonly error: Readonly<Ref<{ readonly statusCode?: number } | null | undefined>>;
|
|
47
|
+
readonly categorySlug: Readonly<Ref<string | undefined>>;
|
|
48
|
+
readonly subcategorySlug: Readonly<Ref<string | undefined>>;
|
|
49
|
+
}): Promise<boolean> {
|
|
50
|
+
if (!import.meta.server) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
const nuxtApp = useNuxtApp();
|
|
54
|
+
const event = useRequestEvent();
|
|
55
|
+
if (!event) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
const route = useRoute();
|
|
59
|
+
const localePath = useLocalePath();
|
|
60
|
+
const rules = useSeoRules();
|
|
61
|
+
// Before the first await, while the setup context is still current.
|
|
62
|
+
const categoryExists = useCategoryExists();
|
|
63
|
+
const requestFetch = useRequestFetch();
|
|
64
|
+
const { locales } = useI18n();
|
|
65
|
+
|
|
66
|
+
/** Whether the product has a page in any storefront language (this one has none). */
|
|
67
|
+
async function translatedElsewhere(): Promise<boolean> {
|
|
68
|
+
const id = parseProductIdFromSlug(product.slug.value);
|
|
69
|
+
const answer = await requestFetch<{ locales: string[] | null }>(productApi.locales(id), {
|
|
70
|
+
query: { locales: locales.value.map(entry => entry.code).join(",") },
|
|
71
|
+
}).catch(() => null);
|
|
72
|
+
return Boolean(answer?.locales?.length);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const info = product.productInfo.value as Product | undefined;
|
|
76
|
+
if (info) {
|
|
77
|
+
if (product.slug.value && product.slug.value !== slugify(info)) {
|
|
78
|
+
const path = categoryProductPath([product.categorySlug.value, product.subcategorySlug.value], info);
|
|
79
|
+
await navigateTo({ path: localePath(path), query: route.query }, { redirectCode: 301 });
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const failure = product.error.value;
|
|
86
|
+
if (failure && failure.statusCode !== 404) {
|
|
87
|
+
setResponseStatus(event, 503);
|
|
88
|
+
setResponseHeader(event, "Retry-After", 120);
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!product.slug.value) {
|
|
93
|
+
setResponseStatus(event, 404);
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
// The category first, also where removed products are gone: a URL under
|
|
97
|
+
// a category the catalogue lacks never named a product (AC-4).
|
|
98
|
+
const [category, subcategory] = productListingSegments(product.requestedCategory.value);
|
|
99
|
+
if (!category) {
|
|
100
|
+
setResponseStatus(event, 404);
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
if (await categoryExists(category, subcategory) !== true) {
|
|
104
|
+
setResponseStatus(event, 404);
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
if (await translatedElsewhere()) {
|
|
108
|
+
setResponseStatus(event, 404);
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
if (rules.value.removed_products === "gone") {
|
|
112
|
+
setResponseStatus(event, 410);
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
// The await above left the Nuxt context, which navigateTo needs.
|
|
116
|
+
await nuxtApp.runWithContext(() => navigateTo(
|
|
117
|
+
{ path: localePath(productFallbackPath(product.requestedCategory.value)), query: route.query },
|
|
118
|
+
{ redirectCode: 301 },
|
|
119
|
+
));
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { productApi } from "../api/product";
|
|
2
|
-
import { normalizeLocaleCode } from "../shared/locale";
|
|
3
|
-
import { productFallbackPath,
|
|
4
|
-
import {
|
|
2
|
+
import { localeLanguage, normalizeLocaleCode } from "../shared/locale";
|
|
3
|
+
import { productFallbackPath, withProductSlug } from "../shared/productLocales";
|
|
4
|
+
import { slugify } from "./useProducts";
|
|
5
|
+
import type { Product } from "./useProducts";
|
|
6
|
+
import { useRouteProductSubject } from "./useRouteSubject";
|
|
5
7
|
|
|
6
8
|
interface ProductLocalesResponse {
|
|
7
9
|
locales: string[] | null;
|
|
10
|
+
names?: Record<string, string> | null;
|
|
8
11
|
}
|
|
9
12
|
|
|
10
13
|
/**
|
|
@@ -20,8 +23,7 @@ interface ProductLocalesResponse {
|
|
|
20
23
|
* locale is linked then, exactly as before. Only a product page narrows.
|
|
21
24
|
*/
|
|
22
25
|
export function useProductLocales() {
|
|
23
|
-
const
|
|
24
|
-
const { id } = useRouteProductSubject();
|
|
26
|
+
const { id, slug, categorySegments } = useRouteProductSubject();
|
|
25
27
|
const { locales } = useI18n();
|
|
26
28
|
const requestFetch = useRequestFetch();
|
|
27
29
|
|
|
@@ -46,11 +48,20 @@ export function useProductLocales() {
|
|
|
46
48
|
return available.value?.includes(normalizeLocaleCode(code)) ?? true;
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
/**
|
|
52
|
+
* A path of this page in another locale with the product's slug in that
|
|
53
|
+
* locale (PE-1236): its name, and so its slug, may be translated, and a
|
|
54
|
+
* link with this locale's slug would land on the outdated-slug 301. Off a
|
|
55
|
+
* product page, or without a name for the locale, the path stays as given.
|
|
56
|
+
*/
|
|
57
|
+
function localizePath(path: string, code: string): string {
|
|
58
|
+
const names = id.value ? data.value?.names : undefined;
|
|
59
|
+
const name = names?.[code] ?? names?.[normalizeLocaleCode(code)] ?? names?.[localeLanguage(code)];
|
|
60
|
+
return name ? withProductSlug(path, slug.value, slugify({ id: id.value, name } as Product)) : path;
|
|
61
|
+
}
|
|
62
|
+
|
|
49
63
|
/** Where a locale without the product goes instead: its category listing, or home. */
|
|
50
|
-
const fallbackPath = computed(() => productFallbackPath(
|
|
51
|
-
routeSegments(route.params.category),
|
|
52
|
-
routeSegments(route.params.rest),
|
|
53
|
-
)));
|
|
64
|
+
const fallbackPath = computed(() => productFallbackPath(categorySegments.value));
|
|
54
65
|
|
|
55
|
-
return { available, hasPage, fallbackPath };
|
|
66
|
+
return { available, hasPage, fallbackPath, localizePath };
|
|
56
67
|
}
|
|
@@ -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
|
+
}
|