Skip to content

Commit

Permalink
fix: include locales in sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
cesargdm committed Sep 27, 2024
1 parent 6043689 commit d866b8f
Showing 1 changed file with 54 additions and 39 deletions.
93 changes: 54 additions & 39 deletions src/app/sitemap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,57 @@ import { getProjects } from '@/lib/projects'

const urls = ['', 'projects', 'blog', 'contact', 'nfts']

function getProjectSitemapEntry(project: {
slug: string
data: { [key: string]: unknown }
}) {
return {
url: `${BASE_URL}/projects/${project.slug}`,
lastModified:
typeof project.data.date === 'string'
? new Date(project.data.date)
: new Date(),
alternates: {
languages: Object.fromEntries(
LOCALES.map((locale) => [
locale,
`${BASE_URL}/${locale}/projects/${project.slug}`,
]),
),
},
}
}

function getPostsSitemapEntry(post: {
slug: string
data: { [key: string]: unknown }
}) {
return {
url: `${BASE_URL}/blog/${post.slug}`,
lastModified:
typeof post.data.date === 'string'
? new Date(post.data.date)
: new Date(),
alternates: {
languages: Object.fromEntries(
LOCALES.map((locale) => [
locale,
`${BASE_URL}/${locale}/blog/${post.slug}`,
]),
),
},
}
}

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const [projects, posts, nfts = []] = await Promise.all([
getProjects(),
getPosts(),
getNfts(),
])
const [projectsEn, postsEn, projectsEs, postsEs, nfts = []] =
await Promise.all([
getProjects('en'),
getPosts('en'),
getProjects('es'),
getPosts('es'),
getNfts(),
])

return urls
.map((url) => ({
Expand All @@ -25,40 +70,10 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
),
},
}))
.concat(
projects.map((project) => ({
url: `${BASE_URL}/projects/${project.slug}`,
lastModified:
typeof project.data.date === 'string'
? new Date(project.data.date)
: new Date(),
alternates: {
languages: Object.fromEntries(
LOCALES.map((locale) => [
locale,
`${BASE_URL}/${locale}/projects/${project.slug}`,
]),
),
},
})),
)
.concat(
posts.map((post) => ({
url: `${BASE_URL}/blog/${post.slug}`,
lastModified:
typeof post.data.date === 'string'
? new Date(post.data.date)
: new Date(),
alternates: {
languages: Object.fromEntries(
LOCALES.map((locale) => [
locale,
`${BASE_URL}/${locale}/blog/${post.slug}`,
]),
),
},
})),
)
.concat(projectsEn.map(getProjectSitemapEntry))
.concat(projectsEs.map(getProjectSitemapEntry))
.concat(postsEn.map(getPostsSitemapEntry))
.concat(postsEs.map(getPostsSitemapEntry))
.concat(
nfts.map((nft) => ({
url: `${BASE_URL}/nfts/ethereum_${nft.contract}_${nft.identifier}`,
Expand Down

0 comments on commit d866b8f

Please sign in to comment.