SEO sitemaps as a first class citizen #9682
AlemTuzlak
started this conversation in
Proposals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
SEO support
This proposal aims to simplify the SEO story in Remix by making generation of sitemaps easier and more convinient. It is a bit hard at the moment to generate a sitemap without hacking into Remix internals, hence why I'm proposing this.
Benefits
Background
There are libraries like:
That aim to solve this problem already in similar ways by accessing either the
EntryContext
in theentry.server.tsx
or theroutes
export from@remix-run/dev/server-build
which I'm pretty sure isn't a thing in the Vite land but I might be mistaken. These are not sustainable long-term due to the reliance on internals which might go away at some point, some sooner rather than later!In order to generate sitemaps you need to know which routes the app has, when was the route last modified, what's the priority etc. This can all be done server-side without touching the client. The only thing you need to be vary off is dynamic routes and url segments which would need a way to get this information before returning the full manifest of the available routes.
Proposal
This would depend on how much Remix wants to offer out of the box. The easiest for the user land would be the following:
This would setup the
sitemap.xml
androbots.txt
files with sensible defaults and you can create the files yourselves to override these like withentry.server
andentry.client
files. Another approach would be to create the sitemap and maybe inject it intocontext
, eg:In Vite land this could run when you initially run the project and on
sitemap
export changes with HMR. Maybe there's even a smarter and easier way to do it that I'm not thinking of, would love to have a discussion on the topic here. These were the things that came to mind as potential solutions.The general idea would be that each route module has a
sitemap
export which allows you to define entries for the final sitemap output, and the route module would look like this:If you want to opt-out of generating a sitemap for the children of the current route (
sitemap
export in a child route would override this):If the route doesn't export anything and the parent routes haven't disallowed sitemap.xml entries the current route url would be used as a sitemap entry.
Open questions
Beta Was this translation helpful? Give feedback.
All reactions