@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.
Files changed (86) hide show
  1. package/README.md +60 -593
  2. package/dist/client/200.html +11 -0
  3. package/dist/client/404.html +11 -0
  4. package/dist/client/_nuxt/Icon.I3NdYkjC.css +1 -0
  5. package/dist/client/_nuxt/Icon.wdYGFqbO.js +1 -0
  6. package/dist/client/_nuxt/IconCSS.6oz918NR.css +1 -0
  7. package/dist/client/_nuxt/IconCSS.L-uj6Ouj.js +1 -0
  8. package/dist/client/_nuxt/builds/latest.json +1 -0
  9. package/dist/client/_nuxt/builds/meta/c3bdccb2-d4db-4a94-9e61-39b740a57bf8.json +1 -0
  10. package/dist/client/_nuxt/entry.Soe9IWze.js +15 -0
  11. package/dist/client/_nuxt/entry.UqhvG0ao.css +1 -0
  12. package/dist/client/_nuxt/error-404.DkXpI38i.css +1 -0
  13. package/dist/client/_nuxt/error-404.uz-DxZsp.js +1 -0
  14. package/dist/client/_nuxt/error-500.BsNDeZpL.js +1 -0
  15. package/dist/client/_nuxt/error-500.SLhS9LVu.css +1 -0
  16. package/dist/client/_nuxt/index.lSDm5iYo.js +1 -0
  17. package/dist/client/index.html +11 -0
  18. package/dist/module.cjs +5 -0
  19. package/dist/module.d.mts +350 -0
  20. package/dist/module.d.ts +350 -0
  21. package/dist/module.json +9 -0
  22. package/dist/module.mjs +994 -0
  23. package/dist/runtime/nitro/composables/asSitemapUrl.d.ts +2 -0
  24. package/dist/runtime/nitro/composables/asSitemapUrl.mjs +3 -0
  25. package/dist/runtime/nitro/composables/defineSitemapEventHandler.d.ts +3 -0
  26. package/dist/runtime/nitro/composables/defineSitemapEventHandler.mjs +2 -0
  27. package/dist/runtime/nitro/composables/getPathRobotConfigPolyfill.d.ts +4 -0
  28. package/dist/runtime/nitro/composables/getPathRobotConfigPolyfill.mjs +3 -0
  29. package/dist/runtime/nitro/kit.d.ts +3 -0
  30. package/dist/runtime/nitro/kit.mjs +23 -0
  31. package/dist/runtime/nitro/middleware/[sitemap]-sitemap.xml.d.ts +2 -0
  32. package/dist/runtime/nitro/middleware/[sitemap]-sitemap.xml.mjs +23 -0
  33. package/dist/runtime/nitro/plugins/compression.d.ts +2 -0
  34. package/dist/runtime/nitro/plugins/compression.mjs +8 -0
  35. package/dist/runtime/nitro/plugins/nuxt-content.d.ts +2 -0
  36. package/dist/runtime/nitro/plugins/nuxt-content.mjs +38 -0
  37. package/dist/runtime/nitro/plugins/warm-up.d.ts +2 -0
  38. package/dist/runtime/nitro/plugins/warm-up.mjs +23 -0
  39. package/dist/runtime/nitro/routes/__sitemap__/debug.d.ts +37 -0
  40. package/dist/runtime/nitro/routes/__sitemap__/debug.mjs +29 -0
  41. package/dist/runtime/nitro/routes/__sitemap__/nuxt-content-urls.d.ts +2 -0
  42. package/dist/runtime/nitro/routes/__sitemap__/nuxt-content-urls.mjs +6 -0
  43. package/dist/runtime/nitro/routes/sitemap.xml.d.ts +2 -0
  44. package/dist/runtime/nitro/routes/sitemap.xml.mjs +13 -0
  45. package/dist/runtime/nitro/routes/sitemap.xsl.d.ts +2 -0
  46. package/dist/runtime/nitro/routes/sitemap.xsl.mjs +230 -0
  47. package/dist/runtime/nitro/routes/sitemap_index.xml.d.ts +2 -0
  48. package/dist/runtime/nitro/routes/sitemap_index.xml.mjs +27 -0
  49. package/dist/runtime/nitro/sitemap/builder/sitemap-index.d.ts +2 -0
  50. package/dist/runtime/nitro/sitemap/builder/sitemap-index.mjs +86 -0
  51. package/dist/runtime/nitro/sitemap/builder/sitemap.d.ts +2 -0
  52. package/dist/runtime/nitro/sitemap/builder/sitemap.mjs +107 -0
  53. package/dist/runtime/nitro/sitemap/builder/xml.d.ts +4 -0
  54. package/dist/runtime/nitro/sitemap/builder/xml.mjs +83 -0
  55. package/dist/runtime/nitro/sitemap/nitro.d.ts +4 -0
  56. package/dist/runtime/nitro/sitemap/nitro.mjs +36 -0
  57. package/dist/runtime/nitro/sitemap/urlset/filter.d.ts +5 -0
  58. package/dist/runtime/nitro/sitemap/urlset/filter.mjs +50 -0
  59. package/dist/runtime/nitro/sitemap/urlset/i18n.d.ts +8 -0
  60. package/dist/runtime/nitro/sitemap/urlset/i18n.mjs +128 -0
  61. package/dist/runtime/nitro/sitemap/urlset/normalise.d.ts +3 -0
  62. package/dist/runtime/nitro/sitemap/urlset/normalise.mjs +77 -0
  63. package/dist/runtime/nitro/sitemap/urlset/sort.d.ts +2 -0
  64. package/dist/runtime/nitro/sitemap/urlset/sort.mjs +19 -0
  65. package/dist/runtime/nitro/sitemap/urlset/sources.d.ts +5 -0
  66. package/dist/runtime/nitro/sitemap/urlset/sources.mjs +82 -0
  67. package/dist/runtime/nitro/tsconfig.json +3 -0
  68. package/dist/runtime/nitro/utils.d.ts +4 -0
  69. package/dist/runtime/nitro/utils.mjs +13 -0
  70. package/dist/runtime/types.d.ts +355 -0
  71. package/dist/runtime/types.mjs +0 -0
  72. package/dist/runtime/utils-pure.d.ts +7 -0
  73. package/dist/runtime/utils-pure.mjs +32 -0
  74. package/dist/types.d.mts +18 -0
  75. package/dist/types.d.ts +18 -0
  76. package/package.json +79 -75
  77. package/CHANGELOG.md +0 -268
  78. package/LICENSE +0 -21
  79. package/lib/builder.js +0 -172
  80. package/lib/cache.js +0 -95
  81. package/lib/generator.js +0 -113
  82. package/lib/logger.js +0 -19
  83. package/lib/middleware.js +0 -195
  84. package/lib/module.js +0 -72
  85. package/lib/options.js +0 -135
  86. package/lib/routes.js +0 -55
package/CHANGELOG.md DELETED
@@ -1,268 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
-
5
- ## [2.4.0](https://github.com/nuxt-community/sitemap-module/compare/v2.3.2...v2.4.0) (2020-06-25)
6
-
7
-
8
- ### Features
9
-
10
- * add hooks on sitemap generation ([f0365d2](https://github.com/nuxt-community/sitemap-module/commit/f0365d233d9881b613d346dfed6aef951139385d))
11
-
12
-
13
- ### Bug Fixes
14
-
15
- * 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)
16
-
17
- ### [2.3.2](https://github.com/nuxt-community/sitemap-module/compare/v2.3.1...v2.3.2) (2020-06-15)
18
-
19
-
20
- ### Bug Fixes
21
-
22
- * i18n rel-alternate-hreflang with router.base ([9a31b31](https://github.com/nuxt-community/sitemap-module/commit/9a31b31b37a281353497161f3edb55e4a6bbe588)), closes [#138](https://github.com/nuxt-community/sitemap-module/issues/138)
23
-
24
- ### [2.3.1](https://github.com/nuxt-community/sitemap-module/compare/v2.3.0...v2.3.1) (2020-06-04)
25
-
26
-
27
- ### Bug Fixes
28
-
29
- * set hreflang with iso value like nuxt-i18n ([959fa82](https://github.com/nuxt-community/sitemap-module/commit/959fa82efe86cbba0bda737fe666592bf25f4533)), closes [#131](https://github.com/nuxt-community/sitemap-module/issues/131)
30
-
31
- ## [2.3.0](https://github.com/nuxt-community/sitemap-module/compare/v2.2.1...v2.3.0) (2020-05-11)
32
-
33
-
34
- ### Features
35
-
36
- * add nuxt-i18n routes support with alternate links by hreflang ([cdbd689](https://github.com/nuxt-community/sitemap-module/commit/cdbd689fc2b5d74407119a99e7703f21baf03cc7)), closes [#91](https://github.com/nuxt-community/sitemap-module/issues/91)
37
- * allow module configuration as function or boolean ([522288c](https://github.com/nuxt-community/sitemap-module/commit/522288c155b67edc9a46afb01823eed9f7fdabd8)), closes [#115](https://github.com/nuxt-community/sitemap-module/issues/115)
38
- * enable ETag header for sitemapindex ([2098334](https://github.com/nuxt-community/sitemap-module/commit/2098334b69692eb7d3c01fd4f2533684603ce40d))
39
-
40
- ### [2.2.1](https://github.com/nuxt-community/sitemap-module/compare/v2.2.0...v2.2.1) (2020-04-23)
41
-
42
-
43
- ### Bug Fixes
44
-
45
- * lastmod on sitemapindex ([56d586b](https://github.com/nuxt-community/sitemap-module/commit/56d586b2ecaac977aca44103377d5c73f2f2dbc0)), closes [#112](https://github.com/nuxt-community/sitemap-module/issues/112)
46
- * logs without additional ([9b4773c](https://github.com/nuxt-community/sitemap-module/commit/9b4773c7766422029593905853f4ddbd7ef17220))
47
- * missing warning on generate mode ([d82ee3e](https://github.com/nuxt-community/sitemap-module/commit/d82ee3ea7b2ebcb8203a964b67f57d41f3a2c797))
48
-
49
- ## [2.2.0](https://github.com/nuxt-community/sitemap-module/compare/v2.1.0...v2.2.0) (2020-04-05)
50
-
51
-
52
- ### Features
53
-
54
- * enable ETag header ([ccf3e10](https://github.com/nuxt-community/sitemap-module/commit/ccf3e10a44073c720eb651181db573bc17664a1c)), closes [#80](https://github.com/nuxt-community/sitemap-module/issues/80)
55
-
56
-
57
- ### Bug Fixes
58
-
59
- * force route.url as string ([dc521ab](https://github.com/nuxt-community/sitemap-module/commit/dc521ab32456c511fec8b312c03544312ff2804d))
60
-
61
- ## [2.1.0](https://github.com/nuxt-community/sitemap-module/compare/v2.0.1...v2.1.0) (2020-03-27)
62
-
63
-
64
- ### Features
65
-
66
- * add router data to each route in the filter function ([3f58560](https://github.com/nuxt-community/sitemap-module/commit/3f58560eea2a8cf075d3265dabcf3621e02f76e6)), closes [#69](https://github.com/nuxt-community/sitemap-module/issues/69)
67
-
68
-
69
- ### Bug Fixes
70
-
71
- * headers of gzipped sitemap ([938d7b6](https://github.com/nuxt-community/sitemap-module/commit/938d7b67cdacee8eb15af6b2d0adaafda08ddaa2))
72
- * omit router data before sitemap creation ([755ec76](https://github.com/nuxt-community/sitemap-module/commit/755ec7647099c362fa18e82492cb9a790f83e46e))
73
-
74
- ### [2.0.1](https://github.com/nuxt-community/sitemap-module/compare/v2.0.0...v2.0.1) (2019-11-12)
75
-
76
-
77
- ### Bug Fixes
78
-
79
- * add router base to each link ([f75ea8b](https://github.com/nuxt-community/sitemap-module/commit/f75ea8b30f1de98873ddecb3306f3044718f0baa)), closes [#88](https://github.com/nuxt-community/sitemap-module/issues/88)
80
- * fail on invalid options ([92a4f2f](https://github.com/nuxt-community/sitemap-module/commit/92a4f2f2ac27cd81fb87ac8e2e7dcf8b30ac4c76))
81
-
82
- ## [2.0.0](https://github.com/nuxt-community/sitemap-module/compare/v1.3.1...v2.0.0) (2019-09-29)
83
-
84
-
85
- ### ⚠ BREAKING CHANGES
86
-
87
- * lastmod option parses all ISO8601 date-only strings as being in UTC rather than local time (see [sitemap.js v4 CHANGELOG](https://github.com/ekalinin/sitemap.js/blob/master/CHANGELOG.md#400))
88
- * Drop support for Nuxt.js 1.x
89
-
90
- ### Features
91
-
92
- * add configuration for sitemap index and multiple sitemaps ([e78e4a2](https://github.com/nuxt-community/sitemap-module/commit/e78e4a2)), closes [#6](https://github.com/nuxt-community/sitemap-module/issues/6)
93
-
94
-
95
- * update dependency sitemap.js to v4 ([795aa1a](https://github.com/nuxt-community/sitemap-module/commit/795aa1a))
96
-
97
- ### [1.3.1](https://github.com/nuxt-community/sitemap-module/compare/v1.3.0...v1.3.1) (2019-09-17)
98
-
99
-
100
- ### Bug Fixes
101
-
102
- * support routes from generate.routes with payload ([44f13d5](https://github.com/nuxt-community/sitemap-module/commit/44f13d5)), closes [#68](https://github.com/nuxt-community/sitemap-module/issues/68)
103
-
104
- ## [1.3.0](https://github.com/nuxt-community/sitemap-module/compare/v1.2.0...v1.3.0) (2019-08-23)
105
-
106
-
107
- ### Features
108
-
109
- * add "trailingSlash" option to add a trailing slash to each route ([b82bb66](https://github.com/nuxt-community/sitemap-module/commit/b82bb66)), closes [#34](https://github.com/nuxt-community/sitemap-module/issues/34) [#78](https://github.com/nuxt-community/sitemap-module/issues/78)
110
-
111
- ## [1.2.0](https://github.com/nuxt-community/sitemap-module/compare/v1.1.0...v1.2.0) (2019-05-10)
112
-
113
-
114
- ### Bug Fixes
115
-
116
- * generate sitemap from an absolute path ([78f1f32](https://github.com/nuxt-community/sitemap-module/commit/78f1f32))
117
- * harmonize logs for all OS ([276e8fa](https://github.com/nuxt-community/sitemap-module/commit/276e8fa))
118
-
119
-
120
- ### Features
121
-
122
- * add "xmlNs" option to set custom XML namespaces ([751a779](https://github.com/nuxt-community/sitemap-module/commit/751a779))
123
-
124
-
125
-
126
- # [1.1.0](https://github.com/nuxt-community/sitemap-module/compare/v1.0.0...v1.1.0) (2019-05-01)
127
-
128
-
129
- ### Bug Fixes
130
-
131
- * hostname initialization ([56fdddd](https://github.com/nuxt-community/sitemap-module/commit/56fdddd)), closes [#60](https://github.com/nuxt-community/sitemap-module/issues/60)
132
-
133
-
134
- ### Features
135
-
136
- * add "xslUrl" option to set a custom XSL file to style the sitemap ([de1b706](https://github.com/nuxt-community/sitemap-module/commit/de1b706)), closes [#58](https://github.com/nuxt-community/sitemap-module/issues/58)
137
-
138
-
139
-
140
- # [1.0.0](https://github.com/nuxt-community/sitemap-module/compare/v0.2.2...v1.0.0) (2019-04-15)
141
-
142
-
143
- ### Bug Fixes
144
-
145
- * automatically create sitemap in `dist` ([#42](https://github.com/nuxt-community/sitemap-module/issues/42)) ([2767ccb](https://github.com/nuxt-community/sitemap-module/commit/2767ccb))
146
- * cache initialization ([a947b33](https://github.com/nuxt-community/sitemap-module/commit/a947b33)), closes [#27](https://github.com/nuxt-community/sitemap-module/issues/27) [#51](https://github.com/nuxt-community/sitemap-module/issues/51)
147
- * create cache ([#47](https://github.com/nuxt-community/sitemap-module/issues/47)) ([cd1d90f](https://github.com/nuxt-community/sitemap-module/commit/cd1d90f))
148
-
149
-
150
- ### Features
151
-
152
- * add "defaults" option to set default route options ([eebbb45](https://github.com/nuxt-community/sitemap-module/commit/eebbb45)), closes [#15](https://github.com/nuxt-community/sitemap-module/issues/15)
153
-
154
-
155
- ### Performance Improvements
156
-
157
- * reduce the use of lodash ([c226f11](https://github.com/nuxt-community/sitemap-module/commit/c226f11))
158
-
159
-
160
- ### BREAKING CHANGES
161
-
162
- * usage of hook that require Nuxt >= 1.0
163
-
164
-
165
-
166
- <a name="0.2.2"></a>
167
- ## [0.2.2](https://github.com/nuxt-community/sitemap-module/compare/v0.2.1...v0.2.2) (2019-03-12)
168
-
169
-
170
- ### Bug Fixes
171
-
172
- * avoid duplicate routes with "index.vue" child-routes ([2315574](https://github.com/nuxt-community/sitemap-module/commit/2315574))
173
-
174
-
175
-
176
- <a name="0.2.1"></a>
177
- ## [0.2.1](https://github.com/nuxt-community/sitemap-module/compare/v0.2.0...v0.2.1) (2019-03-12)
178
-
179
-
180
- ### Bug Fixes
181
-
182
- * add child-routes to sitemap.xml ([#49](https://github.com/nuxt-community/sitemap-module/issues/49)) ([1073cf7](https://github.com/nuxt-community/sitemap-module/commit/1073cf7))
183
-
184
-
185
-
186
- <a name="0.2.0"></a>
187
- # [0.2.0](https://github.com/nuxt-community/sitemap-module/compare/v0.1.2...v0.2.0) (2019-01-02)
188
-
189
-
190
- ### Features
191
-
192
- * add custom `filter` option ([239a1ed](https://github.com/nuxt-community/sitemap-module/commit/239a1ed))
193
-
194
-
195
-
196
- <a name="0.1.2"></a>
197
- ## [0.1.2](https://github.com/nuxt-community/sitemap-module/compare/v0.1.1...v0.1.2) (2018-12-11)
198
-
199
-
200
- ### Bug Fixes
201
-
202
- * fix static folder path ([0e02ea6](https://github.com/nuxt-community/sitemap-module/commit/0e02ea6))
203
-
204
-
205
- <a name="0.1.1"></a>
206
- ## [0.1.1](https://github.com/nuxt-community/sitemap-module/compare/v0.1.0...v0.1.1) (2018-04-16)
207
-
208
-
209
- ### Bug Fixes
210
-
211
- * disable gzip option by default ([fba2943](https://github.com/nuxt-community/sitemap-module/commit/fba2943))
212
- * header of gzipped sitemap ([30edf85](https://github.com/nuxt-community/sitemap-module/commit/30edf85))
213
-
214
-
215
-
216
- <a name="0.1.0"></a>
217
- ## [0.1.0](https://github.com/nuxt-community/sitemap-module/compare/v0.0.5...v0.1.0) (2018-04-16)
218
-
219
-
220
- ### Features
221
-
222
- * feat: add gzip compression to sitemap by default ([6cee9bd](https://github.com/nuxt-community/sitemap-module/commit/6cee9bd)), closes [#16](https://github.com/nuxt-community/sitemap-module/issues/16)
223
-
224
-
225
- ### Performance Improvements
226
-
227
- * optimize lodash imports ([5e1e68f](https://github.com/nuxt-community/sitemap-module/commit/5e1e68f))
228
-
229
-
230
-
231
- <a name="0.0.5"></a>
232
- ## [0.0.5](https://github.com/nuxt-community/sitemap-module/compare/v0.0.4...v0.0.5) (2018-04-14)
233
-
234
-
235
- ### Bug Fixes
236
-
237
- * wrap async calls ([b1b785a](https://github.com/nuxt-community/sitemap-module/commit/b1b785a))
238
-
239
-
240
-
241
- <a name="0.0.4"></a>
242
- ## 0.0.4 (2018-03-20)
243
-
244
-
245
- ### Bug Fixes
246
-
247
- * add routesUnion() method to combine routes arrays ([5d4f5b7](https://github.com/nuxt-community/sitemap-module/commit/5d4f5b7))
248
-
249
-
250
-
251
- <a name="0.0.3"></a>
252
- ## [0.0.3](https://github.com/nuxt/modules/compare/@nuxtjs/sitemap@0.0.2...@nuxtjs/sitemap@0.0.3) (2017-08-03)
253
-
254
-
255
- ### Bug Fixes
256
-
257
- * **sitemap:** nuxt rc compability (#104) ([335ae7a](https://github.com/nuxt/modules/commit/335ae7a))
258
-
259
-
260
-
261
-
262
- <a name="0.0.2"></a>
263
- ## [0.0.2](https://github.com/nuxt/modules/compare/@nuxtjs/sitemap@0.0.1...@nuxtjs/sitemap@0.0.2) (2017-07-25)
264
-
265
-
266
- ### Bug Fixes
267
-
268
- * **sitemap:** refactor to fix production build ([27fdca8](https://github.com/nuxt/modules/commit/27fdca8))
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) Nuxt Community
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/lib/builder.js DELETED
@@ -1,172 +0,0 @@
1
- const { hostname } = require('os')
2
- const { join } = require('path')
3
- const { URL } = require('url')
4
-
5
- const isHTTPS = require('is-https')
6
- const sm = require('sitemap')
7
-
8
- const logger = require('./logger')
9
-
10
- /**
11
- * Initialize a fresh sitemap instance
12
- *
13
- * @param {Object} options
14
- * @param {Array} routes
15
- * @param {string} base
16
- * @param {Request} req
17
- * @returns {Sitemap} sitemap instance
18
- */
19
- function createSitemap(options, routes, base = null, req = null) {
20
- const sitemapConfig = {}
21
-
22
- // Set cacheTime
23
- sitemapConfig.cacheTime = options.cacheTime || 0
24
-
25
- // Set sitemap hostname
26
- sitemapConfig.hostname = getHostname(options, req, base)
27
-
28
- // Set XML namespaces
29
- sitemapConfig.xmlNs = options.xmlNs
30
-
31
- // Set XSL url
32
- sitemapConfig.xslUrl = options.xslUrl
33
-
34
- // Set default values to each route
35
- routes = routes.map((route) => ({ ...options.defaults, ...route }))
36
-
37
- // Add a trailing slash to each route URL
38
- if (options.trailingSlash) {
39
- routes = routes.map((route) => {
40
- if (!route.url.endsWith('/')) {
41
- route.url = `${route.url}/`
42
- }
43
- return route
44
- })
45
- }
46
-
47
- // Add alternate i18n routes
48
- if (options.i18n) {
49
- const { locales, routesNameSeparator } = options.i18n
50
-
51
- // Set alternate routes for each page
52
- routes.reduce((i18nRoutes, route) => {
53
- if (!route.name) {
54
- return i18nRoutes
55
- }
56
-
57
- const [page, lang, isDefault = false] = route.name.split(routesNameSeparator)
58
-
59
- if (!lang) {
60
- return i18nRoutes
61
- }
62
-
63
- // Init alternate route
64
- const link = {
65
- lang,
66
- url: join('.', route.url),
67
- }
68
- if (isDefault) {
69
- link.lang = 'x-default'
70
- } else {
71
- const locale = locales.find(({ code }) => code === lang)
72
- if (locale && locale.iso) {
73
- link.lang = locale.iso
74
- }
75
- }
76
-
77
- // Group alternate routes by page and sorted by lang
78
- if (!i18nRoutes[page]) {
79
- i18nRoutes[page] = []
80
- }
81
- const langs = i18nRoutes[page].map(({ lang }) => lang)
82
- langs.push(link.lang)
83
- const index = langs.sort().indexOf(link.lang)
84
- i18nRoutes[page].splice(index, 0, link)
85
-
86
- // Set alternate routes
87
- route.links = i18nRoutes[page]
88
-
89
- return i18nRoutes
90
- }, {})
91
- }
92
-
93
- // Enable the custom filter function for each declared route
94
- if (typeof options.filter === 'function') {
95
- routes = options.filter({
96
- options: { ...sitemapConfig },
97
- routes,
98
- })
99
- }
100
-
101
- routes = routes.map((route) => {
102
- // Omit the router data
103
- const { chunkName, component, name, path, ...sitemapOptions } = route
104
-
105
- // Normalize to absolute path
106
- return {
107
- ...sitemapOptions,
108
- url: join('.', String(sitemapOptions.url)),
109
- }
110
- })
111
-
112
- // Set urls
113
- sitemapConfig.urls = routes
114
-
115
- // Create sitemap instance
116
- return sm.createSitemap(sitemapConfig)
117
- }
118
-
119
- /**
120
- * Initialize a fresh sitemapindex instance
121
- *
122
- * @param {Object} options
123
- * @param {string} base
124
- * @param {Request} req
125
- * @returns {string}
126
- */
127
- function createSitemapIndex(options, base = null, req = null) {
128
- const sitemapIndexConfig = {}
129
-
130
- // Set urls
131
- const defaultHostname = options.hostname
132
- sitemapIndexConfig.urls = options.sitemaps.map((options) => {
133
- // Normalize to absolute path
134
- const path = join('.', options.gzip ? `${options.path}.gz` : options.path)
135
- const hostname = getHostname(options.hostname ? options : { ...options, hostname: defaultHostname }, req, base)
136
- const url = new URL(path, hostname)
137
- return { url: url.href, lastmod: options.lastmod }
138
- })
139
-
140
- // Set lastmod for each sitemap
141
- sitemapIndexConfig.lastmod = options.lastmod
142
-
143
- // Set XML namespaces
144
- sitemapIndexConfig.xmlNs = options.xmlNs
145
-
146
- // Set XSL url
147
- sitemapIndexConfig.xslUrl = options.xslUrl
148
-
149
- // Create a sitemapindex
150
- return sm.buildSitemapIndex(sitemapIndexConfig)
151
- }
152
-
153
- /**
154
- * Determine the current hostname
155
- *
156
- * @param {Object} options
157
- * @param {Request} req
158
- * @param {string} base
159
- * @returns {string}
160
- */
161
- function getHostname(options, req, base) {
162
- /* istanbul ignore if */
163
- if (!options.hostname && !req) {
164
- logger.fatal('The `hostname` option is mandatory in your config on `spa` or `generate` build mode', options)
165
- }
166
- return join(
167
- options.hostname || (req && `${isHTTPS(req) ? 'https' : 'http'}://${req.headers.host}`) || `http://${hostname()}`,
168
- base
169
- )
170
- }
171
-
172
- module.exports = { createSitemap, createSitemapIndex }
package/lib/cache.js DELETED
@@ -1,95 +0,0 @@
1
- const { promisify } = require('util')
2
-
3
- const AsyncCache = require('async-cache')
4
- const unionBy = require('lodash.unionby')
5
-
6
- /**
7
- * Initialize a cache instance for sitemap routes
8
- *
9
- * @param {Object} globalCache
10
- * @param {Object} options
11
- * @returns {AsyncCache.Cache<any>} Cache instance
12
- */
13
- function createRoutesCache(globalCache, options) {
14
- const cache = new AsyncCache({
15
- maxAge: options.cacheTime,
16
- async load(_, callback) {
17
- try {
18
- let routes = await promisifyRoute(options.routes)
19
- routes = joinRoutes(globalCache.staticRoutes ? globalCache.staticRoutes() : [], routes)
20
- callback(null, routes)
21
- } catch (err) {
22
- /* istanbul ignore next */
23
- callback(err)
24
- }
25
- },
26
- })
27
- cache.get = promisify(cache.get)
28
-
29
- return cache
30
- }
31
-
32
- /* istanbul ignore next */
33
- /* eslint-disable */
34
-
35
- /**
36
- * Promisify the `options.routes` option
37
- *
38
- * @remarks Borrowed from nuxt/common/utils
39
- *
40
- * @param {Function} fn Function that fetch dynamic routes
41
- * @returns {Promise.<Array>} Promise that return a list of routes
42
- */
43
- function promisifyRoute(fn) {
44
- // If routes is an array
45
- if (Array.isArray(fn)) {
46
- return Promise.resolve(fn)
47
- }
48
- // If routes is a function expecting a callback
49
- if (fn.length === 1) {
50
- return new Promise((resolve, reject) => {
51
- fn(function (err, routeParams) {
52
- if (err) {
53
- reject(err)
54
- }
55
- resolve(routeParams)
56
- })
57
- })
58
- }
59
- let promise = fn()
60
- if (!promise || (!(promise instanceof Promise) && typeof promise.then !== 'function')) {
61
- promise = Promise.resolve(promise)
62
- }
63
- return promise
64
- }
65
- /* eslint-enable */
66
-
67
- /**
68
- * Join static and dynamic routes into a single list
69
- *
70
- * @param {Array} staticRoutes
71
- * @param {Array} dynamicRoutes
72
- * @returns {Array} List of routes
73
- */
74
- function joinRoutes(staticRoutes, dynamicRoutes) {
75
- // Validate routes
76
- staticRoutes = staticRoutes.map(ensureIsValidRoute)
77
- dynamicRoutes = dynamicRoutes.map(ensureIsValidRoute)
78
- // Join sitemap routes by URL
79
- return unionBy(dynamicRoutes, staticRoutes, 'url')
80
- }
81
-
82
- /**
83
- * Make sure a route is an object with an "url" string property
84
- *
85
- * @param {Object | string} route Route Object or Payload Object or String value
86
- * @returns {Object} A valid route object
87
- */
88
- function ensureIsValidRoute(route) {
89
- route = typeof route === 'object' ? (route.route ? { url: route.route } : route) : { url: route }
90
- // force as string
91
- route.url = String(route.url)
92
- return route
93
- }
94
-
95
- module.exports = { createRoutesCache }
package/lib/generator.js DELETED
@@ -1,113 +0,0 @@
1
- const path = require('path')
2
- const { gzipSync } = require('zlib')
3
-
4
- const fs = require('fs-extra')
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
- * Generate a static file for each sitemap or sitemapindex
14
- *
15
- * @param {Object} options
16
- * @param {Object} globalCache
17
- * @param {Nuxt} nuxtInstance
18
- * @param {number} depth
19
- */
20
- async function generateSitemaps(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
- await generateSitemapIndex(options, globalCache, nuxtInstance, depth)
31
- } else {
32
- await generateSitemap(options, globalCache, nuxtInstance, depth)
33
- }
34
- }
35
-
36
- /**
37
- * Generate a sitemap file
38
- *
39
- * @param {Object} options
40
- * @param {Object} globalCache
41
- * @param {Nuxt} nuxtInstance
42
- * @param {number} depth
43
- */
44
- async function generateSitemap(options, globalCache, nuxtInstance, depth = 0) {
45
- // Init options
46
- options = setDefaultSitemapOptions(options, nuxtInstance, depth > 0)
47
-
48
- // Init cache
49
- const cache = {}
50
- cache.staticRoutes = () => excludeRoutes(options.exclude, globalCache.staticRoutes)
51
- cache.routes = createRoutesCache(cache, options)
52
-
53
- // Generate sitemap.xml
54
- const routes = await cache.routes.get('routes')
55
- const base = nuxtInstance.options.router.base
56
- const sitemap = await createSitemap(options, routes, base)
57
- const xmlFilePath = path.join(nuxtInstance.options.generate.dir, options.path)
58
- fs.outputFileSync(xmlFilePath, sitemap.toXML())
59
- logger.success('Generated', getPathname(nuxtInstance.options.generate.dir, xmlFilePath))
60
-
61
- // Generate sitemap.xml.gz
62
- if (options.gzip) {
63
- const gzipFilePath = path.join(nuxtInstance.options.generate.dir, options.pathGzip)
64
- fs.outputFileSync(gzipFilePath, sitemap.toGzip())
65
- logger.success('Generated', getPathname(nuxtInstance.options.generate.dir, gzipFilePath))
66
- }
67
- }
68
-
69
- /**
70
- * Generate a sitemapindex file
71
- *
72
- * @param {Object} options
73
- * @param {Object} globalCache
74
- * @param {Nuxt} nuxtInstance
75
- * @param {number} depth
76
- */
77
- async function generateSitemapIndex(options, globalCache, nuxtInstance, depth = 0) {
78
- // Init options
79
- options = setDefaultSitemapIndexOptions(options, nuxtInstance)
80
-
81
- // Generate sitemapindex.xml
82
- const base = nuxtInstance.options.router.base
83
- const xml = createSitemapIndex(options, base)
84
- const xmlFilePath = path.join(nuxtInstance.options.generate.dir, options.path)
85
- fs.outputFileSync(xmlFilePath, xml)
86
- logger.success('Generated', getPathname(nuxtInstance.options.generate.dir, xmlFilePath))
87
-
88
- // Generate sitemapindex.xml.gz
89
- if (options.gzip) {
90
- const gzip = gzipSync(xml)
91
- const gzipFilePath = path.join(nuxtInstance.options.generate.dir, options.pathGzip)
92
- fs.outputFileSync(gzipFilePath, gzip)
93
- logger.success('Generated', getPathname(nuxtInstance.options.generate.dir, gzipFilePath))
94
- }
95
-
96
- // Generate linked sitemaps
97
- await Promise.all(
98
- options.sitemaps.map((sitemapOptions) => generateSitemaps(sitemapOptions, globalCache, nuxtInstance, depth + 1))
99
- )
100
- }
101
-
102
- /**
103
- * Convert a file path to a URL pathname
104
- *
105
- * @param {string} dirPath
106
- * @param {string} filePath
107
- * @returns {string}
108
- */
109
- function getPathname(dirPath, filePath) {
110
- return [, ...path.relative(dirPath, filePath).split(path.sep)].join('/')
111
- }
112
-
113
- module.exports = { generateSitemaps, generateSitemap, generateSitemapIndex }
package/lib/logger.js DELETED
@@ -1,19 +0,0 @@
1
- /* istanbul ignore file */
2
-
3
- const consola = require('consola')
4
-
5
- function warn(message, options = null) {
6
- consola.warn({
7
- message: `[sitemap-module] ${message}`,
8
- additional: options ? JSON.stringify(options, null, 2) : null,
9
- })
10
- }
11
-
12
- function fatal(message, options = null) {
13
- consola.fatal({
14
- message: `[sitemap-module] ${message}`,
15
- additional: options ? JSON.stringify(options, null, 2) : null,
16
- })
17
- }
18
-
19
- module.exports = { ...consola, warn, fatal }