@nuxtjs/sitemap 2.4.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -593
- package/dist/client/200.html +11 -0
- package/dist/client/404.html +11 -0
- package/dist/client/_nuxt/Icon.I3NdYkjC.css +1 -0
- package/dist/client/_nuxt/Icon.wdYGFqbO.js +1 -0
- package/dist/client/_nuxt/IconCSS.6oz918NR.css +1 -0
- package/dist/client/_nuxt/IconCSS.L-uj6Ouj.js +1 -0
- package/dist/client/_nuxt/builds/latest.json +1 -0
- package/dist/client/_nuxt/builds/meta/c3bdccb2-d4db-4a94-9e61-39b740a57bf8.json +1 -0
- package/dist/client/_nuxt/entry.Soe9IWze.js +15 -0
- package/dist/client/_nuxt/entry.UqhvG0ao.css +1 -0
- package/dist/client/_nuxt/error-404.DkXpI38i.css +1 -0
- package/dist/client/_nuxt/error-404.uz-DxZsp.js +1 -0
- package/dist/client/_nuxt/error-500.BsNDeZpL.js +1 -0
- package/dist/client/_nuxt/error-500.SLhS9LVu.css +1 -0
- package/dist/client/_nuxt/index.lSDm5iYo.js +1 -0
- package/dist/client/index.html +11 -0
- package/dist/module.cjs +5 -0
- package/dist/module.d.mts +350 -0
- package/dist/module.d.ts +350 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +994 -0
- package/dist/runtime/nitro/composables/asSitemapUrl.d.ts +2 -0
- package/dist/runtime/nitro/composables/asSitemapUrl.mjs +3 -0
- package/dist/runtime/nitro/composables/defineSitemapEventHandler.d.ts +3 -0
- package/dist/runtime/nitro/composables/defineSitemapEventHandler.mjs +2 -0
- package/dist/runtime/nitro/composables/getPathRobotConfigPolyfill.d.ts +4 -0
- package/dist/runtime/nitro/composables/getPathRobotConfigPolyfill.mjs +3 -0
- package/dist/runtime/nitro/kit.d.ts +3 -0
- package/dist/runtime/nitro/kit.mjs +23 -0
- package/dist/runtime/nitro/middleware/[sitemap]-sitemap.xml.d.ts +2 -0
- package/dist/runtime/nitro/middleware/[sitemap]-sitemap.xml.mjs +23 -0
- package/dist/runtime/nitro/plugins/compression.d.ts +2 -0
- package/dist/runtime/nitro/plugins/compression.mjs +8 -0
- package/dist/runtime/nitro/plugins/nuxt-content.d.ts +2 -0
- package/dist/runtime/nitro/plugins/nuxt-content.mjs +38 -0
- package/dist/runtime/nitro/plugins/warm-up.d.ts +2 -0
- package/dist/runtime/nitro/plugins/warm-up.mjs +23 -0
- package/dist/runtime/nitro/routes/__sitemap__/debug.d.ts +37 -0
- package/dist/runtime/nitro/routes/__sitemap__/debug.mjs +29 -0
- package/dist/runtime/nitro/routes/__sitemap__/nuxt-content-urls.d.ts +2 -0
- package/dist/runtime/nitro/routes/__sitemap__/nuxt-content-urls.mjs +6 -0
- package/dist/runtime/nitro/routes/sitemap.xml.d.ts +2 -0
- package/dist/runtime/nitro/routes/sitemap.xml.mjs +13 -0
- package/dist/runtime/nitro/routes/sitemap.xsl.d.ts +2 -0
- package/dist/runtime/nitro/routes/sitemap.xsl.mjs +230 -0
- package/dist/runtime/nitro/routes/sitemap_index.xml.d.ts +2 -0
- package/dist/runtime/nitro/routes/sitemap_index.xml.mjs +27 -0
- package/dist/runtime/nitro/sitemap/builder/sitemap-index.d.ts +2 -0
- package/dist/runtime/nitro/sitemap/builder/sitemap-index.mjs +86 -0
- package/dist/runtime/nitro/sitemap/builder/sitemap.d.ts +2 -0
- package/dist/runtime/nitro/sitemap/builder/sitemap.mjs +107 -0
- package/dist/runtime/nitro/sitemap/builder/xml.d.ts +4 -0
- package/dist/runtime/nitro/sitemap/builder/xml.mjs +83 -0
- package/dist/runtime/nitro/sitemap/nitro.d.ts +4 -0
- package/dist/runtime/nitro/sitemap/nitro.mjs +36 -0
- package/dist/runtime/nitro/sitemap/urlset/filter.d.ts +5 -0
- package/dist/runtime/nitro/sitemap/urlset/filter.mjs +50 -0
- package/dist/runtime/nitro/sitemap/urlset/i18n.d.ts +8 -0
- package/dist/runtime/nitro/sitemap/urlset/i18n.mjs +128 -0
- package/dist/runtime/nitro/sitemap/urlset/normalise.d.ts +3 -0
- package/dist/runtime/nitro/sitemap/urlset/normalise.mjs +77 -0
- package/dist/runtime/nitro/sitemap/urlset/sort.d.ts +2 -0
- package/dist/runtime/nitro/sitemap/urlset/sort.mjs +19 -0
- package/dist/runtime/nitro/sitemap/urlset/sources.d.ts +5 -0
- package/dist/runtime/nitro/sitemap/urlset/sources.mjs +82 -0
- package/dist/runtime/nitro/tsconfig.json +3 -0
- package/dist/runtime/nitro/utils.d.ts +4 -0
- package/dist/runtime/nitro/utils.mjs +13 -0
- package/dist/runtime/types.d.ts +355 -0
- package/dist/runtime/types.mjs +0 -0
- package/dist/runtime/utils-pure.d.ts +7 -0
- package/dist/runtime/utils-pure.mjs +32 -0
- package/dist/types.d.mts +18 -0
- package/dist/types.d.ts +18 -0
- package/package.json +79 -75
- package/CHANGELOG.md +0 -268
- package/LICENSE +0 -21
- package/lib/builder.js +0 -172
- package/lib/cache.js +0 -95
- package/lib/generator.js +0 -113
- package/lib/logger.js +0 -19
- package/lib/middleware.js +0 -195
- package/lib/module.js +0 -72
- package/lib/options.js +0 -135
- package/lib/routes.js +0 -55
package/lib/middleware.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
const { gzipSync } = require('zlib')
|
|
2
|
-
|
|
3
|
-
const generateETag = require('etag')
|
|
4
|
-
const fresh = require('fresh')
|
|
5
|
-
|
|
6
|
-
const { createSitemap, createSitemapIndex } = require('./builder')
|
|
7
|
-
const { createRoutesCache } = require('./cache')
|
|
8
|
-
const logger = require('./logger')
|
|
9
|
-
const { setDefaultSitemapOptions, setDefaultSitemapIndexOptions } = require('./options')
|
|
10
|
-
const { excludeRoutes } = require('./routes')
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Register a middleware for each sitemap or sitemapindex
|
|
14
|
-
*
|
|
15
|
-
* @param {Object} options
|
|
16
|
-
* @param {Object} globalCache
|
|
17
|
-
* @param {Nuxt} nuxtInstance
|
|
18
|
-
* @param {number} depth
|
|
19
|
-
*/
|
|
20
|
-
function registerSitemaps(options, globalCache, nuxtInstance, depth = 0) {
|
|
21
|
-
/* istanbul ignore if */
|
|
22
|
-
if (depth > 1) {
|
|
23
|
-
// see https://webmasters.stackexchange.com/questions/18243/can-a-sitemap-index-contain-other-sitemap-indexes
|
|
24
|
-
logger.warn("A sitemap index file can't list other sitemap index files, but only sitemap files")
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const isSitemapIndex = options && options.sitemaps && Array.isArray(options.sitemaps) && options.sitemaps.length > 0
|
|
28
|
-
|
|
29
|
-
if (isSitemapIndex) {
|
|
30
|
-
registerSitemapIndex(options, globalCache, nuxtInstance, depth)
|
|
31
|
-
} else {
|
|
32
|
-
registerSitemap(options, globalCache, nuxtInstance, depth)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Register a middleware to serve a sitemap
|
|
38
|
-
*
|
|
39
|
-
* @param {Object} options
|
|
40
|
-
* @param {Object} globalCache
|
|
41
|
-
* @param {Nuxt} nuxtInstance
|
|
42
|
-
* @param {number} depth
|
|
43
|
-
*/
|
|
44
|
-
function registerSitemap(options, globalCache, nuxtInstance, depth = 0) {
|
|
45
|
-
const base = nuxtInstance.options.router.base
|
|
46
|
-
|
|
47
|
-
// Init options
|
|
48
|
-
options = setDefaultSitemapOptions(options, nuxtInstance, depth > 0)
|
|
49
|
-
|
|
50
|
-
// Init cache
|
|
51
|
-
const cache = {}
|
|
52
|
-
cache.staticRoutes = () => excludeRoutes(options.exclude, globalCache.staticRoutes)
|
|
53
|
-
cache.routes = createRoutesCache(cache, options)
|
|
54
|
-
|
|
55
|
-
// On run cmd "start" or "generate [--no-build]"
|
|
56
|
-
if (globalCache.staticRoutes) {
|
|
57
|
-
// On server ready
|
|
58
|
-
nuxtInstance.nuxt.hook('listen', () => {
|
|
59
|
-
// Hydrate cache
|
|
60
|
-
cache.routes.get('routes')
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (options.gzip) {
|
|
65
|
-
// Add server middleware for sitemap.xml.gz
|
|
66
|
-
nuxtInstance.addServerMiddleware({
|
|
67
|
-
path: options.pathGzip,
|
|
68
|
-
async handler(req, res, next) {
|
|
69
|
-
try {
|
|
70
|
-
// Init sitemap
|
|
71
|
-
const routes = await cache.routes.get('routes')
|
|
72
|
-
const gzip = await createSitemap(options, routes, base, req).toGzip()
|
|
73
|
-
// Check cache headers
|
|
74
|
-
if (validHttpCache(gzip, options.etag, req, res)) {
|
|
75
|
-
return
|
|
76
|
-
}
|
|
77
|
-
// Send http response
|
|
78
|
-
res.setHeader('Content-Type', 'application/gzip')
|
|
79
|
-
res.end(gzip)
|
|
80
|
-
} catch (err) {
|
|
81
|
-
/* istanbul ignore next */
|
|
82
|
-
next(err)
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Add server middleware for sitemap.xml
|
|
89
|
-
nuxtInstance.addServerMiddleware({
|
|
90
|
-
path: options.path,
|
|
91
|
-
/**
|
|
92
|
-
* @param {Request} req
|
|
93
|
-
* @param {Response} res
|
|
94
|
-
* @param {*} next
|
|
95
|
-
*/
|
|
96
|
-
async handler(req, res, next) {
|
|
97
|
-
try {
|
|
98
|
-
// Init sitemap
|
|
99
|
-
const routes = await cache.routes.get('routes')
|
|
100
|
-
const xml = await createSitemap(options, routes, base, req).toXML()
|
|
101
|
-
// Check cache headers
|
|
102
|
-
if (validHttpCache(xml, options.etag, req, res)) {
|
|
103
|
-
return
|
|
104
|
-
}
|
|
105
|
-
// Send http response
|
|
106
|
-
res.setHeader('Content-Type', 'application/xml')
|
|
107
|
-
res.end(xml)
|
|
108
|
-
} catch (err) {
|
|
109
|
-
/* istanbul ignore next */
|
|
110
|
-
next(err)
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
})
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Register a middleware to serve a sitemapindex
|
|
118
|
-
*
|
|
119
|
-
* @param {Object} options
|
|
120
|
-
* @param {Object} globalCache
|
|
121
|
-
* @param {Nuxt} nuxtInstance
|
|
122
|
-
* @param {number} depth
|
|
123
|
-
*/
|
|
124
|
-
function registerSitemapIndex(options, globalCache, nuxtInstance, depth = 0) {
|
|
125
|
-
const base = nuxtInstance.options.router.base
|
|
126
|
-
|
|
127
|
-
// Init options
|
|
128
|
-
options = setDefaultSitemapIndexOptions(options, nuxtInstance)
|
|
129
|
-
|
|
130
|
-
if (options.gzip) {
|
|
131
|
-
// Add server middleware for sitemapindex.xml.gz
|
|
132
|
-
nuxtInstance.addServerMiddleware({
|
|
133
|
-
path: options.pathGzip,
|
|
134
|
-
handler(req, res, next) {
|
|
135
|
-
// Init sitemap index
|
|
136
|
-
const sitemapIndex = createSitemapIndex(options, base, req)
|
|
137
|
-
const gzip = gzipSync(sitemapIndex)
|
|
138
|
-
// Check cache headers
|
|
139
|
-
if (validHttpCache(gzip, options.etag, req, res)) {
|
|
140
|
-
return
|
|
141
|
-
}
|
|
142
|
-
// Send http response
|
|
143
|
-
res.setHeader('Content-Type', 'application/gzip')
|
|
144
|
-
res.end(gzip)
|
|
145
|
-
},
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Add server middleware for sitemapindex.xml
|
|
150
|
-
nuxtInstance.addServerMiddleware({
|
|
151
|
-
path: options.path,
|
|
152
|
-
handler(req, res, next) {
|
|
153
|
-
// Init sitemap index
|
|
154
|
-
const xml = createSitemapIndex(options, base, req)
|
|
155
|
-
// Check cache headers
|
|
156
|
-
if (validHttpCache(xml, options.etag, req, res)) {
|
|
157
|
-
return
|
|
158
|
-
}
|
|
159
|
-
// Send http response
|
|
160
|
-
res.setHeader('Content-Type', 'application/xml')
|
|
161
|
-
res.end(xml)
|
|
162
|
-
},
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
// Register linked sitemaps
|
|
166
|
-
options.sitemaps.forEach((sitemapOptions) => registerSitemaps(sitemapOptions, globalCache, nuxtInstance, depth + 1))
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Validate the freshness of HTTP cache using headers
|
|
171
|
-
*
|
|
172
|
-
* @param {Object} entity
|
|
173
|
-
* @param {Object} options
|
|
174
|
-
* @param {Request} req
|
|
175
|
-
* @param {Response} res
|
|
176
|
-
* @returns {boolean}
|
|
177
|
-
*/
|
|
178
|
-
function validHttpCache(entity, options, req, res) {
|
|
179
|
-
if (!options) {
|
|
180
|
-
return false
|
|
181
|
-
}
|
|
182
|
-
const { hash } = options
|
|
183
|
-
const etag = hash ? hash(entity, options) : generateETag(entity, options)
|
|
184
|
-
if (fresh(req.headers, { etag })) {
|
|
185
|
-
// Resource not modified
|
|
186
|
-
res.statusCode = 304
|
|
187
|
-
res.end()
|
|
188
|
-
return true
|
|
189
|
-
}
|
|
190
|
-
// Add ETag header
|
|
191
|
-
res.setHeader('ETag', etag)
|
|
192
|
-
return false
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
module.exports = { registerSitemaps, registerSitemap, registerSitemapIndex }
|
package/lib/module.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
|
|
3
|
-
const fs = require('fs-extra')
|
|
4
|
-
|
|
5
|
-
const { generateSitemaps } = require('./generator')
|
|
6
|
-
const logger = require('./logger')
|
|
7
|
-
const { registerSitemaps } = require('./middleware')
|
|
8
|
-
const { getStaticRoutes } = require('./routes')
|
|
9
|
-
|
|
10
|
-
module.exports = async function module(moduleOptions) {
|
|
11
|
-
const nuxtInstance = this
|
|
12
|
-
|
|
13
|
-
// Init options
|
|
14
|
-
const options = await initOptions(nuxtInstance, moduleOptions)
|
|
15
|
-
if (options === false) {
|
|
16
|
-
logger.info('Sitemap disabled')
|
|
17
|
-
return
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Init cache
|
|
21
|
-
// a file "sitemap-routes.json" is written to "dist" dir on "build" mode
|
|
22
|
-
const jsonStaticRoutesPath = !nuxtInstance.options.dev
|
|
23
|
-
? path.resolve(nuxtInstance.options.buildDir, path.join('dist', 'sitemap-routes.json'))
|
|
24
|
-
: null
|
|
25
|
-
const staticRoutes = fs.readJsonSync(jsonStaticRoutesPath, { throws: false })
|
|
26
|
-
const globalCache = { staticRoutes }
|
|
27
|
-
|
|
28
|
-
// Init static routes
|
|
29
|
-
nuxtInstance.extendRoutes((routes) => {
|
|
30
|
-
// Create a cache for static routes
|
|
31
|
-
globalCache.staticRoutes = getStaticRoutes(routes)
|
|
32
|
-
|
|
33
|
-
// On run cmd "build"
|
|
34
|
-
if (!nuxtInstance.options.dev) {
|
|
35
|
-
// Save static routes
|
|
36
|
-
fs.outputJsonSync(jsonStaticRoutesPath, globalCache.staticRoutes)
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
// On "generate" mode, generate static files for each sitemap or sitemapindex
|
|
41
|
-
nuxtInstance.nuxt.hook('generate:done', async () => {
|
|
42
|
-
await nuxtInstance.nuxt.callHook('sitemap:generate:before', nuxtInstance, options)
|
|
43
|
-
logger.info('Generating sitemaps')
|
|
44
|
-
await Promise.all(options.map((options) => generateSitemaps(options, globalCache, nuxtInstance)))
|
|
45
|
-
await nuxtInstance.nuxt.callHook('sitemap:generate:done', nuxtInstance)
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
// On "ssr" mode, register middlewares for each sitemap or sitemapindex
|
|
49
|
-
options.forEach((options) => {
|
|
50
|
-
registerSitemaps(options, globalCache, nuxtInstance)
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function initOptions(nuxtInstance, moduleOptions) {
|
|
55
|
-
if (nuxtInstance.options.sitemap === false || moduleOptions === false) {
|
|
56
|
-
return false
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
let options = nuxtInstance.options.sitemap || moduleOptions
|
|
60
|
-
|
|
61
|
-
if (typeof options === 'function') {
|
|
62
|
-
options = await options.call(nuxtInstance)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (options === false) {
|
|
66
|
-
return false
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return Array.isArray(options) ? options : [options]
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
module.exports.meta = require('../package.json')
|
package/lib/options.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
const MODULE_NAME = require('../package.json').name
|
|
2
|
-
|
|
3
|
-
const logger = require('./logger')
|
|
4
|
-
|
|
5
|
-
const DEFAULT_NUXT_PUBLIC_PATH = '/_nuxt/'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Set default options for a sitemap config
|
|
9
|
-
*
|
|
10
|
-
* @param {Object} options
|
|
11
|
-
* @param {Nuxt} nuxtInstance
|
|
12
|
-
* @param {boolean} isLinkedToSitemapIndex
|
|
13
|
-
* @returns {Object}
|
|
14
|
-
*/
|
|
15
|
-
function setDefaultSitemapOptions(options, nuxtInstance, isLinkedToSitemapIndex = false) {
|
|
16
|
-
const defaults = {
|
|
17
|
-
path: '/sitemap.xml',
|
|
18
|
-
hostname:
|
|
19
|
-
// TODO: remove support of "build.publicPath" on release 3.0
|
|
20
|
-
nuxtInstance.options.build.publicPath !== DEFAULT_NUXT_PUBLIC_PATH
|
|
21
|
-
? nuxtInstance.options.build.publicPath
|
|
22
|
-
: undefined,
|
|
23
|
-
exclude: [],
|
|
24
|
-
routes: nuxtInstance.options.generate.routes || [],
|
|
25
|
-
cacheTime: 1000 * 60 * 15,
|
|
26
|
-
etag: nuxtInstance.options.render.etag,
|
|
27
|
-
filter: undefined,
|
|
28
|
-
gzip: false,
|
|
29
|
-
xmlNs: undefined,
|
|
30
|
-
xslUrl: undefined,
|
|
31
|
-
trailingSlash: false,
|
|
32
|
-
lastmod: undefined,
|
|
33
|
-
i18n: undefined,
|
|
34
|
-
defaults: {},
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const sitemapOptions = {
|
|
38
|
-
...defaults,
|
|
39
|
-
...options,
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (sitemapOptions.i18n) {
|
|
43
|
-
// Check modules config
|
|
44
|
-
const modules = Object.keys(nuxtInstance.requiredModules)
|
|
45
|
-
/* istanbul ignore if */
|
|
46
|
-
if (modules.indexOf('nuxt-i18n') > modules.indexOf(MODULE_NAME)) {
|
|
47
|
-
logger.warn(
|
|
48
|
-
`To enable the "i18n" option, the "${MODULE_NAME}" must be declared after the "nuxt-i18n" module in your config`
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/* istanbul ignore if */
|
|
53
|
-
if (typeof sitemapOptions.i18n === 'string') {
|
|
54
|
-
// TODO: remove support of "string" as shortcut notation on release 3.0
|
|
55
|
-
sitemapOptions.i18n = true
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Set default i18n options
|
|
59
|
-
sitemapOptions.i18n = {
|
|
60
|
-
locales: [],
|
|
61
|
-
routesNameSeparator: '___',
|
|
62
|
-
...sitemapOptions.i18n,
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/* istanbul ignore if */
|
|
67
|
-
if (sitemapOptions.generate) {
|
|
68
|
-
logger.warn("The `generate` option isn't needed anymore in your config. Please remove it!")
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/* istanbul ignore if */
|
|
72
|
-
if (!sitemapOptions.path) {
|
|
73
|
-
logger.fatal('The `path` option is either empty or missing in your config for a sitemap', options)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/* istanbul ignore if */
|
|
77
|
-
if (sitemapOptions.lastmod && !isLinkedToSitemapIndex) {
|
|
78
|
-
logger.warn('The `lastmod` option is only available in the config of a sitemap linked to a sitemap index')
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
sitemapOptions.pathGzip = sitemapOptions.gzip ? `${sitemapOptions.path}.gz` : sitemapOptions.path
|
|
82
|
-
|
|
83
|
-
return sitemapOptions
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Set default options for a sitemapindex config
|
|
88
|
-
*
|
|
89
|
-
* @param {Object} options
|
|
90
|
-
* @param {Nuxt} nuxtInstance
|
|
91
|
-
* @returns {Object}
|
|
92
|
-
*/
|
|
93
|
-
function setDefaultSitemapIndexOptions(options, nuxtInstance) {
|
|
94
|
-
const defaults = {
|
|
95
|
-
path: '/sitemapindex.xml',
|
|
96
|
-
hostname: undefined,
|
|
97
|
-
sitemaps: [],
|
|
98
|
-
lastmod: undefined,
|
|
99
|
-
etag: nuxtInstance.options.render.etag,
|
|
100
|
-
gzip: false,
|
|
101
|
-
xmlNs: undefined,
|
|
102
|
-
xslUrl: undefined,
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const sitemapIndexOptions = {
|
|
106
|
-
...defaults,
|
|
107
|
-
...options,
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/* istanbul ignore if */
|
|
111
|
-
if (sitemapIndexOptions.generate) {
|
|
112
|
-
logger.warn("The `generate` option isn't needed anymore in your config. Please remove it!")
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/* istanbul ignore if */
|
|
116
|
-
if (!sitemapIndexOptions.path) {
|
|
117
|
-
logger.fatal('The `path` option is either empty or missing in your config for a sitemap index', options)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
sitemapIndexOptions.sitemaps.forEach((sitemapOptions) => {
|
|
121
|
-
/* istanbul ignore if */
|
|
122
|
-
if (!sitemapOptions.path) {
|
|
123
|
-
logger.fatal('The `path` option is either empty or missing in your config for a sitemap', sitemapOptions)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// set cascading hostname
|
|
127
|
-
sitemapOptions.hostname = sitemapOptions.hostname || sitemapIndexOptions.hostname
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
sitemapIndexOptions.pathGzip = sitemapIndexOptions.gzip ? `${sitemapIndexOptions.path}.gz` : sitemapIndexOptions.path
|
|
131
|
-
|
|
132
|
-
return sitemapIndexOptions
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
module.exports = { setDefaultSitemapOptions, setDefaultSitemapIndexOptions }
|
package/lib/routes.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
const { Minimatch } = require('minimatch')
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Exclude routes by matching glob patterns on url
|
|
5
|
-
*
|
|
6
|
-
* @param {string[]} patterns
|
|
7
|
-
* @param {Array} routes
|
|
8
|
-
* @returns {Array}
|
|
9
|
-
*/
|
|
10
|
-
function excludeRoutes(patterns, routes) {
|
|
11
|
-
patterns.forEach((pattern) => {
|
|
12
|
-
const minimatch = new Minimatch(pattern)
|
|
13
|
-
minimatch.negate = true
|
|
14
|
-
routes = routes.filter(({ url }) => minimatch.match(url))
|
|
15
|
-
})
|
|
16
|
-
return routes
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Get static routes from Nuxt router and ignore dynamic routes
|
|
21
|
-
*
|
|
22
|
-
* @param {Object} router
|
|
23
|
-
* @returns {Array}
|
|
24
|
-
*/
|
|
25
|
-
function getStaticRoutes(router) {
|
|
26
|
-
return flattenStaticRoutes(router)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Recursively flatten all static routes and their nested routes
|
|
31
|
-
*
|
|
32
|
-
* @param {Object} router
|
|
33
|
-
* @param {string} path
|
|
34
|
-
* @param {Array} routes
|
|
35
|
-
* @returns {Array}
|
|
36
|
-
*/
|
|
37
|
-
function flattenStaticRoutes(router, path = '', routes = []) {
|
|
38
|
-
router.forEach((route) => {
|
|
39
|
-
// Skip dynamic routes
|
|
40
|
-
if ([':', '*'].some((c) => route.path.includes(c))) {
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
// Nested routes
|
|
44
|
-
if (route.children) {
|
|
45
|
-
return flattenStaticRoutes(route.children, path + route.path + '/', routes)
|
|
46
|
-
}
|
|
47
|
-
// Normalize url (without trailing slash)
|
|
48
|
-
route.url = path.length && !route.path.length ? path.slice(0, -1) : path + route.path
|
|
49
|
-
|
|
50
|
-
routes.push(route)
|
|
51
|
-
})
|
|
52
|
-
return routes
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
module.exports = { excludeRoutes, getStaticRoutes }
|