orionplace-nuxt 0.7.2 → 0.7.4
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/README.md +4 -1
- package/package.json +1 -1
- package/src/favicon-handler.mjs +12 -0
- package/src/module.mjs +1 -0
- package/templates/app/app.vue +4 -0
- package/templates/app/components/orionplace/blog/StorefrontJournal.vue +1 -0
- package/templates/app/components/orionplace/search/ProductSearchResults.vue +60 -12
- package/templates/app/components/orionplace/shared/StorefrontPagination.README.md +5 -0
- package/templates/app/components/orionplace/shared/StorefrontPagination.vue +63 -16
- package/templates/app/components/orionplace/stores/StorefrontStores.vue +1 -0
- package/templates/app/composables/useOrionplaceAppLoad.ts +10 -1
- package/templates/app/composables/useOrionplacePageSeo.ts +49 -5
- package/templates/app/pages/journal/[id].vue +36 -0
- package/templates/app/pages/journal/index.vue +7 -0
- package/templates/app/utils/orionplace/blogLayout.ts +13 -0
- package/templates/app/utils/orionplace/pageSeo.ts +318 -8
- package/templates/app/utils/orionplaceAppLoad.ts +10 -0
package/README.md
CHANGED
|
@@ -502,11 +502,14 @@ server from the project root or explicitly point it at the configuration directo
|
|
|
502
502
|
Every supplied page sets its title, description and keywords through
|
|
503
503
|
`app/composables/useOrionplacePageSeo.ts` and Nuxt's `useSeoMeta()`.
|
|
504
504
|
The homepage prefers `init.seo`, and category pages prefer their localized SEO
|
|
505
|
-
fields. Empty values fall back to page-specific Russian or English copy in
|
|
505
|
+
fields. Empty values fall back to page-specific Russian, Spanish or English copy in
|
|
506
506
|
`app/utils/orionplace/pageSeo.ts`. Metadata updates with the current locale and
|
|
507
507
|
route data. The homepage retains additional backend Open Graph and Twitter tags
|
|
508
508
|
through `useHead()`. Profile and logout pages remain excluded from indexing;
|
|
509
509
|
search results retain their `noindex, follow` policy.
|
|
510
|
+
Pages with a canonical address also link the same page in the other storefront languages (`hreflang`) and set `og:type` and `og:locale`; a journal article adds its publication date (`article:published_time`) and schema.org `BlogPosting` data. The store icon (`logos.ico`) is the page's `<link rel="icon">`. An unknown `?locale` opens the default language.
|
|
511
|
+
|
|
512
|
+
List pages (journal, categories, stores) link their previous and next pages as real links (`?page=2`). Each later page has its own canonical address and a title with its page number; a journal page past the last one answers 404.
|
|
510
513
|
|
|
511
514
|
## Documentation
|
|
512
515
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orionplace-nuxt",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"description": "Nuxt 4 storefront for your Orionplace marketplace: setup CLI, server API gateway, typed store and ready-made catalog, cart, checkout and account components in English and Russian, plus an Android app build.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineEventHandler, setResponseStatus } from 'h3';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* /favicon.ico without a file in public/: Nitro would answer it with a
|
|
5
|
+
* placeholder text that is not an image. The storefront's icon is the
|
|
6
|
+
* <link rel="icon"> from App Load (logos.ico), so this address answers 404,
|
|
7
|
+
* as in the React and Svelte storefronts. A public/favicon.ico still wins.
|
|
8
|
+
*/
|
|
9
|
+
export default defineEventHandler((event) => {
|
|
10
|
+
setResponseStatus(event, 404);
|
|
11
|
+
return '';
|
|
12
|
+
});
|
package/src/module.mjs
CHANGED
|
@@ -81,6 +81,7 @@ export default defineNuxtModule({
|
|
|
81
81
|
addServerHandler({ route: '/robots.txt', method: 'get', handler: resolve(directory, 'seo.mjs') });
|
|
82
82
|
addServerHandler({ route: '/sitemap.xml', method: 'get', handler: resolve(directory, 'seo.mjs') });
|
|
83
83
|
}
|
|
84
|
+
addServerHandler({ route: '/favicon.ico', method: 'get', handler: resolve(import.meta.dirname, 'favicon-handler.mjs') });
|
|
84
85
|
addServerHandler({ middleware: true, handler: resolve(directory, 'domain.mjs') });
|
|
85
86
|
addServerPlugin(resolve(import.meta.dirname, 'asset-loading-plugin.mjs'));
|
|
86
87
|
},
|
package/templates/app/app.vue
CHANGED
|
@@ -6,13 +6,17 @@
|
|
|
6
6
|
import OrionplaceThemeProvider from '@/components/orionplace/theme/OrionplaceThemeProvider.vue';
|
|
7
7
|
import { useOrionplaceTheme } from '@/composables/useOrionplaceTheme';
|
|
8
8
|
import { storefrontPageError } from '@/composables/useOrionplaceMissingPage';
|
|
9
|
+
import { storefrontIconLinks } from '@/utils/orionplace/pageSeo';
|
|
9
10
|
|
|
10
11
|
const store = useOrionplaceStore();
|
|
11
12
|
const route = useRoute();
|
|
12
13
|
const { mode } = useOrionplaceTheme();
|
|
13
14
|
|
|
15
|
+
// The store's icon from the admin panel (logos.ico) for browser tabs and
|
|
16
|
+
// search results; a page without it keeps the browser default.
|
|
14
17
|
useHead(() => ({
|
|
15
18
|
htmlAttrs: { lang: store.localeCode },
|
|
19
|
+
link: storefrontIconLinks(store.init?.logos?.ico),
|
|
16
20
|
}));
|
|
17
21
|
|
|
18
22
|
// The middleware opens the 503 error page during navigation. A refresh that
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { computed, ref, watch } from 'vue';
|
|
3
|
+
import { useRoute } from '#imports';
|
|
3
4
|
import { useOrionplaceStableHeight } from '@/composables/useOrionplaceStableHeight';
|
|
4
5
|
import { useOrionplaceBrowseStore } from '@/stores/orionplaceBrowse';
|
|
5
6
|
import { useOrionplaceSelectionsStore } from '@/stores/orionplaceSelections';
|
|
6
7
|
import { browseLabels } from '@/utils/orionplace/browseLabels';
|
|
7
8
|
import { hasSearchFilters } from '@/utils/orionplace/searchFilters';
|
|
9
|
+
import { storefrontPageHref } from '@/utils/orionplace/pageSeo';
|
|
8
10
|
import SearchFilters from '@/components/orionplace/search/SearchFilters.vue';
|
|
9
11
|
import ProductGroup from '@/components/orionplace/products/ProductGroup.vue';
|
|
10
12
|
import type { ProductFacetSelection } from '@/interfaces/orionplace/products/IProductSearchFacets';
|
|
@@ -95,6 +97,38 @@
|
|
|
95
97
|
}
|
|
96
98
|
});
|
|
97
99
|
const labels = computed(() => browseLabels(selectionStore.localeCode));
|
|
100
|
+
// Every list of this component keeps its page in the address (`?page=`),
|
|
101
|
+
// so previous and next are links search engines follow; a click changes
|
|
102
|
+
// the page in place.
|
|
103
|
+
const route = useRoute();
|
|
104
|
+
const search = computed(
|
|
105
|
+
() => new URL(route.fullPath, 'http://storefront').search,
|
|
106
|
+
);
|
|
107
|
+
const previousHref = computed(() =>
|
|
108
|
+
!props.pending && props.page > 1
|
|
109
|
+
? storefrontPageHref(route.path, search.value, props.page - 1)
|
|
110
|
+
: undefined,
|
|
111
|
+
);
|
|
112
|
+
const nextHref = computed(() =>
|
|
113
|
+
!props.pending && !props.failed && props.hasNext
|
|
114
|
+
? storefrontPageHref(route.path, search.value, props.page + 1)
|
|
115
|
+
: undefined,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
// A link opened in a new tab or window keeps its default.
|
|
119
|
+
function followPage(event: MouseEvent, value: number) {
|
|
120
|
+
if (
|
|
121
|
+
event.button !== 0 ||
|
|
122
|
+
event.metaKey ||
|
|
123
|
+
event.ctrlKey ||
|
|
124
|
+
event.shiftKey ||
|
|
125
|
+
event.altKey
|
|
126
|
+
) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
emit('changePage', value);
|
|
131
|
+
}
|
|
98
132
|
const filtersOpen = ref(false);
|
|
99
133
|
const hasFilters = computed(() =>
|
|
100
134
|
hasSearchFilters(
|
|
@@ -410,22 +444,29 @@
|
|
|
410
444
|
"
|
|
411
445
|
data-search-pagination
|
|
412
446
|
>
|
|
413
|
-
<
|
|
414
|
-
|
|
415
|
-
:
|
|
447
|
+
<component
|
|
448
|
+
:is="previousHref ? 'a' : 'button'"
|
|
449
|
+
:type="previousHref ? undefined : 'button'"
|
|
450
|
+
:href="previousHref"
|
|
451
|
+
:rel="previousHref ? 'prev' : undefined"
|
|
452
|
+
:disabled="previousHref ? undefined : pending || page === 1"
|
|
416
453
|
class="
|
|
417
454
|
inline-flex h-11 items-center justify-center px-5
|
|
418
455
|
[font-family:inherit] text-xs font-medium uppercase tracking-[0.08em]
|
|
419
|
-
text-orionplace-text
|
|
456
|
+
text-orionplace-text no-underline
|
|
420
457
|
border border-solid border-orionplace-border bg-transparent
|
|
421
458
|
cursor-pointer outline-none
|
|
422
459
|
hover:border-orionplace-text focus-visible:border-orionplace-text
|
|
423
460
|
disabled:cursor-not-allowed disabled:opacity-40
|
|
424
461
|
"
|
|
425
|
-
@click="
|
|
462
|
+
@click="
|
|
463
|
+
previousHref
|
|
464
|
+
? followPage($event, page - 1)
|
|
465
|
+
: emit('changePage', page - 1)
|
|
466
|
+
"
|
|
426
467
|
>
|
|
427
468
|
← {{ labels.previous }}
|
|
428
|
-
</
|
|
469
|
+
</component>
|
|
429
470
|
<span
|
|
430
471
|
class="
|
|
431
472
|
text-xs uppercase tracking-[0.08em] tabular-nums
|
|
@@ -435,22 +476,29 @@
|
|
|
435
476
|
{{ labels.page }} {{ page }}
|
|
436
477
|
<template v-if="pages">{{ labels.of }} {{ pages }}</template>
|
|
437
478
|
</span>
|
|
438
|
-
<
|
|
439
|
-
|
|
440
|
-
:
|
|
479
|
+
<component
|
|
480
|
+
:is="nextHref ? 'a' : 'button'"
|
|
481
|
+
:type="nextHref ? undefined : 'button'"
|
|
482
|
+
:href="nextHref"
|
|
483
|
+
:rel="nextHref ? 'next' : undefined"
|
|
484
|
+
:disabled="nextHref ? undefined : pending || failed || !hasNext"
|
|
441
485
|
class="
|
|
442
486
|
inline-flex h-11 items-center justify-center px-5
|
|
443
487
|
[font-family:inherit] text-xs font-medium uppercase tracking-[0.08em]
|
|
444
|
-
text-orionplace-text
|
|
488
|
+
text-orionplace-text no-underline
|
|
445
489
|
border border-solid border-orionplace-border bg-transparent
|
|
446
490
|
cursor-pointer outline-none
|
|
447
491
|
hover:border-orionplace-text focus-visible:border-orionplace-text
|
|
448
492
|
disabled:cursor-not-allowed disabled:opacity-40
|
|
449
493
|
"
|
|
450
|
-
@click="
|
|
494
|
+
@click="
|
|
495
|
+
nextHref
|
|
496
|
+
? followPage($event, page + 1)
|
|
497
|
+
: emit('changePage', page + 1)
|
|
498
|
+
"
|
|
451
499
|
>
|
|
452
500
|
{{ labels.next }} →
|
|
453
|
-
</
|
|
501
|
+
</component>
|
|
454
502
|
</nav>
|
|
455
503
|
</div>
|
|
456
504
|
</section>
|
|
@@ -40,6 +40,11 @@ pages supplied by the full starter.
|
|
|
40
40
|
between them, for a narrow list such as the support conversations; the buttons
|
|
41
41
|
keep Previous and Next as their accessible names.
|
|
42
42
|
|
|
43
|
+
`linked` is for lists that keep their page number in the address
|
|
44
|
+
(`?page=2`): Previous and Next are links to those addresses, so search engines
|
|
45
|
+
reach every page of the list, and a click still changes the page in place.
|
|
46
|
+
The journal and the store list use it.
|
|
47
|
+
|
|
43
48
|
## Endpoint coverage
|
|
44
49
|
|
|
45
50
|
No direct API request; the parent supplies the state.
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { computed, ref } from 'vue';
|
|
3
|
+
import { useRoute } from '#imports';
|
|
3
4
|
import { useOrionplaceSelectionsStore } from '@/stores/orionplaceSelections';
|
|
4
5
|
import { featureLabels } from '@/utils/orionplace/featureLabels';
|
|
5
6
|
import { scrollToPaginatedList } from '@/utils/orionplace/paginationScroll';
|
|
7
|
+
import { storefrontPageHref } from '@/utils/orionplace/pageSeo';
|
|
6
8
|
import type { IApiPagination } from '@/interfaces/orionplace/accounts/IProfileData';
|
|
7
9
|
import '@/components/orionplace/shared/features.css';
|
|
8
10
|
|
|
@@ -11,17 +13,58 @@
|
|
|
11
13
|
pending?: boolean;
|
|
12
14
|
scrollTarget?: HTMLElement | string | null;
|
|
13
15
|
compact?: boolean;
|
|
16
|
+
linked?: boolean;
|
|
14
17
|
}>();
|
|
18
|
+
// `linked`: the list keeps its page number in the address (`?page=`), so
|
|
19
|
+
// previous and next are links to those addresses and search engines reach
|
|
20
|
+
// every page. A click still changes the page in place.
|
|
15
21
|
const emit = defineEmits<{ change: [page: number] }>();
|
|
16
22
|
const selectionStore = useOrionplaceSelectionsStore();
|
|
17
23
|
const labels = computed(() => featureLabels(selectionStore.localeCode));
|
|
18
24
|
const page = computed(() => props.pagination.page ?? 1);
|
|
19
25
|
const nav = ref<HTMLElement>();
|
|
26
|
+
const route = useRoute();
|
|
27
|
+
const previousPage = computed(
|
|
28
|
+
() => props.pagination.previous_page_number || page.value - 1,
|
|
29
|
+
);
|
|
30
|
+
const nextPage = computed(() =>
|
|
31
|
+
typeof props.pagination.next_page_number === 'number'
|
|
32
|
+
? props.pagination.next_page_number
|
|
33
|
+
: page.value + 1,
|
|
34
|
+
);
|
|
35
|
+
const search = computed(
|
|
36
|
+
() => new URL(route.fullPath, 'http://storefront').search,
|
|
37
|
+
);
|
|
38
|
+
const previousHref = computed(() =>
|
|
39
|
+
props.linked && !props.pending && props.pagination.has_previous
|
|
40
|
+
? storefrontPageHref(route.path, search.value, previousPage.value)
|
|
41
|
+
: undefined,
|
|
42
|
+
);
|
|
43
|
+
const nextHref = computed(() =>
|
|
44
|
+
props.linked && !props.pending && props.pagination.has_next
|
|
45
|
+
? storefrontPageHref(route.path, search.value, nextPage.value)
|
|
46
|
+
: undefined,
|
|
47
|
+
);
|
|
20
48
|
|
|
21
49
|
function change(value: number) {
|
|
22
50
|
emit('change', value);
|
|
23
51
|
scrollToPaginatedList(nav.value, props.scrollTarget);
|
|
24
52
|
}
|
|
53
|
+
|
|
54
|
+
// A link opened in a new tab or window keeps its default.
|
|
55
|
+
function follow(event: MouseEvent, value: number) {
|
|
56
|
+
if (
|
|
57
|
+
event.button !== 0 ||
|
|
58
|
+
event.metaKey ||
|
|
59
|
+
event.ctrlKey ||
|
|
60
|
+
event.shiftKey ||
|
|
61
|
+
event.altKey
|
|
62
|
+
) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
change(value);
|
|
67
|
+
}
|
|
25
68
|
</script>
|
|
26
69
|
|
|
27
70
|
<template>
|
|
@@ -41,13 +84,20 @@
|
|
|
41
84
|
The compact form fits a narrow list: arrow buttons named for screen
|
|
42
85
|
readers, with the page count between them.
|
|
43
86
|
-->
|
|
44
|
-
<
|
|
87
|
+
<component
|
|
88
|
+
:is="previousHref ? 'a' : 'button'"
|
|
45
89
|
class="op-feature-button"
|
|
46
|
-
type="button"
|
|
90
|
+
:type="previousHref ? undefined : 'button'"
|
|
91
|
+
:href="previousHref"
|
|
92
|
+
:rel="previousHref ? 'prev' : undefined"
|
|
47
93
|
:aria-label="compact ? labels.previous : undefined"
|
|
48
94
|
:title="compact ? labels.previous : undefined"
|
|
49
|
-
:disabled="pending || !pagination.has_previous"
|
|
50
|
-
@click="
|
|
95
|
+
:disabled="previousHref ? undefined : pending || !pagination.has_previous"
|
|
96
|
+
@click="
|
|
97
|
+
previousHref
|
|
98
|
+
? follow($event, previousPage)
|
|
99
|
+
: change(previousPage)
|
|
100
|
+
"
|
|
51
101
|
>
|
|
52
102
|
<svg
|
|
53
103
|
v-if="compact"
|
|
@@ -63,24 +113,21 @@
|
|
|
63
113
|
<path d="m15 5-7 7 7 7" />
|
|
64
114
|
</svg>
|
|
65
115
|
<template v-else>{{ labels.previous }}</template>
|
|
66
|
-
</
|
|
116
|
+
</component>
|
|
67
117
|
<span class="tabular-nums">
|
|
68
118
|
{{ labels.page }} {{ page }}
|
|
69
119
|
<template v-if="pagination.pages">/ {{ pagination.pages }}</template>
|
|
70
120
|
</span>
|
|
71
|
-
<
|
|
121
|
+
<component
|
|
122
|
+
:is="nextHref ? 'a' : 'button'"
|
|
72
123
|
class="op-feature-button"
|
|
73
|
-
type="button"
|
|
124
|
+
:type="nextHref ? undefined : 'button'"
|
|
125
|
+
:href="nextHref"
|
|
126
|
+
:rel="nextHref ? 'next' : undefined"
|
|
74
127
|
:aria-label="compact ? labels.next : undefined"
|
|
75
128
|
:title="compact ? labels.next : undefined"
|
|
76
|
-
:disabled="pending || !pagination.has_next"
|
|
77
|
-
@click="
|
|
78
|
-
change(
|
|
79
|
-
typeof pagination.next_page_number === 'number'
|
|
80
|
-
? pagination.next_page_number
|
|
81
|
-
: page + 1,
|
|
82
|
-
)
|
|
83
|
-
"
|
|
129
|
+
:disabled="nextHref ? undefined : pending || !pagination.has_next"
|
|
130
|
+
@click="nextHref ? follow($event, nextPage) : change(nextPage)"
|
|
84
131
|
>
|
|
85
132
|
<svg
|
|
86
133
|
v-if="compact"
|
|
@@ -96,6 +143,6 @@
|
|
|
96
143
|
<path d="m9 5 7 7-7 7" />
|
|
97
144
|
</svg>
|
|
98
145
|
<template v-else>{{ labels.next }}</template>
|
|
99
|
-
</
|
|
146
|
+
</component>
|
|
100
147
|
</nav>
|
|
101
148
|
</template>
|
|
@@ -7,7 +7,11 @@ import type {
|
|
|
7
7
|
AppLoadResult,
|
|
8
8
|
} from '@/interfaces/orionplace/transport';
|
|
9
9
|
import { useOrionplaceApi } from '@/composables/useOrionplaceApi';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
appLoadRejectedLocale,
|
|
12
|
+
appLoadResult,
|
|
13
|
+
inspectAppLoad,
|
|
14
|
+
} from '@/utils/orionplaceAppLoad';
|
|
11
15
|
|
|
12
16
|
/** Transport and explicit actions. Calling this accessor does not start a request. */
|
|
13
17
|
export function useOrionplaceAppLoad() {
|
|
@@ -51,6 +55,11 @@ export function useOrionplaceAppLoad() {
|
|
|
51
55
|
// or CSRF token) is relayed to the browser by the shared API transport,
|
|
52
56
|
// which also sends it with the later requests of the same render.
|
|
53
57
|
const failure = inspectAppLoad(received.body, received.status);
|
|
58
|
+
// An address with a language the storefront does not have (`?locale=xx`)
|
|
59
|
+
// opens in the storefront's default language instead of the 503 page.
|
|
60
|
+
if (failure && locale && appLoadRejectedLocale(failure)) {
|
|
61
|
+
return request(signal);
|
|
62
|
+
}
|
|
54
63
|
if (failure) {
|
|
55
64
|
throw createError({
|
|
56
65
|
message: 'Marketplace initialization failed.',
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { computed, toValue } from 'vue';
|
|
2
2
|
import type { MaybeRefOrGetter } from 'vue';
|
|
3
3
|
import { useHead, useRequestHeader, useRoute, useSeoMeta } from '#imports';
|
|
4
|
+
import { useOrionplaceStore } from '@/stores/orionplace';
|
|
4
5
|
import {
|
|
5
6
|
storefrontAbsoluteUrl,
|
|
7
|
+
storefrontAlternateLinks,
|
|
6
8
|
storefrontCanonicalUrl,
|
|
9
|
+
storefrontOpenGraphLocale,
|
|
10
|
+
storefrontOpenGraphType,
|
|
7
11
|
storefrontPageMetadata,
|
|
12
|
+
storefrontPagedText,
|
|
8
13
|
storefrontPublicOrigin,
|
|
9
14
|
} from '@/utils/orionplace/pageSeo';
|
|
10
15
|
import type { StorefrontSeoPage } from '@/utils/orionplace/pageSeo';
|
|
@@ -19,6 +24,9 @@ export function useOrionplacePageSeo(
|
|
|
19
24
|
keywords?: MaybeRefOrGetter<string | undefined>;
|
|
20
25
|
robots?: MaybeRefOrGetter<string | undefined>;
|
|
21
26
|
image?: MaybeRefOrGetter<string | undefined>;
|
|
27
|
+
/** A journal article's dates (ISO 8601) for article:published_time. */
|
|
28
|
+
published?: MaybeRefOrGetter<string | undefined>;
|
|
29
|
+
modified?: MaybeRefOrGetter<string | undefined>;
|
|
22
30
|
/**
|
|
23
31
|
* The page's schema.org data (a record page, e.g. the product), built
|
|
24
32
|
* from its canonical address and the visitor's origin. A page without a
|
|
@@ -28,6 +36,7 @@ export function useOrionplacePageSeo(
|
|
|
28
36
|
} = {},
|
|
29
37
|
) {
|
|
30
38
|
const route = useRoute();
|
|
39
|
+
const store = useOrionplaceStore();
|
|
31
40
|
// The address the visitor used: the proxy's host during the server render.
|
|
32
41
|
const origin = import.meta.server
|
|
33
42
|
? storefrontPublicOrigin(
|
|
@@ -51,19 +60,46 @@ export function useOrionplacePageSeo(
|
|
|
51
60
|
),
|
|
52
61
|
);
|
|
53
62
|
|
|
63
|
+
// A later list page (`?page=2`) names its page number.
|
|
64
|
+
const paged = computed(() => ({
|
|
65
|
+
title:
|
|
66
|
+
storefrontPagedText(metadata.value.title, canonical.value, toValue(locale)) ??
|
|
67
|
+
metadata.value.title,
|
|
68
|
+
description:
|
|
69
|
+
storefrontPagedText(
|
|
70
|
+
metadata.value.description,
|
|
71
|
+
canonical.value,
|
|
72
|
+
toValue(locale),
|
|
73
|
+
) ?? metadata.value.description,
|
|
74
|
+
}));
|
|
75
|
+
|
|
54
76
|
// Link previews use the same title and description as the page; the
|
|
55
77
|
// image is the record's first picture when the page has one, as a
|
|
56
78
|
// complete address.
|
|
57
79
|
const seo = {
|
|
58
|
-
title: () =>
|
|
59
|
-
description: () =>
|
|
80
|
+
title: () => paged.value.title,
|
|
81
|
+
description: () => paged.value.description,
|
|
60
82
|
keywords: () => metadata.value.keywords,
|
|
61
83
|
robots: () => toValue(values.robots),
|
|
62
|
-
ogTitle: () =>
|
|
63
|
-
ogDescription: () =>
|
|
84
|
+
ogTitle: () => paged.value.title,
|
|
85
|
+
ogDescription: () => paged.value.description,
|
|
64
86
|
ogImage: () => storefrontAbsoluteUrl(toValue(values.image), origin),
|
|
65
87
|
ogUrl: () => canonical.value,
|
|
88
|
+
// Nuxt's head types leave out og:type `product` (Open Graph product
|
|
89
|
+
// pages); the tag renders as given.
|
|
90
|
+
ogType: () =>
|
|
91
|
+
storefrontOpenGraphType(toValue(page)) as 'website' | 'article',
|
|
92
|
+
ogLocale: () => storefrontOpenGraphLocale(toValue(locale)),
|
|
93
|
+
articlePublishedTime: () => toValue(values.published),
|
|
94
|
+
articleModifiedTime: () => toValue(values.modified),
|
|
66
95
|
};
|
|
96
|
+
// The page in the storefront's other languages, beside the canonical one.
|
|
97
|
+
const alternates = computed(() =>
|
|
98
|
+
storefrontAlternateLinks(
|
|
99
|
+
canonical.value,
|
|
100
|
+
Object.keys(store.init?.locale ?? {}),
|
|
101
|
+
),
|
|
102
|
+
);
|
|
67
103
|
const structured = computed(() =>
|
|
68
104
|
canonical.value && values.structuredData
|
|
69
105
|
? structuredDataJson(values.structuredData(canonical.value, origin))
|
|
@@ -73,7 +109,15 @@ export function useOrionplacePageSeo(
|
|
|
73
109
|
useHead({
|
|
74
110
|
link: () =>
|
|
75
111
|
canonical.value
|
|
76
|
-
? [
|
|
112
|
+
? [
|
|
113
|
+
{ key: 'canonical', rel: 'canonical', href: canonical.value },
|
|
114
|
+
...alternates.value.map((alternate) => ({
|
|
115
|
+
key: `alternate-${alternate.hreflang}`,
|
|
116
|
+
rel: 'alternate' as const,
|
|
117
|
+
hreflang: alternate.hreflang,
|
|
118
|
+
href: alternate.href,
|
|
119
|
+
})),
|
|
120
|
+
]
|
|
77
121
|
: [],
|
|
78
122
|
script: () =>
|
|
79
123
|
structured.value
|
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
import { useOrionplaceStorefront } from '@/composables/useOrionplaceStorefront';
|
|
8
8
|
import { useOrionplaceServerData } from '@/composables/useOrionplaceServerData';
|
|
9
9
|
import { requestBlogPost } from '@/utils/orionplace/blogLayout';
|
|
10
|
+
import {
|
|
11
|
+
storefrontAbsoluteUrl,
|
|
12
|
+
storefrontArticleData,
|
|
13
|
+
storefrontIsoDate,
|
|
14
|
+
} from '@/utils/orionplace/pageSeo';
|
|
10
15
|
import {
|
|
11
16
|
getAvailableNestedValueFromObject,
|
|
12
17
|
plainText,
|
|
@@ -74,6 +79,37 @@
|
|
|
74
79
|
),
|
|
75
80
|
).slice(0, 160),
|
|
76
81
|
image: () => cover.value,
|
|
82
|
+
published: () => storefrontIsoDate(post.value?.date_created?.date),
|
|
83
|
+
modified: () =>
|
|
84
|
+
storefrontIsoDate(post.value?.date_updated?.date) ??
|
|
85
|
+
storefrontIsoDate(post.value?.date_created?.date),
|
|
86
|
+
// The article as schema.org BlogPosting, with the store as its author.
|
|
87
|
+
structuredData: (canonical, origin) =>
|
|
88
|
+
post.value
|
|
89
|
+
? storefrontArticleData({
|
|
90
|
+
canonical,
|
|
91
|
+
origin,
|
|
92
|
+
headline:
|
|
93
|
+
getAvailableNestedValueFromObject(
|
|
94
|
+
post.value.locale,
|
|
95
|
+
store.localeCode,
|
|
96
|
+
'post_title',
|
|
97
|
+
) ?? '',
|
|
98
|
+
description:
|
|
99
|
+
plainText(
|
|
100
|
+
getAvailableNestedValueFromObject(
|
|
101
|
+
post.value.locale,
|
|
102
|
+
store.localeCode,
|
|
103
|
+
'post_preview_text',
|
|
104
|
+
),
|
|
105
|
+
).slice(0, 160) || undefined,
|
|
106
|
+
image: storefrontAbsoluteUrl(cover.value, origin),
|
|
107
|
+
published: storefrontIsoDate(post.value.date_created?.date),
|
|
108
|
+
modified: storefrontIsoDate(post.value.date_updated?.date),
|
|
109
|
+
locale: store.localeCode,
|
|
110
|
+
storeName: store.init?.contact?.company_name,
|
|
111
|
+
})
|
|
112
|
+
: undefined,
|
|
77
113
|
});
|
|
78
114
|
|
|
79
115
|
// An invalid ID, or an article that blog_posts_get does not return,
|
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
import { useOrionplaceStore } from '@/stores/orionplace';
|
|
5
5
|
import { useOrionplacePageSeo } from '@/composables/useOrionplacePageSeo';
|
|
6
6
|
import { useOrionplaceServerData } from '@/composables/useOrionplaceServerData';
|
|
7
|
+
import { useOrionplaceMissingPage } from '@/composables/useOrionplaceMissingPage';
|
|
7
8
|
import {
|
|
8
9
|
blogPageNumber,
|
|
9
10
|
blogPageSize,
|
|
11
|
+
journalPagePastEnd,
|
|
10
12
|
blogPostsRequest,
|
|
11
13
|
blogViewType,
|
|
12
14
|
} from '@/utils/orionplace/blogLayout';
|
|
@@ -49,6 +51,11 @@
|
|
|
49
51
|
);
|
|
50
52
|
|
|
51
53
|
useOrionplacePageSeo('journal', () => store.localeCode);
|
|
54
|
+
|
|
55
|
+
// A page number past the last page has no articles: it answers 404, so
|
|
56
|
+
// search engines drop it instead of indexing an empty list.
|
|
57
|
+
const pastLastPage = journalPagePastEnd(page.value, serverPage.value);
|
|
58
|
+
useOrionplaceMissingPage(() => pastLastPage, 'Page not found');
|
|
52
59
|
</script>
|
|
53
60
|
|
|
54
61
|
<template>
|
|
@@ -93,3 +93,16 @@ export function blogCoverInitial(title: string) {
|
|
|
93
93
|
export function blogCoverPattern(postId: number) {
|
|
94
94
|
return Math.abs(postId) % 3;
|
|
95
95
|
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Whether a journal page number lies past the last page: the server render
|
|
99
|
+
* loaded that page (no filters) and it has no articles. Page 1 of an empty
|
|
100
|
+
* journal is a page of its own.
|
|
101
|
+
*/
|
|
102
|
+
export function journalPagePastEnd(
|
|
103
|
+
page: number,
|
|
104
|
+
loaded: IBlogJournalPage | null | undefined,
|
|
105
|
+
): boolean {
|
|
106
|
+
const posts = loaded?.data?.posts?.data;
|
|
107
|
+
return page > 1 && loaded?.page === page && Array.isArray(posts) && !posts.length;
|
|
108
|
+
}
|
|
@@ -263,17 +263,157 @@ const pageCopy = {
|
|
|
263
263
|
'error, store',
|
|
264
264
|
],
|
|
265
265
|
},
|
|
266
|
+
es: {
|
|
267
|
+
tariffs: [
|
|
268
|
+
'Planes de suscripción',
|
|
269
|
+
'Precios por periodo, periodos de prueba y opciones de cada plan.',
|
|
270
|
+
'planes, suscripciones, prueba',
|
|
271
|
+
],
|
|
272
|
+
tariff: [
|
|
273
|
+
'Plan de suscripción',
|
|
274
|
+
'Descripción, funciones, periodos y opciones de un plan de suscripción.',
|
|
275
|
+
'plan, suscripción, periodo',
|
|
276
|
+
],
|
|
277
|
+
subscriptions: [
|
|
278
|
+
'Mis suscripciones',
|
|
279
|
+
'Fechas de las suscripciones y renovación automática.',
|
|
280
|
+
'suscripciones, cuenta',
|
|
281
|
+
],
|
|
282
|
+
sellers: ['Vendedores', 'Vendedores y sus productos.', 'vendedores, productos'],
|
|
283
|
+
stores: [
|
|
284
|
+
'Tiendas',
|
|
285
|
+
'Direcciones, contactos y horarios de las tiendas.',
|
|
286
|
+
'tiendas, direcciones',
|
|
287
|
+
],
|
|
288
|
+
catalog: ['Catálogo', 'Categorías de productos de la tienda.', 'catálogo, categorías'],
|
|
289
|
+
activity: [
|
|
290
|
+
'Mi actividad',
|
|
291
|
+
'Códigos promocionales, reseñas e historial de accesos del cliente.',
|
|
292
|
+
'cuenta, códigos promocionales, reseñas, accesos',
|
|
293
|
+
],
|
|
294
|
+
promo: [
|
|
295
|
+
'Productos del código promocional',
|
|
296
|
+
'Productos de la tienda a los que se aplica la oferta del código promocional.',
|
|
297
|
+
'código promocional, oferta, productos',
|
|
298
|
+
],
|
|
299
|
+
wishlist: [
|
|
300
|
+
'Favoritos',
|
|
301
|
+
'Productos guardados y avisos de disponibilidad.',
|
|
302
|
+
'favoritos, productos',
|
|
303
|
+
],
|
|
304
|
+
contact: [
|
|
305
|
+
'Contacto',
|
|
306
|
+
'Datos de contacto de la empresa y formulario de mensajes de la tienda.',
|
|
307
|
+
'contacto, mensaje',
|
|
308
|
+
],
|
|
309
|
+
privacy: [
|
|
310
|
+
'Política de privacidad',
|
|
311
|
+
'Qué datos recibe la tienda, para qué, a quién los transmite y qué cookies usa el sitio.',
|
|
312
|
+
'datos personales, privacidad, cookies',
|
|
313
|
+
],
|
|
314
|
+
unsubscribe: [
|
|
315
|
+
'Preferencias de correo',
|
|
316
|
+
'Darse de baja de los correos de la tienda.',
|
|
317
|
+
'correos, baja',
|
|
318
|
+
],
|
|
319
|
+
tickets: [
|
|
320
|
+
'Soporte',
|
|
321
|
+
'Conversaciones del usuario con el soporte.',
|
|
322
|
+
'soporte, conversaciones',
|
|
323
|
+
],
|
|
324
|
+
orders: [
|
|
325
|
+
'Mis pedidos',
|
|
326
|
+
'Historial de pedidos y artículos comprados.',
|
|
327
|
+
'pedidos, compras',
|
|
328
|
+
],
|
|
329
|
+
cart: ['Carrito', 'Artículos y pago del pedido.', 'carrito, pago'],
|
|
330
|
+
addresses: [
|
|
331
|
+
'Mis direcciones',
|
|
332
|
+
'Direcciones de entrega guardadas.',
|
|
333
|
+
'direcciones, entrega',
|
|
334
|
+
],
|
|
335
|
+
wallet: [
|
|
336
|
+
'Monedero y pagos',
|
|
337
|
+
'Saldo e historial de pagos.',
|
|
338
|
+
'monedero, pagos',
|
|
339
|
+
],
|
|
340
|
+
home: [
|
|
341
|
+
'Tienda',
|
|
342
|
+
'Categorías y productos de la tienda.',
|
|
343
|
+
'tienda, catálogo, productos',
|
|
344
|
+
],
|
|
345
|
+
browse: [
|
|
346
|
+
'Resultados de búsqueda',
|
|
347
|
+
'Productos que coinciden con la búsqueda y los filtros elegidos.',
|
|
348
|
+
'búsqueda de productos, filtros, catálogo',
|
|
349
|
+
],
|
|
350
|
+
featured: [
|
|
351
|
+
'Destacados',
|
|
352
|
+
'Productos de las categorías que el cliente ha buscado en la tienda.',
|
|
353
|
+
'recomendaciones, productos, filtros',
|
|
354
|
+
],
|
|
355
|
+
category: [
|
|
356
|
+
'Categoría de productos',
|
|
357
|
+
'Productos y filtros disponibles de la categoría elegida.',
|
|
358
|
+
'categoría, productos, filtros',
|
|
359
|
+
],
|
|
360
|
+
journal: [
|
|
361
|
+
'Revista',
|
|
362
|
+
'Publicaciones de la tienda con títulos, resúmenes y tiempo de lectura.',
|
|
363
|
+
'revista, publicaciones, artículos',
|
|
364
|
+
],
|
|
365
|
+
publication: [
|
|
366
|
+
'Publicación de la revista',
|
|
367
|
+
'Un artículo de la revista de la tienda.',
|
|
368
|
+
'revista, publicación, artículo',
|
|
369
|
+
],
|
|
370
|
+
product: [
|
|
371
|
+
'Ficha de producto',
|
|
372
|
+
'Descripción, precio, variantes y disponibilidad del producto.',
|
|
373
|
+
'producto, precio, disponibilidad',
|
|
374
|
+
],
|
|
375
|
+
manufacturers: [
|
|
376
|
+
'Fabricantes',
|
|
377
|
+
'Fabricantes de la tienda con logotipos e índice alfabético.',
|
|
378
|
+
'fabricantes, marcas, índice alfabético',
|
|
379
|
+
],
|
|
380
|
+
profile: [
|
|
381
|
+
'Perfil personal',
|
|
382
|
+
'Datos personales, correo, notificaciones y contraseña de la cuenta.',
|
|
383
|
+
'perfil, cuenta, ajustes',
|
|
384
|
+
],
|
|
385
|
+
logout: [
|
|
386
|
+
'Cerrar sesión',
|
|
387
|
+
'Fin de la sesión y vuelta a la página principal.',
|
|
388
|
+
'cuenta, cerrar sesión, sesión',
|
|
389
|
+
],
|
|
390
|
+
notFound: [
|
|
391
|
+
'Página no encontrada',
|
|
392
|
+
'No hay ninguna página de la tienda en esta dirección.',
|
|
393
|
+
'página no encontrada, 404',
|
|
394
|
+
],
|
|
395
|
+
error: [
|
|
396
|
+
'Algo salió mal',
|
|
397
|
+
'No se pudo mostrar la página de la tienda.',
|
|
398
|
+
'error, tienda',
|
|
399
|
+
],
|
|
400
|
+
},
|
|
266
401
|
} as const;
|
|
267
402
|
|
|
268
403
|
export type StorefrontSeoPage = keyof typeof pageCopy.en;
|
|
269
404
|
|
|
405
|
+
/** The page copy for a storefront language; languages without one use English. */
|
|
406
|
+
function storefrontCopyLanguage(locale: string): keyof typeof pageCopy {
|
|
407
|
+
const language = locale.toLowerCase().split(/[-_]/)[0];
|
|
408
|
+
return language === 'ru' || language === 'es' ? language : 'en';
|
|
409
|
+
}
|
|
410
|
+
|
|
270
411
|
export function storefrontPageMetadata(
|
|
271
412
|
page: StorefrontSeoPage,
|
|
272
413
|
locale: string,
|
|
273
414
|
values: { title?: string; description?: string; keywords?: string } = {},
|
|
274
415
|
) {
|
|
275
|
-
const copy =
|
|
276
|
-
pageCopy[locale.toLowerCase().startsWith('ru') ? 'ru' : 'en'][page];
|
|
416
|
+
const copy = pageCopy[storefrontCopyLanguage(locale)][page];
|
|
277
417
|
const title = plainText(values.title ?? '') || copy[0];
|
|
278
418
|
|
|
279
419
|
return {
|
|
@@ -320,11 +460,15 @@ export function storefrontAbsoluteUrl(
|
|
|
320
460
|
// The pages the sitemap lists (runtime/marketplace.mjs), plus plan pages.
|
|
321
461
|
const indexedPage = /^\/(?:|catalog|journal|tariffs|manufacturers|sellers|stores|contact|privacy|(?:category|product|journal)\/\d+|tariffs\/[^/]+\/\d+)$/;
|
|
322
462
|
|
|
463
|
+
// Listed pages that are lists with page numbers (`?page=2`).
|
|
464
|
+
const pagedList = /^\/(?:journal|stores|category\/\d+)$/;
|
|
465
|
+
|
|
323
466
|
/**
|
|
324
467
|
* The canonical address of a page: the sitemap's address for it, the page in
|
|
325
|
-
* the language it shows (`?locale=`).
|
|
326
|
-
*
|
|
327
|
-
* pages
|
|
468
|
+
* the language it shows (`?locale=`). A later page of a list is a page of its
|
|
469
|
+
* own (`?locale=en&page=2`, Google's pagination guide), linked from the
|
|
470
|
+
* list's page links. Pages that are not listed, pages with other query
|
|
471
|
+
* parameters (filters, private keys) and noindex pages get none.
|
|
328
472
|
*/
|
|
329
473
|
export function storefrontCanonicalUrl(
|
|
330
474
|
origin: string,
|
|
@@ -333,9 +477,13 @@ export function storefrontCanonicalUrl(
|
|
|
333
477
|
locale: string,
|
|
334
478
|
robots?: string,
|
|
335
479
|
): string | undefined {
|
|
336
|
-
const path
|
|
337
|
-
const query
|
|
480
|
+
const path = pathname.replace(/\/+$/, '') || '/';
|
|
481
|
+
const query = new URLSearchParams(search);
|
|
482
|
+
const pageNumber = query.get('page');
|
|
338
483
|
query.delete('locale');
|
|
484
|
+
if (pageNumber !== null && pagedList.test(path) && /^[1-9]\d{0,5}$/.test(pageNumber)) {
|
|
485
|
+
query.delete('page');
|
|
486
|
+
}
|
|
339
487
|
if (
|
|
340
488
|
!origin ||
|
|
341
489
|
/noindex/i.test(robots ?? '') ||
|
|
@@ -344,9 +492,171 @@ export function storefrontCanonicalUrl(
|
|
|
344
492
|
) {
|
|
345
493
|
return undefined;
|
|
346
494
|
}
|
|
347
|
-
const url
|
|
495
|
+
const url = new URL(path, `${origin}/`);
|
|
348
496
|
if (locale) {
|
|
349
497
|
url.searchParams.set('locale', locale);
|
|
350
498
|
}
|
|
499
|
+
if (pageNumber && Number(pageNumber) > 1 && pagedList.test(path)) {
|
|
500
|
+
url.searchParams.set('page', pageNumber);
|
|
501
|
+
}
|
|
351
502
|
return url.toString();
|
|
352
503
|
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* A later page of a list repeats the list's title and description; the page
|
|
507
|
+
* number keeps them distinct (search engines report repeated titles as
|
|
508
|
+
* duplicates). The number comes from the canonical address, so only the
|
|
509
|
+
* indexed list pages get it.
|
|
510
|
+
*/
|
|
511
|
+
export function storefrontPagedText(
|
|
512
|
+
text: string | undefined,
|
|
513
|
+
canonical: string | undefined,
|
|
514
|
+
locale: string,
|
|
515
|
+
): string | undefined {
|
|
516
|
+
const page = canonical ? Number(new URL(canonical).searchParams.get('page')) : 0;
|
|
517
|
+
if (!text || !(page > 1)) {
|
|
518
|
+
return text;
|
|
519
|
+
}
|
|
520
|
+
const words: Record<string, string> = { ru: 'страница', es: 'página' };
|
|
521
|
+
const word = words[storefrontCopyLanguage(locale)] ?? 'page';
|
|
522
|
+
return `${text} · ${word} ${page}`;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* The address of another page of the list on screen: the current address
|
|
527
|
+
* with `page=` set (left out for page 1), every other parameter kept. Page
|
|
528
|
+
* links are real links, so search engines reach every page of a list.
|
|
529
|
+
*/
|
|
530
|
+
export function storefrontPageHref(
|
|
531
|
+
pathname: string,
|
|
532
|
+
search: string,
|
|
533
|
+
page: number,
|
|
534
|
+
): string {
|
|
535
|
+
const query = new URLSearchParams(search);
|
|
536
|
+
if (page > 1) {
|
|
537
|
+
query.set('page', String(page));
|
|
538
|
+
} else {
|
|
539
|
+
query.delete('page');
|
|
540
|
+
}
|
|
541
|
+
const text = query.toString();
|
|
542
|
+
return `${pathname}${text ? `?${text}` : ''}`;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/** og:type of a page: a product and a journal article have their own kinds. */
|
|
546
|
+
export function storefrontOpenGraphType(
|
|
547
|
+
page: StorefrontSeoPage,
|
|
548
|
+
): 'product' | 'article' | 'website' {
|
|
549
|
+
if (page === 'product') {
|
|
550
|
+
return 'product';
|
|
551
|
+
}
|
|
552
|
+
return page === 'publication' ? 'article' : 'website';
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
const openGraphRegions: Record<string, string> = {
|
|
556
|
+
de: 'de_DE',
|
|
557
|
+
en: 'en_US',
|
|
558
|
+
es: 'es_ES',
|
|
559
|
+
fr: 'fr_FR',
|
|
560
|
+
it: 'it_IT',
|
|
561
|
+
kk: 'kk_KZ',
|
|
562
|
+
pl: 'pl_PL',
|
|
563
|
+
pt: 'pt_PT',
|
|
564
|
+
ru: 'ru_RU',
|
|
565
|
+
tr: 'tr_TR',
|
|
566
|
+
uk: 'uk_UA',
|
|
567
|
+
zh: 'zh_CN',
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
/** og:locale (`language_TERRITORY`) of a storefront language, when it is known. */
|
|
571
|
+
export function storefrontOpenGraphLocale(locale: string): string | undefined {
|
|
572
|
+
return openGraphRegions[locale.toLowerCase().split(/[-_]/)[0]!];
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* The same page in every storefront language (hreflang), for a page with a
|
|
577
|
+
* canonical address: the canonical address with each language's `?locale=`,
|
|
578
|
+
* as the sitemap lists them. Search engines that ignore the sitemap's
|
|
579
|
+
* language links (Yandex) read these. A single language gives none.
|
|
580
|
+
*/
|
|
581
|
+
export function storefrontAlternateLinks(
|
|
582
|
+
canonical: string | undefined,
|
|
583
|
+
locales: string[],
|
|
584
|
+
): { hreflang: string; href: string }[] {
|
|
585
|
+
const codes = [
|
|
586
|
+
...new Set(
|
|
587
|
+
locales
|
|
588
|
+
.map((code) => code.trim())
|
|
589
|
+
.filter((code) => /^[a-z]{2,3}(?:-[a-z0-9]{2,8})*$/i.test(code)),
|
|
590
|
+
),
|
|
591
|
+
];
|
|
592
|
+
if (!canonical || codes.length < 2) {
|
|
593
|
+
return [];
|
|
594
|
+
}
|
|
595
|
+
return codes.map((code) => {
|
|
596
|
+
const url = new URL(canonical);
|
|
597
|
+
url.searchParams.set('locale', code);
|
|
598
|
+
return { hreflang: code, href: url.toString() };
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* A backend date (`d.m.Y`, e.g. `22.09.2026`) as an ISO 8601 date
|
|
604
|
+
* (`2026-09-22`); anything else gives `undefined`. A date without a time
|
|
605
|
+
* cannot disagree with the visible date in another time zone.
|
|
606
|
+
*/
|
|
607
|
+
export function storefrontIsoDate(
|
|
608
|
+
value: string | null | undefined,
|
|
609
|
+
): string | undefined {
|
|
610
|
+
const match = /^(\d{2})\.(\d{2})\.(\d{4})$/.exec((value ?? '').trim());
|
|
611
|
+
return match ? `${match[3]}-${match[2]}-${match[1]}` : undefined;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* schema.org BlogPosting of a journal article (Google "Article" structured
|
|
616
|
+
* data): headline, cover, dates, and the store as author and publisher.
|
|
617
|
+
*/
|
|
618
|
+
export function storefrontArticleData(input: {
|
|
619
|
+
canonical: string;
|
|
620
|
+
origin: string;
|
|
621
|
+
headline: string;
|
|
622
|
+
description?: string;
|
|
623
|
+
image?: string;
|
|
624
|
+
published?: string;
|
|
625
|
+
modified?: string;
|
|
626
|
+
locale: string;
|
|
627
|
+
storeName?: string;
|
|
628
|
+
}): Record<string, unknown> {
|
|
629
|
+
const store = {
|
|
630
|
+
'@type': 'Organization',
|
|
631
|
+
name: input.storeName || new URL(input.origin).hostname,
|
|
632
|
+
url: `${input.origin}/`,
|
|
633
|
+
};
|
|
634
|
+
const modified = input.modified || input.published;
|
|
635
|
+
return {
|
|
636
|
+
'@context': 'https://schema.org',
|
|
637
|
+
'@type': 'BlogPosting',
|
|
638
|
+
'@id': `${input.canonical}#article`,
|
|
639
|
+
mainEntityOfPage: input.canonical,
|
|
640
|
+
url: input.canonical,
|
|
641
|
+
headline: input.headline.slice(0, 110),
|
|
642
|
+
...(input.description ? { description: input.description } : {}),
|
|
643
|
+
...(input.image ? { image: [input.image] } : {}),
|
|
644
|
+
...(input.published ? { datePublished: input.published } : {}),
|
|
645
|
+
...(modified ? { dateModified: modified } : {}),
|
|
646
|
+
inLanguage: input.locale,
|
|
647
|
+
author: store,
|
|
648
|
+
publisher: store,
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* The store's icon (App Load `logos.ico`) as `<link rel="icon">` tags: search
|
|
654
|
+
* engines read the icon from the home page. Only a complete http(s) address
|
|
655
|
+
* is used; the type is left out, so it cannot disagree with the file.
|
|
656
|
+
*/
|
|
657
|
+
export function storefrontIconLinks(
|
|
658
|
+
icon: string | null | undefined,
|
|
659
|
+
): { key: string; rel: 'icon'; href: string }[] {
|
|
660
|
+
const href = storefrontAbsoluteUrl(icon, '');
|
|
661
|
+
return href ? [{ key: 'icon', rel: 'icon', href }] : [];
|
|
662
|
+
}
|
|
@@ -71,3 +71,13 @@ export function appLoadResult(
|
|
|
71
71
|
loadedAt: new Date().toISOString(),
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Whether App Load refused the request's language (`?lang=` of a language the
|
|
77
|
+
* storefront does not have): the backend answers it with field errors and
|
|
78
|
+
* HTTP 452. The language is the only client value App Load reads, so the
|
|
79
|
+
* storefront loads again without it.
|
|
80
|
+
*/
|
|
81
|
+
export function appLoadRejectedLocale(failure: AppLoadFailure): boolean {
|
|
82
|
+
return failure.kind === 'validation' || failure.httpStatus === 452;
|
|
83
|
+
}
|