Project

General

Profile

Actions

ClientProject #3432

open

[SEO]: POC for Splitting Sitemap & Korean Stock Sitemap Fix

Added by Md.Sajib Ahmed 6 months ago. Updated 6 months ago.

Status:
Complete
Priority:
High
Target version:
Start date:
10/12/2025
Due date:
% Done:

100%

Estimated time:
7:00 h
Spent time:

Description

Tasks

  1. POC for Splitting Sitemap

    • Conducted a proof of concept to split large sitemap files into multiple smaller files for better scalability and crawling performance.
  2. 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.
  3. 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.
Actions

Also available in: Atom PDF