How to generate sitemap on user-generated content site in express js?

469 Views Asked by At

I'm creating a user-generated content site using expressjs. How can I add the URL of these generated content to the sitemap and get it done automatically?

It also needs to be removed from these URLs via the sitemap when the user deletes the account or deletes the content.

I tried the sitemap builder npm packages created for express js, but none of them worked as I wanted, or the intended use was not the same as my intended use.

1

There are 1 best solutions below

0
Marco On

I am unsure if I understood your question, so I assume the following: Your users can generate new URLs that you want to publish in an sitemap.xml that is returned from a specific endpoint right?

If so I'd suggest to use the sitemap.js package. However this package still needs a list of URLs and the metadata you want to deliver.

You could just save the URLs and the metadata to a database table, the filesystem, or whatever data storage you use. Every time content is generated or deleted you also update your URLs list there.

Now, if someone accesses the sitemap endpoint, URLs are read from storage and sitemap.js generates an XML. Goal achieved!