From fc3eb6c0c682a65c57dc6b3ad611ed06079eb796 Mon Sep 17 00:00:00 2001 From: "igor.la" Date: Mon, 9 Dec 2024 14:34:54 +0300 Subject: [PATCH 1/4] Refactor pagination a bit to optimize requests; Optimize SEO; --- frontend/app.vue | 10 ++- frontend/components/search/Pagination.vue | 17 ++++- frontend/components/search/PaginationCity.vue | 29 +++++++++ .../components/search/PaginationCountry.vue | 38 +++++++++-- frontend/i18n/locales/en-GB/meta.ts | 2 + frontend/i18n/locales/ru-RU/meta.ts | 5 +- frontend/pages/city/[city].vue | 58 ++--------------- frontend/pages/country/[country].vue | 65 ++----------------- frontend/pages/index.vue | 28 -------- frontend/utils/ld-json.ts | 2 +- 10 files changed, 100 insertions(+), 154 deletions(-) diff --git a/frontend/app.vue b/frontend/app.vue index da17c00e..251cfb8c 100644 --- a/frontend/app.vue +++ b/frontend/app.vue @@ -33,7 +33,7 @@ const getPath = (path: string) => { const langRefs = locales.value.map((it) => ({ rel: 'alternate', hreflang: it.code, - href: `${config.public.domain}/${it.code}${getPath(route.path)}` + href: `https://${config.public.domain}/${it.code}${getPath(route.path)}` })); useHead({ link: [ @@ -44,17 +44,21 @@ useHead({ }, { rel: 'canonical', - href: `${config.public.domain}/${locale.value}${getPath(route.path)}` + href: `https://${config.public.domain}/${locale.value}${getPath(route.path)}` }, { rel: 'alternate', hreflang: 'x-default', - href: `${config.public.domain}/ru${getPath(route.path)}` + href: `https://${config.public.domain}/ru${getPath(route.path)}` }, ...langRefs ], title: `${t('meta.default_title.first')} | ${t('meta.default_title.second')}`, meta: [ + { + name: 'keywords', + content: t('meta.default_keywords') + }, { name: 'description', content: t('meta.default_description') diff --git a/frontend/components/search/Pagination.vue b/frontend/components/search/Pagination.vue index 64b5a401..f11cfd5b 100644 --- a/frontend/components/search/Pagination.vue +++ b/frontend/components/search/Pagination.vue @@ -55,6 +55,14 @@ const { } }); +useHead({ + script: [ + posterEvents.value + ? getJSONEventList(posterEvents.value.docs, locale.value, route.path) + : undefined + ] +}); + watch( () => route.query, (value) => { @@ -77,7 +85,6 @@ watch( watch( () => posterEvents, (posterEvents) => { - console.log(posterEvents); if (posterEvents.value.page > posterEvents.value.totalPages) { const currentParams = { ...route.query, ...{ page: 1 } }; navigateTo({ query: currentParams }); @@ -188,6 +195,14 @@ watch( /> + + import { countries as supportedCountries } from '../../../common/const/supportedCountries'; import { useRoute } from 'vue-router'; +import { CommonErrorsEnum } from '../../../common/const'; const { t, locale } = useI18n(); @@ -78,6 +79,26 @@ const { } }); +if (errorEvents.value) { + if ( + errorEvents.value.data && + errorEvents.value.data.message === CommonErrorsEnum.CITY_NOT_FOUND + ) { + throw createError({ + statusCode: 404, + data: { message: t(`errors.${CommonErrorsEnum.CITY_NOT_FOUND}`, { city: city }) } + }); + } +} + +useHead({ + script: [ + posterEvents.value + ? getJSONEventList(posterEvents.value.docs, locale.value, route.path) + : undefined + ] +}); + watch( () => route.query, (value) => { @@ -201,6 +222,14 @@ watch( /> + + -import { - declinationCountries, - countries as supportedCountries, - queryToCountryLocaleName, - queryToCountryCode -} from '../../../common/const/supportedCountries'; +import { queryToCountryLocaleName } from '../../../common/const/supportedCountries'; import { useRoute } from 'vue-router'; +import { CommonErrorsEnum } from '../../../common/const'; const { t, locale } = useI18n(); @@ -62,6 +58,28 @@ const { } }); +if (errorEvents.value) { + if ( + errorEvents.value.data && + errorEvents.value.data.message === CommonErrorsEnum.COUNTRY_NOT_FOUND + ) { + throw createError({ + statusCode: 404, + data: { + message: t(`errors.${CommonErrorsEnum.COUNTRY_NOT_FOUND}`, { country: country }) + } + }); + } +} + +useHead({ + script: [ + posterEvents.value + ? getJSONEventList(posterEvents.value.docs, locale.value, route.path) + : undefined + ] +}); + watch( () => route.query, (value) => { @@ -185,6 +203,14 @@ watch( /> + + import { useUserStore } from '../../stores/user.store'; +import { + declinationCountries, + countries as supportedCountries +} from '../../../common/const/supportedCountries'; const route = useRoute(); @@ -7,11 +11,6 @@ const userStore = useUserStore(); const { locale, t } = useI18n(); const mobile = inject('mobile'); -import { CommonErrorsEnum } from '../../../common/const/common-errors'; -import { - declinationCountries, - countries as supportedCountries -} from '../../../common/const/supportedCountries'; const { sendAnalytics } = useSendTrackingEvent(); @@ -50,44 +49,11 @@ getMeta({ }) }); -const dateStart = computed(() => - dateFromQueryToFilter('first', getFirstQuery(route.query.startDate as string)) -); -const dateEnd = computed(() => { - return dateFromQueryToFilter('second', getFirstQuery(route.query.endDate as string)); -}); const tags = computed(() => getFirstQuery(route.query.tags) .split(', ') .filter((item) => item !== '') ); -const { - data: posterEvents, - error: errorEvents, - pending -} = await apiRouter.filters.findEventsByCity.useQuery({ - data: { - city, - query: { - tags, - startDate: dateStart, - endDate: dateEnd - }, - watch: [tags.value, dateStart.value, dateEnd.value] - } -}); - -if (errorEvents.value) { - if ( - errorEvents.value.data && - errorEvents.value.data.message === CommonErrorsEnum.CITY_NOT_FOUND - ) { - throw createError({ - statusCode: 404, - data: { message: t(`errors.${CommonErrorsEnum.CITY_NOT_FOUND}`, { city: city }) } - }); - } -} export type Option = { label: string; value: string }; @@ -118,14 +84,6 @@ const filterCountriesOptions = computed(() => { return filtered; }); -useHead({ - script: [ - posterEvents.value - ? getJSONEventList(posterEvents.value, locale.value, route.path) - : undefined - ] -}); - watch( () => route.query, (value) => { @@ -152,14 +110,6 @@ watch( - - diff --git a/frontend/pages/country/[country].vue b/frontend/pages/country/[country].vue index 3cb5f8de..3f4e9c4c 100644 --- a/frontend/pages/country/[country].vue +++ b/frontend/pages/country/[country].vue @@ -1,5 +1,11 @@