npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ax2/sitemap-module

v1.0.0

Published

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

Downloads

4

Readme

Sitemap Module

npm (scoped with tag) npm CircleCI Codecov Dependencies js-standard-style

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

📖 Release Notes

Features

  • Module based on the awesome Sitemap Module for Nuxt.js package
  • Itself based on the awesome sitemap.js package
  • Automatically add the static routes to the sitemap
  • Works with all modes (universal, spa, generate)
  • For Nuxt 1.x and higher
  • Enables Multiple Sitemaps

Setup

  • Add the @ax2/sitemap dependency with yarn or npm to your project.

  • Add @ax2/sitemap to the modules section of nuxt.config.js:

  modules: [
    '@ax2/sitemap'
  ]

notice: If you use other modules (eg. nuxt-i18n), always declare the sitemap module at end of array (eg. modules: ['nuxt-i18n', '@ax2/sitemap'])

  • Configure it for a single sitemap:
{
  modules: [
    '@ax2/sitemap'
  ],
  sitemap: {
    hostname: 'https://example.com',
    gzip: true,
    exclude: [
      '/secret',
      '/admin/**'
    ],
    routes: [
      '/page/1',
      {
        url: '/page/2',
        changefreq: 'daily',
        priority: 1,
        lastmodISO: '2017-06-30T13:30:00.000Z'
      }
    ]
  }
  • Or configure it for a several sitemaps: You need different pathnames for each sitemap.
{
  modules: [
    '@ax2/sitemap'
  ],
  sitemap: [
    {
      path: 'sitemap1.xml',
      hostname: 'https://example.com',
      gzip: true,
      exclude: [
        '/secret',
        '/admin/**'
      ],
      routes: [
        '/page/1',
        {
          url: '/page/2',
          changefreq: 'daily',
          priority: 1,
          lastmodISO: '2017-06-30T13:30:00.000Z'
        }
      ]
    },
    {
      path: 'sitemap2.xml',
      hostname: 'https://example.com',
      gzip: true,
      exclude: [
        '/secret',
        '/admin/**'
      ],
      routes: [
        '/page/1',
        {
          url: '/page/2',
          changefreq: 'daily',
          priority: 1,
          lastmodISO: '2017-06-30T13:30:00.000Z'
        }
      ]
    }
  ]
  }

Configuration

routes

The routes parameter follows the same way than the generate configuration.

See as well the routes examples below.

path (optional)

  • Default: sitemap.xml

The URL path of the generated sitemap.

hostname (optional)

  • Default:
    1. sitemap.hostname value from your nuxt.config.js
    2. build.publicPath value from your nuxt.config.js
    3. os.hostname() for generate or spa mode, or dynamically based on request URL (headers.host) for universal mode

This value is mandatory for generation sitemap file, and you should explicitly provide it for generate or spa mode.

cacheTime (optional)

  • Default: 1000 * 60 * 15 (15 Minutes)

Defines how frequently should sitemap routes being updated.

Please note that after each invalidation, routes will be evaluated again. (See routes section)

exclude (optional)

  • Default: []

The exclude parameter is an array of glob patterns to exclude static routes from the generated sitemap.

filter (optional)

  • Default: undefined

If filter option is set as a function, all routes will be filtered through it.

Examples:

// nuxt.config.js

// Filter routes by language
{
  sitemap: {
    filter ({ routes, options }) {
      if (options.hostname === 'example.com') {
        return routes.filter(route => route.locale === 'en')
      }
      return routes.filter(route => route.locale === 'fr')
    }
  }
}

// Add a trailing slash to each route
{
  sitemap: {
    filter ({ routes }) {
      return routes.map(route => route.url = `${route.url}/`)
    }
  }
}

gzip (optional)

  • Default: false

Enable the creation of the .xml.gz sitemap compressed with gzip.

defaults (optional)

  • Default: {}

The defaults parameter set the default options for all routes.

// nuxt.config.js

{
  sitemap: {
    defaults: {
      changefreq: 'daily',
      priority: 1,
      lastmod: new Date(),
      lastmodrealtime: true
    }
  }
}

See available options: https://github.com/ekalinin/sitemap.js#usage

Routes

By default, the dynamic routes are ignored by the sitemap module.
Nuxt cannot automatically provide this type of complex routes.

Example:

-| pages/
---| index.vue  --> static route
---| about.vue  --> static route
---| users/
-----| _id.vue  --> dynamic route

If you want the module to add any route with dynamic parameters, you have to set an array of dynamic routes.

eg. add routes for /users/:id in the configuration:

// nuxt.config.js

{
  sitemap: {
    routes: [
      '/users/1',
      '/users/2',
      '/users/3'
    ]
  }
}

Function which returns a Promise

// nuxt.config.js

const axios = require('axios')

{
  sitemap: {
    routes () {
      return axios.get('https://jsonplaceholder.typicode.com/users')
        .then(res => res.data.map(user => '/users/' + user.username))
    }
  }
}

Function with a callback

This feature is deprecated. Use a promise-based approach instead.

// nuxt.config.js

const axios = require('axios')

{
  sitemap: {
    routes (callback) {
      axios.get('https://jsonplaceholder.typicode.com/users')
      .then(res => {
        let routes = res.data.map(user => '/users/' + user.username)
        callback(null, routes)
      })
      .catch(callback)
    }
  }
}

License

MIT License

Contributors