Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/app/robots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { MetadataRoute } from "next";

export default function robots(): MetadataRoute.Robots {
const baseUrl = process.env.NEXT_PUBLIC_APP_URL || "https://weftmap.com";
return {
rules: {
userAgent: "*",
allow: "/",
},
sitemap: `${baseUrl}/sitemap.xml`,
Comment on lines +4 to +10

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.

};
}
46 changes: 46 additions & 0 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { MetadataRoute } from "next";
import { locales } from "@/i18n/config";
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.

const entries: MetadataRoute.Sitemap = [];

for (const lang of locales) {
// Homepage: /:lang
entries.push({
url: `${baseUrl}/${lang}`,
lastModified: new Date(),
Comment thread
YasserYG8 marked this conversation as resolved.
changeFrequency: "weekly",
priority: 1.0,
});

// App page: /:lang/app
entries.push({
url: `${baseUrl}/${lang}/app`,
lastModified: new Date(),
changeFrequency: "monthly",
priority: 0.8,
});

// Docs index: /:lang/docs
entries.push({
url: `${baseUrl}/${lang}/docs`,
lastModified: new Date(),
changeFrequency: "monthly",
priority: 0.7,
});

// Docs pages: /:lang/docs/:slug
for (const slug of DOC_SLUGS) {
entries.push({
url: `${baseUrl}/${lang}/docs/${slug}`,
lastModified: new Date(),
changeFrequency: "monthly",
priority: 0.6,
});
}
}

return entries;
}
Loading