Skip to content

Conversation

@prashantchauhan-12
Copy link
Contributor

Bug Fix: Sitemap Indexing Issue

Problem

The user reported that Google Search Console cannot index sitemap.xml.
Investigation revealed two potential issues:

  1. Build Order: The build script ran next build before npm run generate:sitemap. This meant public/sitemap.xml was copied to the deployment folder (out/) before being updated. The deployed sitemap was always one version behind.
  2. Route Duplication: The sitemap-generator.js script appended blog routes to routes.js on every run. Repeated runs caused duplicate entries in routes.js and sitemap.xml, which could invalidate the sitemap or confuse crawling.

Changes Applied

1. Updated package.json

Modified the build script to generate the sitemap before building the Next.js app.

  • Before: "build": "next build && npm run generate:sitemap"
  • After: "build": "npm run generate:sitemap && next build"
    This ensures the out directory contains the latest sitemap.xml copied from public.

2. Updated scripts/sitemap-generator.js

  • Added robust deduplication logic for routes. The script now ensures that routes.js and sitemap.xml only contain unique paths, preferring the latest data from blogsArray.
  • Added a safety step to copy generated files to ./out if the directory exists. This handles cases where the script is run manually after a build.

How to Verify

  1. Run npm run build.
  2. Check out/sitemap.xml (or deployed URL) to confirm it matches public/sitemap.xml.
  3. Check routes.js to ensure no duplicate blog entries exist.
  4. Deploy the changes and request indexing in Google Search Console.

@mattqdev
Copy link
Collaborator

Thank you seems interesting, I'll merge and then I'll check if it works

@mattqdev mattqdev merged commit 6a2d12b into physicshub:main Jan 27, 2026
1 check passed
@physicshub
Copy link
Owner

🎉 This PR is included in version 3.22.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@prashantchauhan-12 prashantchauhan-12 deleted the fix/sitemap-issue branch January 27, 2026 10:46
@mattqdev
Copy link
Collaborator

@prashantchauhan-12 sitemap is now buggy, check here: https://physicshub.github.io/sitemap.xml

It is shown as a plain html file, but it shouldn't.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants