New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nuxtjs/sitemap

Package Overview
Dependencies
Maintainers
3
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuxtjs/sitemap

[![npm](https://img.shields.io/npm/dt/@nuxtjs/sitemap.svg?style=flat-square)](https://www.npmjs.com/package/@nuxtjs/sitemap) [![npm (scoped with tag)](https://img.shields.io/npm/v/@nuxtjs/sitemap/latest.svg?style=flat-square)](https://www.npmjs.com/packag

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
92K
decreased by-11.87%
Maintainers
3
Weekly downloads
 
Created
Source

Sitemap

npm npm (scoped with tag)

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

Module based on the awesome sitemap package ❤️

Setup

  • Add @nuxtjs/sitemap dependency using yarn or npm to your project
  • Add @nuxtjs/sitemap module to nuxt.config.js
  modules: [
   '@nuxtjs/sitemap'
  ]
  • Add additional options to sitemap section of nuxt.config.js to override defaults
  sitemap: {
    path: '/sitemap.xml',
    hostname: 'https://example.com',
    cacheTime: 1000 * 60 * 15,
    generate: false, // Enable me when using nuxt generate
    exclude: [
      '/secret',
      '/admin/**'
    ]
    routes: [
      '/page/1',
      {
        url: '/page/2',
        changefreq: 'daily',
        priority: 1,
        lastmodISO: '2017-06-30T13:30:00.000Z'
      }
    ]
  }

Options

exclude

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

routes

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

See as well the routes examples below.

path

  • Default: /sitemap.xml

Where serve/generate sitemap file

hostname

  • Default:
    • hostname() for generate mode
    • Dynamically based on request url for middleware mode

This values is mondatory for generation sitemap file, and you should explicitly provide it for generate mode.

generate

  • Default: false

Generates static sitemap file during build/generate instead of serving using middleware.

cacheTime

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

Defines how friequently should sitemap routes being updated. This option is only effective when generate is false. Pleae note that after each invalidation, routes will be evalouated again. (See routes section)

Routes

Dynamic routes are ignored by the sitemap module.

Example:

-| pages/
---| index.vue
---| users/
-----| _id.vue

If you want the module to add routes with dynamic params, you need to set an array of dynamic routes.

We add routes for /users/:id in nuxt.config.js:

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

Function which returns a Promise

nuxt.config.js

const axios = require('axios')

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

Function with a callback

nuxt.config.js

const axios = require('axios')

module.exports = {
  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)
    }
  }
}

Contributors

FAQs

Package last updated on 25 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc