Sitemap index #61025
omerp-explorium
started this conversation in
Ideas
Sitemap index
#61025
Replies: 3 comments 6 replies
-
I made a PR that adds support for |
Beta Was this translation helpful? Give feedback.
5 replies
-
I don't understand the utility of |
Beta Was this translation helpful? Give feedback.
1 reply
-
Meanwhile, I went with my own custom index at import { env } from "~/env";
import { getLastMod } from "~/lib/sitemap";
import { generateSitemaps as getArtistSitemaps } from "../api/sitemaps/artists/sitemap";
import { generateSitemaps as getEventSitemaps } from "../api/sitemaps/events/sitemap";
import { generateSitemaps as getVenueSitemaps } from "../api/sitemaps/venues/sitemap";
export const revalidate = 3600; // cache for 1 hour
function getFileName(id?: number) {
if (id == null) {
return "sitemap.xml";
}
/**
* https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap#generating-multiple-sitemaps
* In production, your generated sitemaps will be available at /.../sitemap/[id].xml. For example, /product/sitemap/1.xml.
* In development, you can view the generated sitemap on /.../sitemap.xml/[id]. For example, /product/sitemap.xml/1. This difference is temporary and will follow the production format.
* See the generateSitemaps API reference for more information.
*/
return env.VERCEL_ENV === "development"
? `sitemap.xml/${id}`
: `sitemap/${id}.xml`;
}
function getLoc(path: string, id?: number) {
return `${env.URL}/api/sitemaps/${path}/${getFileName(id)}`;
}
function getSitemap(path: string, id?: number) {
return /* XML */ `<sitemap><loc>${getLoc(path, id)}</loc><lastmod>${getLastMod()}</lastmod></sitemap>`;
}
function getSitemaps(ids: { id: number }[], path: string) {
return ids.map(({ id }) => getSitemap(path, id)).join("");
}
export async function GET() {
const xml = /* XML */ `<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${getSitemap("cities")}
${getSitemaps(await getEventSitemaps(), "events")}
${getSitemaps(await getArtistSitemaps(), "artists")}
${getSitemaps(await getVenueSitemaps(), "venues")}
</sitemapindex>
`;
return new Response(xml, {
headers: {
"Content-Type": "application/xml",
},
});
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Goals
When using the multiple sitmap approach, Nextjs should produce a root sitemap that will point to all sitemap urlsets e.g /sitemap.xml
Non-Goals
Background
As you can see in the image, we should also have this sitemap pointing to multiple sitemaps
Taken from Google documentation on large sitemaps
Proposal
I propose Nextjs will keep track of all the generated sitemaps, and generate the proposed sitemap of sitemaps xml.
What do you think?
Beta Was this translation helpful? Give feedback.
All reactions