-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { getServerSideSitemap } from "next-sitemap"; | ||
import type { ISitemapField } from "next-sitemap"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
export async function GET(request: Request) { | ||
try { | ||
// Get the absolute path to your MDX files | ||
const postsDirectory = path.join(process.cwd(), "src", "app", "posts"); // Adjust this path to where your MDX files are stored | ||
|
||
// Read all MDX files from the directory | ||
const files = fs.readdirSync(postsDirectory); | ||
|
||
// Create sitemap entries for each blog post | ||
const fields: ISitemapField[] = files | ||
.filter((filename) => filename.endsWith(".mdx")) | ||
.map((filename) => ({ | ||
loc: `${process.env.SITE_URL}/blog/${filename.replace(".mdx", "")}`, | ||
lastmod: new Date().toISOString(), | ||
changefreq: "daily" as const, // This fixes the TypeScript error | ||
priority: 0.7, | ||
})); | ||
|
||
// Add the main blog page | ||
fields.push({ | ||
loc: `${process.env.SITE_URL}/blog`, | ||
lastmod: new Date().toISOString(), | ||
changefreq: "daily" as const, // This fixes the TypeScript error | ||
priority: 0.8, | ||
}); | ||
|
||
return getServerSideSitemap(fields); | ||
} catch (e) { | ||
console.log(e); | ||
return new Response("Something went wrong", { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters