Skip to content

Commit

Permalink
ADO-171109: Fixed SEO issue and check if alpha/beta site to add corre…
Browse files Browse the repository at this point in the history
…ct breadcrumbs (#1043)

fixed SEO issue and check if alpha/beta site to add correct breadcrumbs
  • Loading branch information
alex-solo authored Apr 11, 2024
1 parent 2715066 commit d8545cd
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 57 deletions.
22 changes: 11 additions & 11 deletions components/Layout/Head.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export const Head: React.VFC<{ title: string }> = ({ title }) => {
const tsln = useTranslation<WebTranslations>()
const altLang = tsln._language === 'en' ? 'fr' : 'en'

const [isCanadaDotCa, setIsCanadaDotCa] = useState(false)
const [isAlpha, setIsAlpha] = useState(false)

useEffect(() => {
if (typeof window !== undefined) {
const hostName = window.location.hostname
setIsCanadaDotCa(hostName.includes('.canada.ca'))
setIsAlpha(hostName.includes('.alpha.service'))
}
}, [])

Expand All @@ -35,28 +35,28 @@ export const Head: React.VFC<{ title: string }> = ({ title }) => {
<link
rel="canonical"
href={
isCanadaDotCa
? `https://estimateursv-oasestimator.service.canada.ca/${tsln._language}${router.pathname}`
: `http://ep-be.alpha.servicecanada.ca/${tsln._language}${router.pathname}`
isAlpha
? `http://ep-be.alpha.service.canada.ca/${tsln._language}${router.pathname}`
: `https://estimateursv-oasestimator.service.canada.ca/${tsln._language}${router.pathname}`
}
/>
<link
rel="alternate"
lang={altLang}
href={
isCanadaDotCa
? `https://estimateursv-oasestimator.service.canada.ca/${altLang}${router.pathname}`
: `https://ep-be.alpha.service.canada.ca/${altLang}${router.pathname}`
isAlpha
? `https://ep-be.alpha.service.canada.ca/${altLang}${router.pathname}`
: `https://estimateursv-oasestimator.service.canada.ca/${altLang}${router.pathname}`
}
/>

<link
rel="alternate"
lang={tsln._language}
href={
isCanadaDotCa
? `https://estimateursv-oasestimator.service.canada.ca/${tsln._language}${router.pathname}`
: `https://ep-be.alpha.service.canada.ca/${tsln._language}${router.pathname}`
isAlpha
? `https://ep-be.alpha.service.canada.ca/${tsln._language}${router.pathname}`
: `https://estimateursv-oasestimator.service.canada.ca/${tsln._language}${router.pathname}`
}
/>
<meta name="keywords" content={tsln.meta.homeKeywords} />
Expand Down
98 changes: 52 additions & 46 deletions components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const Layout: React.VFC<{
title: string
}> = ({ children, title }) => {
const router = useRouter()
const hostname = typeof window !== 'undefined' ? window.location.hostname : ''

// basically returns 'results' or 'resultats' IF, otherwise index or questions in the other locale.
const langToggleLink =
Expand Down Expand Up @@ -53,54 +54,59 @@ export const Layout: React.VFC<{
onSubmit: () => {},
}

const breadcrumbs =
process.env.APP_ENV === 'production'
? [
{
text: tsln.breadcrumb1Title,
link: tsln.breadcrumb1URL,
},
{
text: tsln.breadcrumb2Title,
link: tsln.breadcrumb2URL,
},
{
text: tsln.breadcrumb3Title,
link: tsln.breadcrumb3URL,
},
{
text: tsln.breadcrumb4Title,
link: tsln.breadcrumb4URL,
},
]
: [
{
text: tsln.breadcrumb1aTitle,
link: tsln.breadcrumb1aURL,
},
{
text: tsln.breadcrumb2aTitle,
link: tsln.breadcrumb2aURL,
},
]
const getBreadcrumbs = () => {
const isBeta = !hostname.includes('.alpha.service')
const breadcrumbs =
process.env.APP_ENV === 'production' && isBeta
? [
{
text: tsln.breadcrumb1Title,
link: tsln.breadcrumb1URL,
},
{
text: tsln.breadcrumb2Title,
link: tsln.breadcrumb2URL,
},
{
text: tsln.breadcrumb3Title,
link: tsln.breadcrumb3URL,
},
{
text: tsln.breadcrumb4Title,
link: tsln.breadcrumb4URL,
},
]
: [
{
text: tsln.breadcrumb1aTitle,
link: tsln.breadcrumb1aURL,
},
{
text: tsln.breadcrumb2aTitle,
link: tsln.breadcrumb2aURL,
},
]

if (router.pathname === '/questions') {
breadcrumbs.push({
text: tsln.breadcrumb6Title,
link: tsln.breadcrumb6URL,
})
} else if (
router.pathname === '/results' ||
router.pathname === '/resultats'
) {
breadcrumbs.push({
text: tsln.breadcrumb6Title,
link: tsln.breadcrumb6URL,
}),
if (router.pathname === '/questions') {
breadcrumbs.push({
text: tsln.breadcrumb7Title,
link: tsln.breadcrumb7URL,
text: tsln.breadcrumb6Title,
link: tsln.breadcrumb6URL,
})
} else if (
router.pathname === '/results' ||
router.pathname === '/resultats'
) {
breadcrumbs.push({
text: tsln.breadcrumb6Title,
link: tsln.breadcrumb6URL,
}),
breadcrumbs.push({
text: tsln.breadcrumb7Title,
link: tsln.breadcrumb7URL,
})
}

return breadcrumbs
}

const handleOnClick = () => {
Expand All @@ -122,7 +128,7 @@ export const Layout: React.VFC<{
id="header"
locale={router.locale}
langUrl={langToggleLink}
breadcrumbItems={breadcrumbs}
breadcrumbItems={getBreadcrumbs()}
topNavProps={topnavProps}
headerText={{
globalHeader: tsln.globalHeader,
Expand Down

0 comments on commit d8545cd

Please sign in to comment.