Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@funken-studio/sitemap-nuxt-3

funken-studio6.3kMITdeprecated4.0.4TypeScript support: included

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

Automatically generate or serve dynamic sitemap.xml for Nuxt projects

nuxt 3, vue 3, nuxt, nuxt.js, nuxtjs, seo, sitemap, sitemap.xml, ssr

readme

@nuxtjs/sitemap

Sitemap Module

npm (scoped with tag) Downloads Build Status Coverage Status License

Automatically generate or serve dynamic sitemap.xml for Nuxt projects!

Read Documentation

📖 Release Notes

Generate sitemap.xml

Normally the sitemap.xml is served via a server middleware / handler, it is only generated in .output/public when running nuxi generate.

If you want to generate the sitemap.xml on every build, you can set the generateOnBuild option to true in the module configuration. (That option might not work if you are using dynamic routes)

// nuxt.config.js
modules: {
  ...
  ['@funken-studio/sitemap-nuxt-3', { generateOnBuild: true }],
  ...
}

Using dynamic routes

  • you are not able to use imports!!
  • see below for a usable workaround:

nuxt.config.ts

import dynamicRoutes from './helpers/dynamicRoutes'
...
 modules: [
    '@funken-studio/sitemap-nuxt-3',
],
sitemap: {
    hostname: 'https://example.com', 
    cacheTime: 1,
    routes: dynamicRoutes,
    defaults: {
      changefreq: 'daily',
      priority: 1,
      lastmod: new Date().toISOString(),
    },
},
...

/helpers/dynamicRoutes

/**
 * since we can't use imports here we just fetch
 * all our routes from a custom API endpoint where we can use imports
 */
export default async () => {
  return await $fetch('/api/sitemap_routes', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

/server/api/sitemap_routes.ts

import { apiPlugin } from '@storyblok/vue'
import { eventHandler } from 'h3'

/**
 * We are using Storyblok as our CMS,
 * in order to have all news and testimonials pages in our sitemap
 * we need to fetch some from Storyblok
 */
export default eventHandler(async (event) => {
  const { req, res } = event
  if (req.method !== 'POST') {
    res.statusCode = 405
    res.end()
    return
  }
  const config = useRuntimeConfig()
  const { storyblokApi } = apiPlugin({ apiOptions: config.public.storyblok })
  console.log('[vue-sitemap] generate dynamic routes')

  const fetchRoutes = async (slug) => {
    const routes = []
    const pageInfo = await storyblokApi.get(`cdn/stories/?starts_with=${slug}`, {
      version: 'published',
      per_page: 1,
      page: 1,
    })

    const totalPages = Math.ceil(pageInfo.headers.total / 25)
    for (let page = 1; page <= totalPages; page++) {
      const pageNews = await storyblokApi.get(`cdn/stories/?starts_with=${slug}`, {
        version: 'published',
        page: page,
      })

      for (const news of pageNews.data.stories) {
        routes.push(`/${slug}/${news.slug}`)
      }

      routes.push(`/${slug}/${page}`)
    }
    return routes
  }

  return [...(await fetchRoutes('news')), ...(await fetchRoutes('testimonials'))]
})

License

MIT License

Contributors

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

4.0.4 (2022-11-19)

Bug Fixes

  • different sitemaps sharing same routes cache (8c959fe)

4.0.3 (2022-11-19)

Bug Fixes

  • adding pre-rendered routes to sitemap when using nuxi generate (0f922a5)

4.0.2 (2022-11-18)

Bug Fixes

  • sitemap generated in wrong directory (be94a1a)

4.0.1 (2022-11-18)

Bug Fixes

  • nuxt 3.0.0: fixes for the latest nuxt release (e515ef9)

4.0.0 (2022-10-24)

⚠ BREAKING CHANGES

  • nuxt-rc.12: not backwards compatible with old release candidates

Bug Fixes

  • nuxt v3.0.0-rc.12 compat (b705933)
  • nuxt-rc.12: changed example in README.md (d1d8d7f)
  • nuxt-rc.12: not backwards compatible with old release candidates (8c207c3)

3.2.0 (2022-07-06)

Features

  • added test cases for nuxt-i18n and switched to @nuxtjs/i18n-edge (4d07701)

3.1.4 (2022-07-01)

3.1.3 (2022-07-01)

Bug Fixes

  • added exports to the package.json

3.1.2 (2022-07-01)

Bug Fixes

3.1.1 (2022-06-28)

3.1.0 (2022-06-28)

Features

Bug Fixes

  • return a valid URL from getHostname (f999d6f)

2.4.0 (2020-06-25)

Features

  • add hooks on sitemap generation (f0365d2)

Bug Fixes

  • generate an <url> for each i18n language available (b6d79c8), closes #140

2.3.2 (2020-06-15)

Bug Fixes

  • i18n rel-alternate-hreflang with router.base (9a31b31), closes #138

2.3.1 (2020-06-04)

Bug Fixes

  • set hreflang with iso value like nuxt-i18n (959fa82), closes #131

2.3.0 (2020-05-11)

Features

  • add nuxt-i18n routes support with alternate links by hreflang (cdbd689), closes #91
  • allow module configuration as function or boolean (522288c), closes #115
  • enable ETag header for sitemapindex (2098334)

2.2.1 (2020-04-23)

Bug Fixes

  • lastmod on sitemapindex (56d586b), closes #112
  • logs without additional (9b4773c)
  • missing warning on generate mode (d82ee3e)

2.2.0 (2020-04-05)

Features

Bug Fixes

  • force route.url as string (dc521ab)

2.1.0 (2020-03-27)

Features

  • add router data to each route in the filter function (3f58560), closes #69

Bug Fixes

  • headers of gzipped sitemap (938d7b6)
  • omit router data before sitemap creation (755ec76)

2.0.1 (2019-11-12)

Bug Fixes

  • add router base to each link (f75ea8b), closes #88
  • fail on invalid options (92a4f2f)

2.0.0 (2019-09-29)

⚠ BREAKING CHANGES

  • lastmod option parses all ISO8601 date-only strings as being in UTC rather than local time (see sitemap.js v4 CHANGELOG)
  • Drop support for Nuxt.js 1.x

Features

  • add configuration for sitemap index and multiple sitemaps (e78e4a2), closes #6
  • update dependency sitemap.js to v4 (795aa1a)

1.3.1 (2019-09-17)

Bug Fixes

  • support routes from generate.routes with payload (44f13d5), closes #68

1.3.0 (2019-08-23)

Features

  • add "trailingSlash" option to add a trailing slash to each route (b82bb66), closes #34 #78

1.2.0 (2019-05-10)

Bug Fixes

  • generate sitemap from an absolute path (78f1f32)
  • harmonize logs for all OS (276e8fa)

Features

  • add "xmlNs" option to set custom XML namespaces (751a779)

1.1.0 (2019-05-01)

Bug Fixes

Features

  • add "xslUrl" option to set a custom XSL file to style the sitemap (de1b706), closes #58

1.0.0 (2019-04-15)

Bug Fixes

Features

  • add "defaults" option to set default route options (eebbb45), closes #15

Performance Improvements

  • reduce the use of lodash (c226f11)

BREAKING CHANGES

  • usage of hook that require Nuxt >= 1.0

0.2.2 (2019-03-12)

Bug Fixes

  • avoid duplicate routes with "index.vue" child-routes (2315574)

0.2.1 (2019-03-12)

Bug Fixes

0.2.0 (2019-01-02)

Features

  • add custom filter option (239a1ed)

0.1.2 (2018-12-11)

Bug Fixes

0.1.1 (2018-04-16)

Bug Fixes

  • disable gzip option by default (fba2943)
  • header of gzipped sitemap (30edf85)

0.1.0 (2018-04-16)

Features

  • feat: add gzip compression to sitemap by default (6cee9bd), closes #16

Performance Improvements

  • optimize lodash imports (5e1e68f)

0.0.5 (2018-04-14)

Bug Fixes

0.0.4 (2018-03-20)

Bug Fixes

  • add routesUnion() method to combine routes arrays (5d4f5b7)

0.0.3 (2017-08-03)

Bug Fixes

  • sitemap: nuxt rc compability (#104) (335ae7a)

0.0.2 (2017-07-25)

Bug Fixes

  • sitemap: refactor to fix production build (27fdca8)