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
5
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuxtjs/sitemap - npm Package Compare versions

Comparing version 2.3.2 to 2.4.0

12

CHANGELOG.md

@@ -5,2 +5,14 @@ # Changelog

## [2.4.0](https://github.com/nuxt-community/sitemap-module/compare/v2.3.2...v2.4.0) (2020-06-25)
### Features
* add hooks on sitemap generation ([f0365d2](https://github.com/nuxt-community/sitemap-module/commit/f0365d233d9881b613d346dfed6aef951139385d))
### Bug Fixes
* generate an <url> for each i18n language available ([b6d79c8](https://github.com/nuxt-community/sitemap-module/commit/b6d79c890a1be0cf9919fe7b1042e8b90e19ac6f)), closes [#140](https://github.com/nuxt-community/sitemap-module/issues/140)
### [2.3.2](https://github.com/nuxt-community/sitemap-module/compare/v2.3.1...v2.3.2) (2020-06-15)

@@ -7,0 +19,0 @@

60

lib/builder.js

@@ -47,48 +47,46 @@ const { hostname } = require('os')

// Group each route with its alternative languages
// Add alternate i18n routes
if (options.i18n) {
const { defaultLocale, locales, routesNameSeparator } = options.i18n
const { locales, routesNameSeparator } = options.i18n
// Set alternate routes for each page
const i18nRoutes = routes.reduce((i18nRoutes, route, index) => {
routes.reduce((i18nRoutes, route) => {
if (!route.name) {
// Route without alternate link
i18nRoutes[`#${index}`] = route
return i18nRoutes
}
let [page, lang, isDefault] = route.name.split(routesNameSeparator) // eslint-disable-line prefer-const
const [page, lang, isDefault = false] = route.name.split(routesNameSeparator)
// Get i18n route, or init it
const i18nRoute = i18nRoutes[page] || { ...route }
if (!lang) {
return i18nRoutes
}
if (lang) {
// Set main link
if (isDefault) {
lang = 'x-default'
// Init alternate route
const link = {
lang,
url: join('.', route.url),
}
if (isDefault) {
link.lang = 'x-default'
} else {
const locale = locales.find(({ code }) => code === lang)
if (locale && locale.iso) {
link.lang = locale.iso
}
if (lang === defaultLocale) {
i18nRoute.url = route.url
}
}
// Set alternate links
if (!i18nRoute.links) {
i18nRoute.links = []
}
const locale = locales.find(({ code }) => code === lang) || { iso: lang }
i18nRoute.links.push({
lang: locale.iso,
url: join('.', route.url),
})
} else {
// No alternate link found
i18nRoute.url = route.url
// Group alternate routes by page and sorted by lang
if (!i18nRoutes[page]) {
i18nRoutes[page] = []
}
const langs = i18nRoutes[page].map(({ lang }) => lang)
langs.push(link.lang)
const index = langs.sort().indexOf(link.lang)
i18nRoutes[page].splice(index, 0, link)
i18nRoutes[page] = i18nRoute
// Set alternate routes
route.links = i18nRoutes[page]
return i18nRoutes
}, {})
routes = Object.values(i18nRoutes)
}

@@ -95,0 +93,0 @@

@@ -42,4 +42,6 @@ const path = require('path')

nuxtInstance.nuxt.hook('generate:done', async () => {
await nuxtInstance.nuxt.callHook('sitemap:generate:before', nuxtInstance, options)
logger.info('Generating sitemaps')
await Promise.all(options.map((options) => generateSitemaps(options, globalCache, nuxtInstance)))
await nuxtInstance.nuxt.callHook('sitemap:generate:done', nuxtInstance)
})

@@ -46,0 +48,0 @@

@@ -19,2 +19,3 @@ const MODULE_NAME = require('../package.json').name

hostname:
// TODO: remove support of "build.publicPath" on release 3.0
nuxtInstance.options.build.publicPath !== DEFAULT_NUXT_PUBLIC_PATH

@@ -52,7 +53,6 @@ ? nuxtInstance.options.build.publicPath

// Shortcut notation
/* istanbul ignore if */
if (typeof sitemapOptions.i18n === 'string') {
sitemapOptions.i18n = {
defaultLocale: sitemapOptions.i18n,
}
// TODO: remove support of "string" as shortcut notation on release 3.0
sitemapOptions.i18n = true
}

@@ -62,3 +62,2 @@

sitemapOptions.i18n = {
defaultLocale: '',
locales: [],

@@ -65,0 +64,0 @@ routesNameSeparator: '___',

{
"name": "@nuxtjs/sitemap",
"version": "2.3.2",
"version": "2.4.0",
"description": "Automatically generate or serve dynamic sitemap.xml for Nuxt.js projects",

@@ -5,0 +5,0 @@ "keywords": [

@@ -32,2 +32,3 @@ # Sitemap Module

- [Routes Declaration](#routes-declaration)
- [Hooks](#hooks)

@@ -377,6 +378,5 @@ ## Installation

// shortcut notation (basic)
i18n: 'en',
i18n: true,
// nuxt-i18n notation (advanced)
i18n: {
defaultLocale: 'en',
locales: ['en', 'es', 'fr'],

@@ -396,2 +396,14 @@ routesNameSeparator: '___'

</url>
<url>
<loc>https://example.com/es/</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/"/>
<xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/"/>
<xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/"/>
</url>
<url>
<loc>https://example.com/fr/</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/"/>
<xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/"/>
<xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/"/>
</url>
```

@@ -586,2 +598,14 @@

## Hooks
Hooks are listeners to Nuxt events. [Learn more](https://nuxtjs.org/api/configuration-hooks)
You can register hooks on certain life cycle events.
| Hook | Arguments | When |
|---|---|---|
| sitemap:generate:before | (nuxt, sitemapOptions) | Hook on before site generation |
| sitemap:generate:done | (nuxt) | Hook on sitemap generation finished |
## License

@@ -588,0 +612,0 @@

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