Skip to content

Commit

Permalink
sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
PxlSyl authored and PxlSyl committed Apr 30, 2024
1 parent f5a05bc commit db13754
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 41 deletions.
13 changes: 13 additions & 0 deletions app/[locale]/robots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MetadataRoute } from 'next'
import siteMetadata from '@/data/siteMetadata'

export default function robots(): MetadataRoute.Robots {
return {
rules: {
userAgent: '*',
allow: '/',
},
sitemap: `${siteMetadata.siteUrl}/sitemap.xml`,
host: siteMetadata.siteUrl,
}
}
43 changes: 43 additions & 0 deletions app/[locale]/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { MetadataRoute } from 'next'
import { allBlogs } from 'contentlayer/generated'
import siteMetadata from '@/data/siteMetadata'
import { fallbackLng, secondLng } from './i18n/locales'

export default function sitemap(): MetadataRoute.Sitemap {
const locales = [fallbackLng, secondLng]
const siteUrl = siteMetadata.siteUrl

// blog route for english
const firstBlogRoutes = allBlogs
.filter((p) => p.language === fallbackLng)
.map((post) => ({
url: `${siteUrl}/${fallbackLng}/${post.path}`,
lastModified: post.lastmod || post.date,
}))

// blog route for french (or your own second language)
const secondBlogRoutes = allBlogs
.filter((p) => p.language === secondLng)
.map((post) => ({
url: `${siteUrl}/${secondLng}/${post.path}`,
lastModified: post.lastmod || post.date,
}))

const BlogRoutes = [...firstBlogRoutes, ...secondBlogRoutes].map((route) => ({
...route,
}))

// all routes for all locales
const routes = locales.flatMap((locale) => {
return ['', 'blog', 'projects', 'tags', 'about'].map((route) => ({
url: `${siteUrl}/${locale}/${route}`,
lastModified: new Date().toISOString().split('T')[0],
}))
})

const SitemapRoutes: MetadataRoute.Sitemap = [...routes, ...BlogRoutes].map((route) => ({
...route,
}))

return SitemapRoutes
}
6 changes: 0 additions & 6 deletions next-sitemap.config.js

This file was deleted.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"start": "next dev",
"dev": "cross-env INIT_CWD=$PWD next dev",
"build": " next build && cross-env NODE_OPTIONS='--experimental-json-modules' node ./scripts/postbuild.mjs",
"postbuild": "next-sitemap",
"serve": "next start",
"analyze": "cross-env ANALYZE=true next build",
"lint": "next lint --fix --dir pages --dir app --dir components --dir lib --dir layouts --dir scripts",
Expand All @@ -32,7 +31,6 @@
"image-size": "1.1.1",
"next": "14.2.3",
"next-contentlayer2": "0.4.5",
"next-sitemap": "^4.2.3",
"next-themes": "^0.3.0",
"pliny": "0.2.0",
"postcss": "^8.4.33",
Expand Down
34 changes: 1 addition & 33 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1844,13 +1844,6 @@ __metadata:
languageName: node
linkType: hard

"@corex/deepmerge@npm:^4.0.43":
version: 4.0.43
resolution: "@corex/deepmerge@npm:4.0.43"
checksum: c9ac6163e982e81e3216a9fc7c68cd60b9788ad3b23d7387c9e9741b0274b42dfc332ae74b993e550c95e4256be5ce68045fc55d363aa083344392dc95b50d8b
languageName: node
linkType: hard

"@discoveryjs/json-ext@npm:0.5.7":
version: 0.5.7
resolution: "@discoveryjs/json-ext@npm:0.5.7"
Expand Down Expand Up @@ -2455,13 +2448,6 @@ __metadata:
languageName: node
linkType: hard

"@next/env@npm:^13.4.3":
version: 13.5.6
resolution: "@next/env@npm:13.5.6"
checksum: c81bd6052db366407da701e4e431becbc80ef36a88bec7883b0266cdfeb45a7da959d37c38e1a816006cd2da287e5ff5b928bdb71025e3d4aa59e07dea3edd59
languageName: node
linkType: hard

"@next/eslint-plugin-next@npm:14.2.3":
version: 14.2.3
resolution: "@next/eslint-plugin-next@npm:14.2.3"
Expand Down Expand Up @@ -8742,7 +8728,7 @@ __metadata:
languageName: node
linkType: hard

"minimist@npm:^1.2.0, minimist@npm:^1.2.6, minimist@npm:^1.2.8":
"minimist@npm:^1.2.0, minimist@npm:^1.2.6":
version: 1.2.8
resolution: "minimist@npm:1.2.8"
checksum: 908491b6cc15a6c440ba5b22780a0ba89b9810e1aea684e253e43c4e3b8d56ec1dcdd7ea96dde119c29df59c936cde16062159eae4225c691e19c70b432b6e6f
Expand Down Expand Up @@ -8939,23 +8925,6 @@ __metadata:
languageName: node
linkType: hard

"next-sitemap@npm:^4.2.3":
version: 4.2.3
resolution: "next-sitemap@npm:4.2.3"
dependencies:
"@corex/deepmerge": "npm:^4.0.43"
"@next/env": "npm:^13.4.3"
fast-glob: "npm:^3.2.12"
minimist: "npm:^1.2.8"
peerDependencies:
next: "*"
bin:
next-sitemap: bin/next-sitemap.mjs
next-sitemap-cjs: bin/next-sitemap.cjs
checksum: 8e88c941b5e487584abaa21a31a94d888c8d37e95892cd6b5bdbc121f49435f75c279e97508a7a99d3de0010e833f3769d0c2d0888d9228be4dbd48e031b831c
languageName: node
linkType: hard

"next-themes@npm:^0.3.0":
version: 0.3.0
resolution: "next-themes@npm:0.3.0"
Expand Down Expand Up @@ -11325,7 +11294,6 @@ __metadata:
lint-staged: "npm:^15.2.0"
next: "npm:14.2.3"
next-contentlayer2: "npm:0.4.5"
next-sitemap: "npm:^4.2.3"
next-themes: "npm:^0.3.0"
pliny: "npm:0.2.0"
postcss: "npm:^8.4.33"
Expand Down

0 comments on commit db13754

Please sign in to comment.