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

🐛 Fix canonical URLs + add missing language alternate #725

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function generateMetadata() {
'Découvrez les relais de Nos Gestes Climat : organisations, collectivités, médias, influenceurs, etc.'
),
alternates: {
canonical: '/relais',
canonical: '/nos-relais',
},
})
}
Expand Down
3 changes: 1 addition & 2 deletions src/app/(simulation)/(large-layout)/classements/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getServerTranslation } from '@/helpers/getServerTranslation'
import { getMetadataObject } from '@/helpers/metadata/getMetadataObject'
import { linkToClassement } from '@/helpers/navigation/classementPages'
import Groups from './_components/Groups'
import Organisations from './_components/Organisations'

Expand All @@ -15,7 +14,7 @@ export async function generateMetadata() {
'Comparez vos résultats avec votre famille ou un groupe d’amis.'
),
alternates: {
canonical: linkToClassement,
canonical: '/classements',
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { getMetadataObject } from '@/helpers/metadata/getMetadataObject'
import { PropsWithChildren } from 'react'
import FiltersProvider from './_components/FiltersProvider'

export async function generateMetadata() {
export async function generateMetadata({
params,
}: {
params: { orgaSlug: string; pollSlug: string }
}) {
const { t } = await getServerTranslation()

return getMetadataObject({
Expand All @@ -12,7 +16,7 @@ export async function generateMetadata() {
'Accédez à des services sur mesure pour sensibiliser vos partenaires au sein de votre organisation.'
),
alternates: {
canonical: '/',
canonical: `/organisations/${params.orgaSlug}/campagnes/${params.pollSlug}`,
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { getServerTranslation } from '@/helpers/getServerTranslation'
import { getMetadataObject } from '@/helpers/metadata/getMetadataObject'
import { PropsWithChildren } from 'react'

export async function generateMetadata() {
export async function generateMetadata({
params,
}: {
params: { orgaSlug: string }
}) {
const { t } = await getServerTranslation()

return getMetadataObject({
Expand All @@ -11,7 +15,7 @@ export async function generateMetadata() {
'Accédez à des services sur mesure pour sensibiliser vos partenaires au sein de votre organisation.'
),
alternates: {
canonical: '/',
canonical: `/organisations/${params.orgaSlug}`,
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { getServerTranslation } from '@/helpers/getServerTranslation'
import { getMetadataObject } from '@/helpers/metadata/getMetadataObject'
import { PropsWithChildren } from 'react'

export async function generateMetadata() {
export async function generateMetadata({
params,
}: {
params: { orgaSlug: string }
}) {
const { t } = await getServerTranslation()

return getMetadataObject({
Expand All @@ -12,7 +16,7 @@ export async function generateMetadata() {
'Accédez à des services sur mesure pour sensibiliser vos partenaires au sein de votre organisation.'
),
alternates: {
canonical: '/',
canonical: `/organisations/${params.orgaSlug}/parametres`,
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function generateMetadata() {
'Accédez à des services sur mesure pour sensibiliser vos partenaires au sein de votre organisation.'
),
alternates: {
canonical: '/',
canonical: '/organisations/connexion',
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function generateMetadata() {
'Accédez à des services sur mesure pour sensibiliser vos partenaires au sein de votre organisation.'
),
alternates: {
canonical: '/',
canonical: '/organisations/creer',
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function generateMetadata() {
'Accédez à des services sur mesure pour sensibiliser vos partenaires au sein de votre organisation.'
),
alternates: {
canonical: '/',
canonical: '/organisations/demander-demo',
},
robots: noIndexObject,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function generateMetadata() {
'Comprenez comment calculer votre empreinte sur le climat en 10min chrono.'
),
alternates: {
canonical: '/infos',
canonical: '/organisations',
},
})
}
Expand Down
15 changes: 4 additions & 11 deletions src/helpers/metadata/getMetadataObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,20 @@ export function getMetadataObject({
let alternatesWithLanguages = null

if (alternates) {
let canonical = alternates.canonical

// We remove the locale from the url (it should not be here anyway, but just in case)
locales.map((locale) => {
if (alternates.canonical.startsWith(`/${locale}`)) {
canonical = alternates.canonical.slice(3)
}
})
const canonical = alternates.canonical

// We set the alternates url for each language
const languages: Record<string, string> = {}
locales.map((locale) => {
if (locale === 'fr') return

locales.map((locale) => {
languages[locale] =
`${BASE_URL}${locale === 'fr' ? '' : `/${locale}`}${canonical}`
})

// We return the alternates object with the canonical url and the languages alternates
alternatesWithLanguages = {
canonical: BASE_URL + canonical,
canonical:
BASE_URL + (locale === 'fr' ? canonical : `/${locale}${canonical}`),
languages,
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/locales/ui/ui-en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -917,10 +917,10 @@ entries:
'ex : Campagne 2024, Classe de 6ème A, etc.': e.g. Campagne 2024, Classe de 6ème A, etc.
Sans titre: Untitled
Masquer les autres campagnes: Hide other campaigns
Date (récentes > anciennes): Date (recent &gt; old)
Date (anciennes > récentes): Date (old &gt; recent)
Date (récentes > anciennes): Date (recent > old)
Date (anciennes > récentes): Date (old > recent)
Campagne créée par <2>{pollData?.organisationName}</2>, le: Campaign created by <2>{pollData?.organisationName}</2>, on
Nom (A > Z): Name (A &gt; Z)
Nom (A > Z): Name (A > Z)
Nom (Z > A): Name (Z &gt; A)
Voir toutes les campagnes: See all campaigns
(définissez un titre dans les paramètres): (define a title in the parameters)
Expand Down
8 changes: 4 additions & 4 deletions src/locales/ui/ui-es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -913,12 +913,12 @@ entries:
Masquer les autres campagnes: Ocultar otras campañas
Sans titre: Sin título
(définissez un titre dans les paramètres): (defina un título en los parámetros)
Date (anciennes > récentes): Fecha (antigua &gt; reciente)
Date (anciennes > récentes): Fecha (antigua > reciente)
Campagne créée par <2>{pollData?.organisationName}</2>, le: Campaña creada por <2>{pollData?.organisationName}</2>, el
Répartition des empreintes carbone: Desglose de la huella de carbono
Nom (A > Z): Nombre (A &gt; Z)
Date (récentes > anciennes): Fecha (reciente &gt; antigua)
Nom (Z > A): Nombre (Z &gt; A)
Nom (A > Z): Nombre (A > Z)
Date (récentes > anciennes): Fecha (reciente > antigua)
Nom (Z > A): Nombre (Z > A)
Accéder aux ressources: Acceso a los recursos
Les ressources de l'ABC: Recursos ABC
Tableau de bord: Cuadro de mandos
Expand Down
Loading