Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate sitemap.xml #386

Closed
odanado opened this issue Aug 16, 2020 · 2 comments · Fixed by #479
Closed

generate sitemap.xml #386

odanado opened this issue Aug 16, 2020 · 2 comments · Fixed by #479
Labels
enhancement New feature or request

Comments

@odanado
Copy link

odanado commented Aug 16, 2020

Is your feature request related to a problem? Please describe.

@nuxtjs/sitemap can generate a sitemap dynamically by specifying the routes option.
But @nuxt/content doesn't support sitemap generation.

Describe the solution you'd like

Update sitemapOptions on the occurrence of the sitemap:generate:before event.
https://github.com/nuxt-community/sitemap-module#hooks

Here's a sample code.
https://github.com/odanado/blog/blob/8ca87f3dc63477d870f09b24b115cd25f3cd8996/app/modules/sitemap.ts

@odanado odanado added the enhancement New feature or request label Aug 16, 2020
@odanado
Copy link
Author

odanado commented Aug 17, 2020

If nuxt-community/sitemap-module#143 is resolved, this issue will also be resolved.
Therefore, there is no need to do anything.

@HannesOberreiter
Copy link

This is my current workaround to generate a sitemap, don't know if it is the best solution but it works for me.

nuxt.config.js

import path from 'path';
import glob from 'glob';
....
sitemap: {
    hostname: URL,
    path: 'sitemap.xml',
    routes: () => {
      const files = glob.sync(path.join(__dirname, '/dist/**/*.html'));
      const urls = files.map(function(file){
        const url = path.relative(
          path.join(
            __dirname, '/dist/'), 
            file
          ).replace('index.html', '');
          return {
            url: url,
            lastmodfile: file
          }
      })
     return urls;
    },
    i18n: true,
    cacheTime: 1000 * 60 * 60 * 2,
    trailingSlash: true,
    gzip: true
  }

Cheers
Hannes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants