Skip to content

feat(seo) : add dynamic sitemap.ts and robots.ts for localized rules …#138

Merged
DataDave-Dev merged 1 commit into
DataDave-Dev:mainfrom
YasserYG8:feat/seo-sitemap-robots
Jun 25, 2026
Merged

feat(seo) : add dynamic sitemap.ts and robots.ts for localized rules …#138
DataDave-Dev merged 1 commit into
DataDave-Dev:mainfrom
YasserYG8:feat/seo-sitemap-robots

Conversation

@YasserYG8

@YasserYG8 YasserYG8 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Description

Closes #63

This PR implements dynamic Sitemap and Robots.txt configuration files for Weftmap using Next.js App Router metadata conventions.

These files help search engines (like Google and Bing) discover and index all localized pages and documentation routes correctly, improving the overall SEO of the application.

Key Changes

  1. Dynamic Sitemap (src/app/sitemap.ts):

    • Automatically generates /sitemap.xml.
    • Loops through all supported locales (en, es, pt, ar, fr, it).
    • Registers homepage, app workspace, docs index, and individual docs sub-pages dynamically using DOC_SLUGS from src/lib/docs.ts.
    • Dynamically constructs the base URL using NEXT_PUBLIC_APP_URL environment variable, defaulting to https://weftmap.com.
  2. Robots Configuration (src/app/robots.ts):

    • Automatically generates /robots.txt.
    • Configures standard indexing permissions (Allow: / for all user-agents).
    • Directs search crawlers to the sitemap file URL.

How to Test

  1. Start the local server:
    pnpm dev
  2. Verify the robots policy is served at:
    http://localhost:3000/robots.txt
  3. Verify the XML sitemap lists all localized routes at:
    http://localhost:3000/sitemap.xml

Summary by CodeRabbit

  • New Features
    • Implemented automatic sitemap generation covering all supported languages, documentation pages, and key application sections to improve search engine discoverability and indexing.
    • Added web crawler configuration to optimize how search engines discover and index the application's content.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Two new Next.js metadata route files are added: src/app/robots.ts exports a robots() function returning an allow-all rule pointing to the sitemap, and src/app/sitemap.ts exports a sitemap() function that generates locale-prefixed URLs for home, app, docs index, and each doc slug.

Changes

SEO Metadata Routes

Layer / File(s) Summary
robots.ts and sitemap.ts implementation
src/app/robots.ts, src/app/sitemap.ts
robots.ts returns a wildcard allow-all rule with the sitemap URL built from NEXT_PUBLIC_APP_URL (fallback https://weftmap.com). sitemap.ts imports locales and DOC_SLUGS, iterates over each locale to emit entries for the home page, app page, docs index, and each docs slug, assigning lastModified, changeFrequency, and priority per entry type.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 Hoppity-hop through every locale and slug,
The crawlers now find every page, snug as a bug.
Robots say "Welcome!" with allow and cheer,
The sitemap unfolds — all your pages are here!
From home to the docs, every URL's in place,
A well-indexed warren, a most orderly space. 🗺️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding dynamic sitemap.ts and robots.ts files for SEO optimization with localized rules support.
Description check ✅ Passed The description provides comprehensive details about changes, includes closure of issue #63, testing instructions, and key implementation details, though it does not follow the repository's Spanish template structure.
Linked Issues check ✅ Passed The PR successfully implements both required components: sitemap.ts that generates entries for all locales and routes, and robots.ts that permits crawling and directs to sitemap, fully addressing issue #63 requirements.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue: only two new files (sitemap.ts and robots.ts) are added to src/app/ for SEO metadata generation, with no extraneous modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/app/robots.ts`:
- Around line 4-10: The baseUrl variable is concatenated directly with
/sitemap.xml to form the sitemap URL, but if NEXT_PUBLIC_APP_URL ends with a
trailing slash, this creates a double slash in the resulting URL. Normalize the
baseUrl by removing any trailing slash before it is used to compose the sitemap
property. Use a string method to check if baseUrl ends with "/" and strip it if
present, ensuring the final sitemap URL is properly formatted without double
slashes.

In `@src/app/sitemap.ts`:
- Line 6: The baseUrl variable is not being normalized to remove trailing
slashes, which causes double-slash URLs when concatenated with paths in the
sitemap entries. Modify the baseUrl assignment to strip any trailing slash from
the NEXT_PUBLIC_APP_URL value using a string method like replace or endsWith
check, so that subsequent concatenations at lines 12, 20, 28, and 37 produce
canonical URLs without double slashes.
- Line 13: The `lastModified` field in the sitemap entries is calling `new
Date()` directly, which generates a new timestamp on every request and misleads
search engines about actual content freshness. Create a stable, build-time
constant for the timestamp at the top of the sitemap.ts file, then replace all
instances of `lastModified: new Date()` (appearing on lines 13, 21, 29, and 38)
with this constant value. This ensures the same timestamp is used consistently
across all sitemap entries, providing an accurate freshness signal to search
engines.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ebcc94a8-72f3-47cf-860f-74b5b1f89906

📥 Commits

Reviewing files that changed from the base of the PR and between 5068a6f and f915479.

📒 Files selected for processing (2)
  • src/app/robots.ts
  • src/app/sitemap.ts

Comment thread src/app/robots.ts
Comment on lines +4 to +10
const baseUrl = process.env.NEXT_PUBLIC_APP_URL || "https://weftmap.com";
return {
rules: {
userAgent: "*",
allow: "/",
},
sitemap: `${baseUrl}/sitemap.xml`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Normalize baseUrl before composing robots sitemap URL.

If NEXT_PUBLIC_APP_URL ends with /, this produces a double slash in sitemap (for example, https://weftmap.com//sitemap.xml).

Proposed fix
 export default function robots(): MetadataRoute.Robots {
-  const baseUrl = process.env.NEXT_PUBLIC_APP_URL || "https://weftmap.com";
+  const baseUrl = (process.env.NEXT_PUBLIC_APP_URL || "https://weftmap.com").replace(/\/+$/, "");
   return {
     rules: {
       userAgent: "*",
       allow: "/",
     },
     sitemap: `${baseUrl}/sitemap.xml`,
   };
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const baseUrl = process.env.NEXT_PUBLIC_APP_URL || "https://weftmap.com";
return {
rules: {
userAgent: "*",
allow: "/",
},
sitemap: `${baseUrl}/sitemap.xml`,
export default function robots(): MetadataRoute.Robots {
const baseUrl = (process.env.NEXT_PUBLIC_APP_URL || "https://weftmap.com").replace(/\/+$/, "");
return {
rules: {
userAgent: "*",
allow: "/",
},
sitemap: `${baseUrl}/sitemap.xml`,
};
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/robots.ts` around lines 4 - 10, The baseUrl variable is concatenated
directly with /sitemap.xml to form the sitemap URL, but if NEXT_PUBLIC_APP_URL
ends with a trailing slash, this creates a double slash in the resulting URL.
Normalize the baseUrl by removing any trailing slash before it is used to
compose the sitemap property. Use a string method to check if baseUrl ends with
"/" and strip it if present, ensuring the final sitemap URL is properly
formatted without double slashes.

Comment thread src/app/sitemap.ts
import { DOC_SLUGS } from "@/lib/docs";

export default function sitemap(): MetadataRoute.Sitemap {
const baseUrl = process.env.NEXT_PUBLIC_APP_URL || "https://weftmap.com";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Normalize baseUrl once to prevent double-slash URLs in sitemap entries.

If NEXT_PUBLIC_APP_URL contains a trailing slash, generated URLs become non-canonical (e.g., ...//en/docs).

Proposed fix
-  const baseUrl = process.env.NEXT_PUBLIC_APP_URL || "https://weftmap.com";
+  const baseUrl = (process.env.NEXT_PUBLIC_APP_URL || "https://weftmap.com").replace(/\/+$/, "");

Also applies to: 12-12, 20-20, 28-28, 37-37

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/sitemap.ts` at line 6, The baseUrl variable is not being normalized
to remove trailing slashes, which causes double-slash URLs when concatenated
with paths in the sitemap entries. Modify the baseUrl assignment to strip any
trailing slash from the NEXT_PUBLIC_APP_URL value using a string method like
replace or endsWith check, so that subsequent concatenations at lines 12, 20,
28, and 37 produce canonical URLs without double slashes.

Comment thread src/app/sitemap.ts
@DataDave-Dev DataDave-Dev merged commit 656cd67 into DataDave-Dev:main Jun 25, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add sitemap.ts and robots.ts

2 participants