Skip to content

Commit

Permalink
fix(sitemap): switch to regular sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
tfkhdyt committed Jul 7, 2024
1 parent 513ef8e commit 86a7053
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
7 changes: 3 additions & 4 deletions next-sitemap.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
16 changes: 0 additions & 16 deletions src/app/server-sitemap-index.xml/route.ts

This file was deleted.

19 changes: 19 additions & 0 deletions src/app/server-sitemap.xml/route.ts
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 86a7053

Please sign in to comment.