vike icon indicating copy to clipboard operation
vike copied to clipboard

Sitemap Plugin

Open mikhin opened this issue 1 year ago • 11 comments

Description

Hello, Vike Community! I'm in search of a sitemap plugin to enhance our project and was wondering if such a feature already exists.

If not, I'd be grateful for any guidance or suggestions on how to elegantly implement this.

Thank you in advance for your time and assistance!

mikhin avatar Jan 21 '24 13:01 mikhin

What exactly do you mean with sitemap? Do you mean example.org/sitemap.xml? What's your motivation?

brillout avatar Jan 21 '24 16:01 brillout

Yeah, sitemap.xml. I have ssr({prerender: true}) and a lot of html files after build phase, so I want to get somehow sitemap.xml after build step too.

mikhin avatar Jan 21 '24 17:01 mikhin

How about a prerender: { sitemap: true } option? Would you be up for a PR?

What's your motivation?

For SEO or other purposes as well? Is it still relevant to have a sitemap.xml for SEO?

brillout avatar Jan 21 '24 18:01 brillout

Would you be up for a PR?

Yeah, I'm ready to get involved

What's your motivation?

In my particular case, I need it for SEO, yes. I want to feed the file into Google Search Console:

Screenshot 2024-01-21 at 21 11 33

mikhin avatar Jan 21 '24 18:01 mikhin

👍 Looking forward to it.

brillout avatar Jan 21 '24 18:01 brillout

Could you suggest suitable internal APIs from Vike? What would it look like in theory?

I'm asking because I'm not familiar with the Vike structure.

mikhin avatar Jan 21 '24 18:01 mikhin

See runPrerender.ts. If you prefer you can write a script you run after an one of the example's $ vite build (e.g. /examples/{react,vue}-full and I'll do the integration of your script into Vike. Whichever you prefer.

brillout avatar Jan 22 '24 06:01 brillout

@mikhin if you want some code for a script that should work with minor adjustments feel free to take from https://github.com/Idrinth/react-file-based-routes/blob/master/src/generate-routes.ts - would be happy if vike would support sitemaps out of the box.

Required adjustments:

  • point to dist instead of src
  • look for .html files instead of .tsx
  • possibly adjust the mapping object

Idrinth avatar Jan 24 '24 09:01 Idrinth

Sounds great, thanks for the tip!

mikhin avatar Jan 24 '24 09:01 mikhin