Skip to content

Commit

Permalink
feat(ceo): create dynamic sitemap
Browse files Browse the repository at this point in the history
closes #544
  • Loading branch information
mateusfg7 committed Jun 19, 2023
1 parent 4bc4c46 commit 97ca8ac
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { MetadataRoute } from 'next'
import { getUniqueCategoryList } from '@/shared/lib/categories'
import { getUniqueTagListFromPosts } from '@/shared/lib/tags'
import { host } from '@/shared/lib/webserver-constants'
import { allPosts } from 'contentlayer/generated'

export default function sitemap(): MetadataRoute.Sitemap {
const commonRoutes = ['', 'categories', 'feed', 'tag', 'portifolio'].map(
route => ({
url: `${host}/${route}`,
lastModified: new Date().toISOString()
})
)

const tags = getUniqueTagListFromPosts().map(tag => ({
url: `${host}/tag/${tag}`,
lastModified: new Date().toISOString()
}))
const categories = getUniqueCategoryList().map(category => ({
url: `${host}/categories/${category}`,
lastModified: new Date().toISOString()
}))
const posts = allPosts.map(post => ({
url: `${host}/post/${post.id}`,
lastModified: new Date(post.date).toISOString()
}))

return [
...commonRoutes,
...tags,
...categories,
...posts,
{
url: `${host}/author/mateusfg7`,
lastModified: new Date().toISOString()
}
]
}

0 comments on commit 97ca8ac

Please sign in to comment.