Next.js Discord

Discord Forum

create a sitemap for my blog site hosted on vercel how?

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
I have hosted a blog site and how to create a sitemap for it how?

9 Replies

Spectacled bear
If you want to create a sitemap dynamically you could create a sitemap.ts file and place your logic there.
Example:

import { API_URL, SITE_URL } from "@/utils/constants";
import { MetadataRoute } from "next";

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const data = await fetch(${API_URL}/user/usernames);
let usernames = ["dummyuser"];
if (data.ok) usernames = await data.json();

return usernames.map((username: string) => {
return {
url: ${SITE_URL}/${username},
changeFrequency: "weekly",
};
});
}
Sun bearOP
should i place in the root folder?
@Sun bear should i place in the root folder?
Spectacled bear
inside app folder
Spectacled bear
is your issue resolved?, if yes please mark the response as answer.
Sun bearOP
Thanks
how to mart solution?
Original message was deleted
see here