From b323d55f1bbf138bfe3f4cf2de4c3384edaa242f Mon Sep 17 00:00:00 2001 From: plentydev Date: Thu, 28 Nov 2024 09:50:51 +0200 Subject: [PATCH 1/7] feat: robots settings --- .../composables/useStructuredData/types.ts | 2 ++ .../useStructuredData/useStructuredData.ts | 24 ++++++++++++++++++- apps/web/pages/product/[slug].vue | 7 ++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/apps/web/composables/useStructuredData/types.ts b/apps/web/composables/useStructuredData/types.ts index 15ef526a3..b4366e68e 100644 --- a/apps/web/composables/useStructuredData/types.ts +++ b/apps/web/composables/useStructuredData/types.ts @@ -5,11 +5,13 @@ export interface UseStructuredDataState { export type SetProductMetaData = (product: Product, categoryTree: CategoryTreeItem) => void; export type SetLogoMeta = () => void; +export type SetProductRobotsMetaData = (product: Product) => void; export interface UseStructuredData { loading: Readonly>; setLogoMeta: SetLogoMeta; setProductMetaData: SetProductMetaData; + setProductRobotsMetaData: SetProductRobotsMetaData; } export type useStructuredDataReturn = () => UseStructuredData; diff --git a/apps/web/composables/useStructuredData/useStructuredData.ts b/apps/web/composables/useStructuredData/useStructuredData.ts index 6d6f8e1f7..ac01b76b2 100644 --- a/apps/web/composables/useStructuredData/useStructuredData.ts +++ b/apps/web/composables/useStructuredData/useStructuredData.ts @@ -1,5 +1,5 @@ import type { useStructuredDataReturn } from './types'; -import type { SetLogoMeta, SetProductMetaData, UseStructuredDataState } from './types'; +import type { SetLogoMeta, SetProductMetaData, SetProductRobotsMetaData, UseStructuredDataState } from './types'; import { categoryTreeGetters, productGetters, reviewGetters, productSeoSettingsGetters } from '@plentymarkets/shop-api'; import type { CategoryTreeItem, Product } from '@plentymarkets/shop-api'; import { useProductReviews } from '../useProductReviews'; @@ -185,9 +185,31 @@ export const useStructuredData: useStructuredDataReturn = () => { state.value.loading = false; }; + const setProductRobotsMetaData: SetProductRobotsMetaData = (product: Product) => { + state.value.loading = true; + + const route = useRoute() + let robotsContent: string | undefined = ''; + + if (!product.seoSettings?.forceRobotsValue && Object.keys(route.query).length > 0) { + robotsContent = 'noindex' + } else { + robotsContent = product.seoSettings?.robots; + } + + useHead({ + meta: [ + { name: 'robots', content: robotsContent } + ], + }); + + state.value.loading = false + } + return { setLogoMeta, setProductMetaData, + setProductRobotsMetaData, ...toRefs(state.value), }; }; diff --git a/apps/web/pages/product/[slug].vue b/apps/web/pages/product/[slug].vue index 8f4990fd0..e2c8d5fc6 100644 --- a/apps/web/pages/product/[slug].vue +++ b/apps/web/pages/product/[slug].vue @@ -57,7 +57,7 @@ definePageMeta({ const { t } = useI18n(); const route = useRoute(); const { setCurrentProduct } = useProducts(); -const { setProductMetaData } = useStructuredData(); +const { setProductMetaData, setProductRobotsMetaData } = useStructuredData(); const { buildProductLanguagePath } = useLocalization(); const { addModernImageExtensionForGallery } = useModernImage(); const { productParams, productId } = createProductParams(route.params); @@ -114,7 +114,10 @@ watch( const categoryTree = categoriesTree.find( (categoryTree) => categoryTreeGetters.getId(categoryTree) === productCategoryId, ); - if (categoryTree) setProductMetaData(product.value, categoryTree); + if (categoryTree) { + setProductMetaData(product.value, categoryTree); + setProductRobotsMetaData(product.value); + } } }, { immediate: true }, From 6757d4bc8eccb6af23920d6fc4eaabb8904e71e0 Mon Sep 17 00:00:00 2001 From: plentydev Date: Thu, 28 Nov 2024 14:21:30 +0200 Subject: [PATCH 2/7] add robots conditions --- apps/web/composables/useStructuredData/useStructuredData.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/web/composables/useStructuredData/useStructuredData.ts b/apps/web/composables/useStructuredData/useStructuredData.ts index ac01b76b2..9f7c2ac43 100644 --- a/apps/web/composables/useStructuredData/useStructuredData.ts +++ b/apps/web/composables/useStructuredData/useStructuredData.ts @@ -191,7 +191,10 @@ export const useStructuredData: useStructuredDataReturn = () => { const route = useRoute() let robotsContent: string | undefined = ''; - if (!product.seoSettings?.forceRobotsValue && Object.keys(route.query).length > 0) { + if ( + (!product.seoSettings?.forceRobotsValue && Object.keys(route.query).length > 0) || + product.seoSettings?.forceNoIndex + ) { robotsContent = 'noindex' } else { robotsContent = product.seoSettings?.robots; From 4555ca5e5df8d5a2561bdad8244b5cce2098558a Mon Sep 17 00:00:00 2001 From: plentydev Date: Thu, 28 Nov 2024 14:26:00 +0200 Subject: [PATCH 3/7] ran prettier --- .../useStructuredData/useStructuredData.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/apps/web/composables/useStructuredData/useStructuredData.ts b/apps/web/composables/useStructuredData/useStructuredData.ts index 9f7c2ac43..9dbb82cce 100644 --- a/apps/web/composables/useStructuredData/useStructuredData.ts +++ b/apps/web/composables/useStructuredData/useStructuredData.ts @@ -188,26 +188,24 @@ export const useStructuredData: useStructuredDataReturn = () => { const setProductRobotsMetaData: SetProductRobotsMetaData = (product: Product) => { state.value.loading = true; - const route = useRoute() + const route = useRoute(); let robotsContent: string | undefined = ''; if ( - (!product.seoSettings?.forceRobotsValue && Object.keys(route.query).length > 0) || - product.seoSettings?.forceNoIndex + (!product.seoSettings?.forceRobotsValue && Object.keys(route.query).length > 0) || + product.seoSettings?.forceNoIndex ) { - robotsContent = 'noindex' + robotsContent = 'noindex'; } else { robotsContent = product.seoSettings?.robots; } useHead({ - meta: [ - { name: 'robots', content: robotsContent } - ], + meta: [{ name: 'robots', content: robotsContent }], }); - state.value.loading = false - } + state.value.loading = false; + }; return { setLogoMeta, From f04a8fc2f22f62a39251a8896ce790a51322d789 Mon Sep 17 00:00:00 2001 From: plentydev Date: Fri, 29 Nov 2024 10:47:45 +0200 Subject: [PATCH 4/7] fix lint error --- .../composables/useStructuredData/useStructuredData.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/apps/web/composables/useStructuredData/useStructuredData.ts b/apps/web/composables/useStructuredData/useStructuredData.ts index 9dbb82cce..82bfa061d 100644 --- a/apps/web/composables/useStructuredData/useStructuredData.ts +++ b/apps/web/composables/useStructuredData/useStructuredData.ts @@ -191,14 +191,11 @@ export const useStructuredData: useStructuredDataReturn = () => { const route = useRoute(); let robotsContent: string | undefined = ''; - if ( + robotsContent = (!product.seoSettings?.forceRobotsValue && Object.keys(route.query).length > 0) || product.seoSettings?.forceNoIndex - ) { - robotsContent = 'noindex'; - } else { - robotsContent = product.seoSettings?.robots; - } + ? 'noindex' + : product.seoSettings?.robots; useHead({ meta: [{ name: 'robots', content: robotsContent }], From 359d85ec05e62f76b14ae4e551b7063fb1a728af Mon Sep 17 00:00:00 2001 From: plentydev Date: Fri, 29 Nov 2024 10:49:58 +0200 Subject: [PATCH 5/7] add changelog --- docs/changelog/changelog_en.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog/changelog_en.md b/docs/changelog/changelog_en.md index 67efb328a..8d92a851c 100644 --- a/docs/changelog/changelog_en.md +++ b/docs/changelog/changelog_en.md @@ -13,6 +13,7 @@ - Added a warning alert on the checkout if no payment or shipping method is available - Added cookie consent management helper functions read more at https://pwa-docs.plentymarkets.com/guide/how-to/cookie#read-and-react-to-a-registered-cookie. - Added dynamic structured data from the SEO config. +- Added robots settings for SEO config. ### 👷 Changed From 0b3e42cd849fd40a655d137f96f4a020ea73acfd Mon Sep 17 00:00:00 2001 From: abocsan-plenty <129151096+abocsan-plenty@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:32:27 +0200 Subject: [PATCH 6/7] chore: cleanup code --- .../composables/useStructuredData/useStructuredData.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/web/composables/useStructuredData/useStructuredData.ts b/apps/web/composables/useStructuredData/useStructuredData.ts index 82bfa061d..6e7f1b342 100644 --- a/apps/web/composables/useStructuredData/useStructuredData.ts +++ b/apps/web/composables/useStructuredData/useStructuredData.ts @@ -189,13 +189,14 @@ export const useStructuredData: useStructuredDataReturn = () => { state.value.loading = true; const route = useRoute(); - let robotsContent: string | undefined = ''; + let robotsContent = product.seoSettings?.robots || ''; - robotsContent = + if ( (!product.seoSettings?.forceRobotsValue && Object.keys(route.query).length > 0) || product.seoSettings?.forceNoIndex - ? 'noindex' - : product.seoSettings?.robots; + ) { + robotsContent = 'noindex'; + } useHead({ meta: [{ name: 'robots', content: robotsContent }], From 115f8407f33bb03207d6794085b7457b7c73b986 Mon Sep 17 00:00:00 2001 From: abocsan-plenty <129151096+abocsan-plenty@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:40:31 +0200 Subject: [PATCH 7/7] chore: package update --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 28f28ae4a..9bde6b27e 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "lhci:desktop": "lhci collect --config=lighthouserc.desktop.json && lhci assert" }, "dependencies": { - "@plentymarkets/shop-api": "^0.80.0", + "@plentymarkets/shop-api": "^0.82.0", "@types/applepayjs": "^14.0.8", "@types/drift-zoom": "^1.5.2", "@types/googlepay": "^0.7.6", diff --git a/yarn.lock b/yarn.lock index 82c5d426d..413078711 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4237,7 +4237,7 @@ __metadata: "@nuxt/test-utils": ^3.13.1 "@nuxtjs/turnstile": ^0.8.0 "@paypal/paypal-js": 8.1.0 - "@plentymarkets/shop-api": ^0.80.0 + "@plentymarkets/shop-api": ^0.82.0 "@types/applepayjs": ^14.0.8 "@types/drift-zoom": ^1.5.2 "@types/googlepay": ^0.7.6 @@ -4273,14 +4273,14 @@ __metadata: languageName: unknown linkType: soft -"@plentymarkets/shop-api@npm:^0.80.0": - version: 0.80.0 - resolution: "@plentymarkets/shop-api@npm:0.80.0::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40plentymarkets%2Fshop-api%2F0.80.0%2Fdf44b34feda5ca2b4cae25d7e8b2b3958cdbf216" +"@plentymarkets/shop-api@npm:^0.82.0": + version: 0.82.0 + resolution: "@plentymarkets/shop-api@npm:0.82.0::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40plentymarkets%2Fshop-api%2F0.82.0%2F97f84422727740bf3a7d7a6d745a74b825c42f77" dependencies: "@vue-storefront/middleware": ^3.10.0 axios: ^1.7.7 consola: ^3.2.3 - checksum: 7ae9f36a7b312acb0122ba3d3264b6285eb8f0732c2a6c1b4e9bf2293983c149ecfb0fa1b9771d24e2d8d1d3cb8e0bed57b3ae7f5c5ee3d9cfc4cd273c52b366 + checksum: 79989eb34d312e5eda12e66251c70884e53a0d4df761b2f6c4f6e2c963566bcb9245202308e0b688375efb9ecfcd84307f4300a4e60937032441defd92e91955 languageName: node linkType: hard