feat(seo) : add dynamic sitemap.ts and robots.ts for localized rules …#138
Conversation
📝 WalkthroughWalkthroughTwo new Next.js metadata route files are added: ChangesSEO Metadata Routes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
src/app/robots.tssrc/app/sitemap.ts
| const baseUrl = process.env.NEXT_PUBLIC_APP_URL || "https://weftmap.com"; | ||
| return { | ||
| rules: { | ||
| userAgent: "*", | ||
| allow: "/", | ||
| }, | ||
| sitemap: `${baseUrl}/sitemap.xml`, |
There was a problem hiding this comment.
🎯 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.
| 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.
| import { DOC_SLUGS } from "@/lib/docs"; | ||
|
|
||
| export default function sitemap(): MetadataRoute.Sitemap { | ||
| const baseUrl = process.env.NEXT_PUBLIC_APP_URL || "https://weftmap.com"; |
There was a problem hiding this comment.
🎯 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.
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
Dynamic Sitemap (
src/app/sitemap.ts):/sitemap.xml.en,es,pt,ar,fr,it).DOC_SLUGSfromsrc/lib/docs.ts.NEXT_PUBLIC_APP_URLenvironment variable, defaulting tohttps://weftmap.com.Robots Configuration (
src/app/robots.ts):/robots.txt.Allow: /for all user-agents).How to Test
http://localhost:3000/robots.txt
http://localhost:3000/sitemap.xml
Summary by CodeRabbit