atinux / content-wind

A lightweight Nuxt theme to build a Markdown driven website. Powered by Nuxt Content, TailwindCSS and Iconify.
https://content-wind.nuxt.space
MIT License
791 stars 55 forks source link

IDEA: Sitemap support? #5

Closed heychazza closed 2 years ago

heychazza commented 2 years ago

Thanks for building this! Could you add a sitemap generation with this if possible?

atinux commented 2 years ago

I believe that could be possible with a server route calling fetchContentNavigation() and generating a XML.

Something like server/routes/sitemap.xml.ts, do you mind trying?

You can import fetchContentNavigation from #content/server

Then we can add the /sitemap.xml route to nitro.prerender in nuxt.config.ts

heychazza commented 2 years ago

I believe that could be possible with a server route calling fetchContentNavigation() and generating a XML.

Something like server/routes/sitemap.xml.ts, do you mind trying?

You can import fetchContentNavigation from #content/server

Then we can add the /sitemap.xml route to nitro.prerender in nuxt.config.ts

Thanks for your reply! Just tried:

 Package import specifier "#content" is not defined

With:

import {fetchContentNavigation, queryContent} from "#content/server";

export default defineEventHandler((event) => {
    const query = queryContent('blog')
    const blogs = fetchContentNavigation(query)

    return {
        api: blogs
    }
})
atinux commented 2 years ago

Can you share a StackBlitz or open a PR to play with it?

heychazza commented 2 years ago

Can you share a StackBlitz or open a PR to play with it?

Hey buddy, https://stackblitz.com/edit/github-d1ngrx-ss7vne?file=nuxt.config.ts

atinux commented 2 years ago

I updated your Stackblitz, it was missing @nuxt/content dependency and it was not activated either.

See a working example: https://stackblitz.com/edit/github-d1ngrx-3vu7ua?file=server%2Froutes%2Fsitemap.xml.ts

heychazza commented 2 years ago

https://stackblitz.com/edit/github-d1ngrx-3vu7ua?file=server%2Froutes%2Fsitemap.xml.ts

Ah so we need serverQueryContent in this case?

How would we query for remaining pages too? Like ones not from nuxt content? Happy to make a PR once I can get all the pages and generate a full sitemap.

atinux commented 2 years ago

For remaining pages you will have to add them manually.

I think this example can be documented in Nuxt Content directly about how to create a sitemap based on the content files.

Personally I never generated sitemap and always had great SEO.

heychazza commented 2 years ago

For remaining pages you will have to add them manually.

I think this example can be documented in Nuxt Content directly about how to create a sitemap based on the content files.

Personally I never generated sitemap and always had great SEO.

Oh wow really? I wasn't sure if sitemaps were needed, I'm happy to P.R the entire sitemap generation (using a sitemap lib) to Nuxt Content.