Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: robots settings #842

Merged
merged 12 commits into from
Dec 5, 2024
2 changes: 2 additions & 0 deletions apps/web/composables/useStructuredData/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ref<boolean>>;
setLogoMeta: SetLogoMeta;
setProductMetaData: SetProductMetaData;
setProductRobotsMetaData: SetProductRobotsMetaData;
}

export type useStructuredDataReturn = () => UseStructuredData;
23 changes: 22 additions & 1 deletion apps/web/composables/useStructuredData/useStructuredData.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -185,9 +185,30 @@ export const useStructuredData: useStructuredDataReturn = () => {
state.value.loading = false;
};

const setProductRobotsMetaData: SetProductRobotsMetaData = (product: Product) => {
state.value.loading = true;

const route = useRoute();
let robotsContent = product.seoSettings?.robots || '';

if (
(!product.seoSettings?.forceRobotsValue && Object.keys(route.query).length > 0) ||
product.seoSettings?.forceNoIndex
) {
robotsContent = 'noindex';
}

useHead({
meta: [{ name: 'robots', content: robotsContent }],
});

state.value.loading = false;
};

return {
setLogoMeta,
setProductMetaData,
setProductRobotsMetaData,
...toRefs(state.value),
};
};
7 changes: 5 additions & 2 deletions apps/web/pages/product/[slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 },
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/changelog_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Added more manufacturer information to legal details drawer.
- Add login redirect on category "after login" visibility.
- The Homepage components are now split in edit block s
- Added robots settings for SEO config.

### 👷 Changed

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Loading