diff --git a/next-sitemap.config.js b/next-sitemap.config.js index b4aabb5..83f2a50 100644 --- a/next-sitemap.config.js +++ b/next-sitemap.config.js @@ -2,10 +2,9 @@ module.exports = { siteUrl: process.env.NEXTAUTH_URL || 'http://localhost:3000', generateRobotsTxt: true, // (optional) - exclude: ['/server-sitemap-index.xml'], // <= exclude here + exclude: ['/server-sitemap.xml'], // <= exclude here robotsTxtOptions: { - additionalSitemaps: [ - 'https://example.com/server-sitemap-index.xml', // <==== Add here - ], + additionalSitemaps: [`${process.env.NEXTAUTH_URL}/server-sitemap.xml`], }, + generateIndexSitemap: false, }; diff --git a/src/app/server-sitemap-index.xml/route.ts b/src/app/server-sitemap-index.xml/route.ts deleted file mode 100644 index 8abaa00..0000000 --- a/src/app/server-sitemap-index.xml/route.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { environment } from '@/environment.mjs'; -import { db } from '@/server/db'; -import { questions } from '@/server/db/schema'; -import { getServerSideSitemapIndex } from 'next-sitemap'; - -export async function GET(_: Request) { - const questionsData = await db - .select({ slug: questions.slug }) - .from(questions); - - const urls = questionsData.map( - (question) => `${environment.NEXTAUTH_URL}/questions/${question.slug}`, - ); - - return getServerSideSitemapIndex(urls); -} diff --git a/src/app/server-sitemap.xml/route.ts b/src/app/server-sitemap.xml/route.ts new file mode 100644 index 0000000..0b18b31 --- /dev/null +++ b/src/app/server-sitemap.xml/route.ts @@ -0,0 +1,19 @@ +import { environment } from '@/environment.mjs'; +import { db } from '@/server/db'; +import { questions } from '@/server/db/schema'; +import { getServerSideSitemap } from 'next-sitemap'; + +export async function GET(_: Request) { + const questionsData = await db + .select({ slug: questions.slug }) + .from(questions); + + const urls = questionsData.map((question) => ({ + loc: `${environment.NEXTAUTH_URL}/questions/${question.slug}`, + lastmod: new Date().toISOString(), + changefreq: 'daily' as const, + priority: 0.7, + })); + + return getServerSideSitemap(urls); +}