Actions
ClientProject #3432
open[SEO]: POC for Splitting Sitemap & Korean Stock Sitemap Fix
Description
Tasks¶
-
POC for Splitting Sitemap
- Conducted a proof of concept to split large sitemap files into multiple smaller files for better scalability and crawling performance.
-
Korean Stock Sitemap Issue & Solution
- Identified an issue with the Korean stock sitemap API.
- Implemented a dynamic sitemap solution with pagination to handle large datasets efficiently.
-
Implementation Guidance
next.config.ts¶
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
async rewrites() {
return [
{
source: "/sitemap.xml",
destination: "/api/sitemap",
},
{
source: "/korean-stock-:page.xml",
destination: "/api/korean-stock/:page",
},
];
},
};
export default nextConfig;
Dynamic Sitemap API Example¶
import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
const ITEMS_PER_SITEMAP = 1000;
type RouteParams = {
params: Promise<{ page: string }>;
};
export async function GET(request: Request, { params }: RouteParams) {
const { page } = await params;
const pageNumber = Number(page);
if (isNaN(pageNumber) || pageNumber < 1) {
return new NextResponse("Invalid page number", { status: 400 });
}
const start = (pageNumber - 1) * ITEMS_PER_SITEMAP;
const palettes = await prisma.sitemap.findMany({
skip: start,
take: ITEMS_PER_SITEMAP,
});
if (palettes.length === 0) {
return new NextResponse("No palettes found for this page", { status: 404 });
}
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${palettes
.map(
(palette) => ` <url>
<loc>${palette.url}/</loc>
<lastmod>${
palette.updatedAt?.toISOString() || palette.createdAt.toISOString()
}</lastmod>
</url>`
)
.join("\n")}
</urlset>`;
return new NextResponse(sitemap, {
headers: {
"Content-Type": "application/xml",
},
});
}
export const dynamic = "force-dynamic";
Outcome¶
- Sitemap splitting successfully implemented and verified.
- Korean stock sitemap API fixed with paginated response support.
- Dynamic XML generation optimized for SEO and server performance.
Updated by Md.Sajib Ahmed 6 months ago
- Status changed from In Progress to Complete
- % Done changed from 0 to 100
Outcome¶
- Sitemap splitting successfully implemented and verified.
- Korean stock sitemap API fixed with paginated response support.
- Dynamic XML generation optimized for SEO and server performance.
Actions