From fb2cedd47c2dbec91f7212222e3c0afa816351e2 Mon Sep 17 00:00:00 2001 From: julientison Date: Thu, 9 Jan 2025 11:02:54 +0100 Subject: [PATCH 1/3] feat: improved isHomePage using currentPage --- composables/use-home-page.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composables/use-home-page.ts b/composables/use-home-page.ts index fd03997a..ae9e4767 100644 --- a/composables/use-home-page.ts +++ b/composables/use-home-page.ts @@ -6,8 +6,9 @@ export async function useHomePage() { const isHomePage = computed(() => { const url = homeItem.value?.url + const currentPage = useCurrentPage() - if (url) return route.path === url + if (url) return currentPage.value.alternateLinks?.[0]?.url === url // If there is an error then maybe the API could not be reached. // Therefore, the common content will be empty. @@ -16,7 +17,7 @@ export async function useHomePage() { const locales: string[] = $i18n?.localeCodes?.value || [] // test `/` or `/{locale}` depending on the current locale and the i18n route strategy from Nuxt i18n or Roadiz - return route.path === '/' || locales.map(locale => joinURL('/', locale)).includes(joinURL('/', route.path)) + return currentPage.value.alternateLinks?.[0]?.url === '/' || locales.map(locale => joinURL('/', locale)).includes(joinURL('/', route.path)) }) const homePagePath = computed(() => { From fac85a702b4e582d454869acc34b1b1bfcae041b Mon Sep 17 00:00:00 2001 From: julientison Date: Thu, 9 Jan 2025 12:01:21 +0100 Subject: [PATCH 2/3] feat: improved isHomePage using webResponse url of currentPage --- composables/use-home-page.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/composables/use-home-page.ts b/composables/use-home-page.ts index ae9e4767..20f8428c 100644 --- a/composables/use-home-page.ts +++ b/composables/use-home-page.ts @@ -2,13 +2,12 @@ import { joinURL } from 'ufo' export async function useHomePage() { const { homeItem } = await useCommonContent() - const route = useRoute() const isHomePage = computed(() => { const url = homeItem.value?.url const currentPage = useCurrentPage() - if (url) return currentPage.value.alternateLinks?.[0]?.url === url + if (url) return currentPage.value.webResponse?.item?.url === url // If there is an error then maybe the API could not be reached. // Therefore, the common content will be empty. @@ -17,7 +16,7 @@ export async function useHomePage() { const locales: string[] = $i18n?.localeCodes?.value || [] // test `/` or `/{locale}` depending on the current locale and the i18n route strategy from Nuxt i18n or Roadiz - return currentPage.value.alternateLinks?.[0]?.url === '/' || locales.map(locale => joinURL('/', locale)).includes(joinURL('/', route.path)) + return currentPage.value.webResponse?.item?.url === '/' || (currentPage.value.webResponse && locales.map(locale => joinURL('/', locale)).includes(joinURL('/', currentPage.value.webResponse.item.url))) }) const homePagePath = computed(() => { From 9880451d0fb40678b183fa15384ffd3b2eb14463 Mon Sep 17 00:00:00 2001 From: julientison Date: Thu, 9 Jan 2025 15:28:40 +0100 Subject: [PATCH 3/3] feat(use-home-page): add currentPageUrl variable --- composables/use-home-page.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composables/use-home-page.ts b/composables/use-home-page.ts index 20f8428c..119c6630 100644 --- a/composables/use-home-page.ts +++ b/composables/use-home-page.ts @@ -5,9 +5,9 @@ export async function useHomePage() { const isHomePage = computed(() => { const url = homeItem.value?.url - const currentPage = useCurrentPage() + const currentPageUrl = useCurrentPage().value.webResponse?.item?.url - if (url) return currentPage.value.webResponse?.item?.url === url + if (url) return currentPageUrl === url // If there is an error then maybe the API could not be reached. // Therefore, the common content will be empty. @@ -16,7 +16,7 @@ export async function useHomePage() { const locales: string[] = $i18n?.localeCodes?.value || [] // test `/` or `/{locale}` depending on the current locale and the i18n route strategy from Nuxt i18n or Roadiz - return currentPage.value.webResponse?.item?.url === '/' || (currentPage.value.webResponse && locales.map(locale => joinURL('/', locale)).includes(joinURL('/', currentPage.value.webResponse.item.url))) + return currentPageUrl === '/' || (currentPageUrl && locales.map(locale => joinURL('/', locale)).includes(joinURL('/', currentPageUrl))) }) const homePagePath = computed(() => {