Skip to content

Commit

Permalink
fix: Canonical links
Browse files Browse the repository at this point in the history
You must have a canonical link for each language.
  • Loading branch information
gorzelinski committed Nov 10, 2024
1 parent d12bd32 commit 7179e32
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 13 deletions.
3 changes: 2 additions & 1 deletion app/[lang]/about/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export async function generateMetadata({
}: PageProps): Promise<Metadata> {
const { layout, page } = await getDictionary(lang)
const languages = generateAlternateLinks(LINKS.about)
const canonical = localizePath(LINKS.about, lang)
const metaImageParams = {
theme: getCookie(COOKIES.theme, { cookies }) as Theme,
title: page.about.metadata.title,
Expand All @@ -43,7 +44,7 @@ export async function generateMetadata({
title: page.about.metadata.title,
description: page.about.metadata.description,
alternates: {
canonical: LINKS.about,
canonical,
languages
},
openGraph: {
Expand Down
2 changes: 1 addition & 1 deletion app/[lang]/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export async function generateMetadata({
}: NestedPageProps): Promise<Metadata> {
const { frontmatter } = await getMDX<'post'>(LINKS.blog, slug, lang)
const { layout, page } = await getDictionary(lang)
const canonical = `${LINKS.blog}${slug}/`
const canonical = localizePath(`${LINKS.blog}${slug}/`, lang)
const languages = generateAlternateLinks(canonical)
const metaImageParams = {
theme: getCookie(COOKIES.theme, { cookies }) as Theme,
Expand Down
5 changes: 3 additions & 2 deletions app/[lang]/blog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { WebPage, WithContext } from 'schema-dts'
import { PageProps, Theme } from '@/types'
import { COOKIES, LINKS } from '@/constants'
import { getDictionary, getMDXes } from '@/scripts'
import { generateAlternateLinks, getMetaImage } from '@/lib'
import { generateAlternateLinks, getMetaImage, localizePath } from '@/lib'
import { openGraph, twitter } from '@/app/shared-metadata'
import { H1, Header, Newsletter, Post, Section } from '@/design-system'
import { small } from '@/design-system/elements/small'
Expand All @@ -15,6 +15,7 @@ export async function generateMetadata({
}: PageProps): Promise<Metadata> {
const { layout, page } = await getDictionary(lang)
const languages = generateAlternateLinks(LINKS.blog)
const canonical = localizePath(LINKS.blog, lang)
const metaImageParams = {
theme: getCookie(COOKIES.theme, { cookies }) as Theme,
title: page.blog.metadata.title,
Expand All @@ -26,7 +27,7 @@ export async function generateMetadata({
title: page.blog.metadata.title,
description: page.blog.metadata.description,
alternates: {
canonical: LINKS.blog,
canonical,
languages
},
openGraph: {
Expand Down
3 changes: 2 additions & 1 deletion app/[lang]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ export async function generateMetadata({
}: PageProps): Promise<Metadata> {
const { page } = await getDictionary(lang)
const languages = generateAlternateLinks(LINKS.home)
const canonical = localizePath(LINKS.home, lang)

return {
title: page.home.metadata.title,
description: page.home.metadata.description,
alternates: {
canonical: LINKS.home,
canonical,
languages
}
}
Expand Down
9 changes: 7 additions & 2 deletions app/[lang]/portfolio/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { NestedPageProps, Theme } from '@/types'
import { COOKIES, LINKS } from '@/constants'
import { i18n } from '@/i18n.config'
import { createPagination, getDictionary, getMDX, getSlugs } from '@/scripts'
import { generateAlternateLinks, getAbsoluteURL, getMetaImage } from '@/lib'
import {
generateAlternateLinks,
getAbsoluteURL,
getMetaImage,
localizePath
} from '@/lib'
import { openGraph, twitter } from '@/app/shared-metadata'
import { Box, Grid, VStack } from '@/styled-system/jsx'
import {
Expand Down Expand Up @@ -39,7 +44,7 @@ export async function generateMetadata({
}: NestedPageProps): Promise<Metadata> {
const { frontmatter } = await getMDX<'project'>(LINKS.portfolio, slug, lang)
const { layout, page } = await getDictionary(lang)
const canonical = `${LINKS.portfolio}${slug}/`
const canonical = localizePath(`${LINKS.portfolio}${slug}/`, lang)
const languages = generateAlternateLinks(canonical)
const metaImageParams = {
theme: getCookie(COOKIES.theme, { cookies }) as Theme,
Expand Down
5 changes: 3 additions & 2 deletions app/[lang]/portfolio/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { WebPage, WithContext } from 'schema-dts'
import { PageProps, Theme } from '@/types'
import { COOKIES, LINKS } from '@/constants'
import { getDictionary, getMDXes } from '@/scripts'
import { generateAlternateLinks, getMetaImage } from '@/lib'
import { generateAlternateLinks, getMetaImage, localizePath } from '@/lib'
import { openGraph, twitter } from '@/app/shared-metadata'
import { H1, Header, Newsletter, Project, Section } from '@/design-system'
import { small } from '@/design-system/elements/small'
Expand All @@ -15,6 +15,7 @@ export async function generateMetadata({
}: PageProps): Promise<Metadata> {
const { layout, page } = await getDictionary(lang)
const languages = generateAlternateLinks(LINKS.portfolio)
const canonical = localizePath(LINKS.portfolio, lang)
const metaImageParams = {
theme: getCookie(COOKIES.theme, { cookies }) as Theme,
title: page.portfolio.metadata.title,
Expand All @@ -26,7 +27,7 @@ export async function generateMetadata({
title: page.portfolio.metadata.title,
description: page.portfolio.metadata.description,
alternates: {
canonical: LINKS.portfolio,
canonical,
languages
},
openGraph: {
Expand Down
5 changes: 3 additions & 2 deletions app/[lang]/subscription-confirmed/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { WebPage, WithContext } from 'schema-dts'
import { PageProps, Theme } from '@/types'
import { COOKIES, LINKS } from '@/constants'
import { getDictionary } from '@/scripts'
import { generateAlternateLinks, getMetaImage } from '@/lib'
import { generateAlternateLinks, getMetaImage, localizePath } from '@/lib'
import { openGraph, twitter } from '@/app/shared-metadata'
import { Confetti, H1, P, Section } from '@/design-system'

Expand All @@ -14,6 +14,7 @@ export async function generateMetadata({
}: PageProps): Promise<Metadata> {
const { layout, page } = await getDictionary(lang)
const languages = generateAlternateLinks(LINKS.subscriptionConfirmed)
const canonical = localizePath(LINKS.subscriptionConfirmed, lang)
const metaImageParams = {
theme: getCookie(COOKIES.theme, { cookies }) as Theme,
title: page.subscriptionConfirmed.metadata.title,
Expand All @@ -25,7 +26,7 @@ export async function generateMetadata({
title: page.subscriptionConfirmed.metadata.title,
description: page.subscriptionConfirmed.metadata.description,
alternates: {
canonical: LINKS.subscriptionConfirmed,
canonical,
languages
},
openGraph: {
Expand Down
5 changes: 3 additions & 2 deletions app/[lang]/uses/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { WebPage, WithContext } from 'schema-dts'
import { PageProps, Theme } from '@/types'
import { COOKIES, LINKS } from '@/constants'
import { getMDX, getDictionary } from '@/scripts'
import { generateAlternateLinks, getMetaImage } from '@/lib'
import { generateAlternateLinks, getMetaImage, localizePath } from '@/lib'
import { openGraph, twitter } from '@/app/shared-metadata'
import {
Article,
Expand All @@ -22,6 +22,7 @@ export async function generateMetadata({
}: PageProps): Promise<Metadata> {
const { layout, page } = await getDictionary(lang)
const languages = generateAlternateLinks(LINKS.uses)
const canonical = localizePath(LINKS.uses, lang)
const metaImageParams = {
theme: getCookie(COOKIES.theme, { cookies }) as Theme,
title: page.uses.metadata.title,
Expand All @@ -33,7 +34,7 @@ export async function generateMetadata({
title: page.uses.metadata.title,
description: page.uses.metadata.description,
alternates: {
canonical: LINKS.uses,
canonical,
languages
},
openGraph: {
Expand Down

0 comments on commit 7179e32

Please sign in to comment.