@nuxtjs/sitemap 2.3.2 → 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 -569
  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 -256
  78. package/LICENSE +0 -21
  79. package/lib/builder.js +0 -174
  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 -70
  85. package/lib/options.js +0 -136
  86. package/lib/routes.js +0 -55
package/CHANGELOG.md DELETED
@@ -1,256 +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.3.2](https://github.com/nuxt-community/sitemap-module/compare/v2.3.1...v2.3.2) (2020-06-15)
6
-
7
-
8
- ### Bug Fixes
9
-
10
- * 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)
11
-
12
- ### [2.3.1](https://github.com/nuxt-community/sitemap-module/compare/v2.3.0...v2.3.1) (2020-06-04)
13
-
14
-
15
- ### Bug Fixes
16
-
17
- * 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)
18
-
19
- ## [2.3.0](https://github.com/nuxt-community/sitemap-module/compare/v2.2.1...v2.3.0) (2020-05-11)
20
-
21
-
22
- ### Features
23
-
24
- * 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)
25
- * 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)
26
- * enable ETag header for sitemapindex ([2098334](https://github.com/nuxt-community/sitemap-module/commit/2098334b69692eb7d3c01fd4f2533684603ce40d))
27
-
28
- ### [2.2.1](https://github.com/nuxt-community/sitemap-module/compare/v2.2.0...v2.2.1) (2020-04-23)
29
-
30
-
31
- ### Bug Fixes
32
-
33
- * lastmod on sitemapindex ([56d586b](https://github.com/nuxt-community/sitemap-module/commit/56d586b2ecaac977aca44103377d5c73f2f2dbc0)), closes [#112](https://github.com/nuxt-community/sitemap-module/issues/112)
34
- * logs without additional ([9b4773c](https://github.com/nuxt-community/sitemap-module/commit/9b4773c7766422029593905853f4ddbd7ef17220))
35
- * missing warning on generate mode ([d82ee3e](https://github.com/nuxt-community/sitemap-module/commit/d82ee3ea7b2ebcb8203a964b67f57d41f3a2c797))
36
-
37
- ## [2.2.0](https://github.com/nuxt-community/sitemap-module/compare/v2.1.0...v2.2.0) (2020-04-05)
38
-
39
-
40
- ### Features
41
-
42
- * enable ETag header ([ccf3e10](https://github.com/nuxt-community/sitemap-module/commit/ccf3e10a44073c720eb651181db573bc17664a1c)), closes [#80](https://github.com/nuxt-community/sitemap-module/issues/80)
43
-
44
-
45
- ### Bug Fixes
46
-
47
- * force route.url as string ([dc521ab](https://github.com/nuxt-community/sitemap-module/commit/dc521ab32456c511fec8b312c03544312ff2804d))
48
-
49
- ## [2.1.0](https://github.com/nuxt-community/sitemap-module/compare/v2.0.1...v2.1.0) (2020-03-27)
50
-
51
-
52
- ### Features
53
-
54
- * 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)
55
-
56
-
57
- ### Bug Fixes
58
-
59
- * headers of gzipped sitemap ([938d7b6](https://github.com/nuxt-community/sitemap-module/commit/938d7b67cdacee8eb15af6b2d0adaafda08ddaa2))
60
- * omit router data before sitemap creation ([755ec76](https://github.com/nuxt-community/sitemap-module/commit/755ec7647099c362fa18e82492cb9a790f83e46e))
61
-
62
- ### [2.0.1](https://github.com/nuxt-community/sitemap-module/compare/v2.0.0...v2.0.1) (2019-11-12)
63
-
64
-
65
- ### Bug Fixes
66
-
67
- * 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)
68
- * fail on invalid options ([92a4f2f](https://github.com/nuxt-community/sitemap-module/commit/92a4f2f2ac27cd81fb87ac8e2e7dcf8b30ac4c76))
69
-
70
- ## [2.0.0](https://github.com/nuxt-community/sitemap-module/compare/v1.3.1...v2.0.0) (2019-09-29)
71
-
72
-
73
- ### ⚠ BREAKING CHANGES
74
-
75
- * 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))
76
- * Drop support for Nuxt.js 1.x
77
-
78
- ### Features
79
-
80
- * 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)
81
-
82
-
83
- * update dependency sitemap.js to v4 ([795aa1a](https://github.com/nuxt-community/sitemap-module/commit/795aa1a))
84
-
85
- ### [1.3.1](https://github.com/nuxt-community/sitemap-module/compare/v1.3.0...v1.3.1) (2019-09-17)
86
-
87
-
88
- ### Bug Fixes
89
-
90
- * 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)
91
-
92
- ## [1.3.0](https://github.com/nuxt-community/sitemap-module/compare/v1.2.0...v1.3.0) (2019-08-23)
93
-
94
-
95
- ### Features
96
-
97
- * 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)
98
-
99
- ## [1.2.0](https://github.com/nuxt-community/sitemap-module/compare/v1.1.0...v1.2.0) (2019-05-10)
100
-
101
-
102
- ### Bug Fixes
103
-
104
- * generate sitemap from an absolute path ([78f1f32](https://github.com/nuxt-community/sitemap-module/commit/78f1f32))
105
- * harmonize logs for all OS ([276e8fa](https://github.com/nuxt-community/sitemap-module/commit/276e8fa))
106
-
107
-
108
- ### Features
109
-
110
- * add "xmlNs" option to set custom XML namespaces ([751a779](https://github.com/nuxt-community/sitemap-module/commit/751a779))
111
-
112
-
113
-
114
- # [1.1.0](https://github.com/nuxt-community/sitemap-module/compare/v1.0.0...v1.1.0) (2019-05-01)
115
-
116
-
117
- ### Bug Fixes
118
-
119
- * hostname initialization ([56fdddd](https://github.com/nuxt-community/sitemap-module/commit/56fdddd)), closes [#60](https://github.com/nuxt-community/sitemap-module/issues/60)
120
-
121
-
122
- ### Features
123
-
124
- * 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)
125
-
126
-
127
-
128
- # [1.0.0](https://github.com/nuxt-community/sitemap-module/compare/v0.2.2...v1.0.0) (2019-04-15)
129
-
130
-
131
- ### Bug Fixes
132
-
133
- * 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))
134
- * 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)
135
- * create cache ([#47](https://github.com/nuxt-community/sitemap-module/issues/47)) ([cd1d90f](https://github.com/nuxt-community/sitemap-module/commit/cd1d90f))
136
-
137
-
138
- ### Features
139
-
140
- * 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)
141
-
142
-
143
- ### Performance Improvements
144
-
145
- * reduce the use of lodash ([c226f11](https://github.com/nuxt-community/sitemap-module/commit/c226f11))
146
-
147
-
148
- ### BREAKING CHANGES
149
-
150
- * usage of hook that require Nuxt >= 1.0
151
-
152
-
153
-
154
- <a name="0.2.2"></a>
155
- ## [0.2.2](https://github.com/nuxt-community/sitemap-module/compare/v0.2.1...v0.2.2) (2019-03-12)
156
-
157
-
158
- ### Bug Fixes
159
-
160
- * avoid duplicate routes with "index.vue" child-routes ([2315574](https://github.com/nuxt-community/sitemap-module/commit/2315574))
161
-
162
-
163
-
164
- <a name="0.2.1"></a>
165
- ## [0.2.1](https://github.com/nuxt-community/sitemap-module/compare/v0.2.0...v0.2.1) (2019-03-12)
166
-
167
-
168
- ### Bug Fixes
169
-
170
- * 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))
171
-
172
-
173
-
174
- <a name="0.2.0"></a>
175
- # [0.2.0](https://github.com/nuxt-community/sitemap-module/compare/v0.1.2...v0.2.0) (2019-01-02)
176
-
177
-
178
- ### Features
179
-
180
- * add custom `filter` option ([239a1ed](https://github.com/nuxt-community/sitemap-module/commit/239a1ed))
181
-
182
-
183
-
184
- <a name="0.1.2"></a>
185
- ## [0.1.2](https://github.com/nuxt-community/sitemap-module/compare/v0.1.1...v0.1.2) (2018-12-11)
186
-
187
-
188
- ### Bug Fixes
189
-
190
- * fix static folder path ([0e02ea6](https://github.com/nuxt-community/sitemap-module/commit/0e02ea6))
191
-
192
-
193
- <a name="0.1.1"></a>
194
- ## [0.1.1](https://github.com/nuxt-community/sitemap-module/compare/v0.1.0...v0.1.1) (2018-04-16)
195
-
196
-
197
- ### Bug Fixes
198
-
199
- * disable gzip option by default ([fba2943](https://github.com/nuxt-community/sitemap-module/commit/fba2943))
200
- * header of gzipped sitemap ([30edf85](https://github.com/nuxt-community/sitemap-module/commit/30edf85))
201
-
202
-
203
-
204
- <a name="0.1.0"></a>
205
- ## [0.1.0](https://github.com/nuxt-community/sitemap-module/compare/v0.0.5...v0.1.0) (2018-04-16)
206
-
207
-
208
- ### Features
209
-
210
- * 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)
211
-
212
-
213
- ### Performance Improvements
214
-
215
- * optimize lodash imports ([5e1e68f](https://github.com/nuxt-community/sitemap-module/commit/5e1e68f))
216
-
217
-
218
-
219
- <a name="0.0.5"></a>
220
- ## [0.0.5](https://github.com/nuxt-community/sitemap-module/compare/v0.0.4...v0.0.5) (2018-04-14)
221
-
222
-
223
- ### Bug Fixes
224
-
225
- * wrap async calls ([b1b785a](https://github.com/nuxt-community/sitemap-module/commit/b1b785a))
226
-
227
-
228
-
229
- <a name="0.0.4"></a>
230
- ## 0.0.4 (2018-03-20)
231
-
232
-
233
- ### Bug Fixes
234
-
235
- * add routesUnion() method to combine routes arrays ([5d4f5b7](https://github.com/nuxt-community/sitemap-module/commit/5d4f5b7))
236
-
237
-
238
-
239
- <a name="0.0.3"></a>
240
- ## [0.0.3](https://github.com/nuxt/modules/compare/@nuxtjs/sitemap@0.0.2...@nuxtjs/sitemap@0.0.3) (2017-08-03)
241
-
242
-
243
- ### Bug Fixes
244
-
245
- * **sitemap:** nuxt rc compability (#104) ([335ae7a](https://github.com/nuxt/modules/commit/335ae7a))
246
-
247
-
248
-
249
-
250
- <a name="0.0.2"></a>
251
- ## [0.0.2](https://github.com/nuxt/modules/compare/@nuxtjs/sitemap@0.0.1...@nuxtjs/sitemap@0.0.2) (2017-07-25)
252
-
253
-
254
- ### Bug Fixes
255
-
256
- * **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,174 +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
- // Group each route with its alternative languages
48
- if (options.i18n) {
49
- const { defaultLocale, locales, routesNameSeparator } = options.i18n
50
-
51
- // Set alternate routes for each page
52
- const i18nRoutes = routes.reduce((i18nRoutes, route, index) => {
53
- if (!route.name) {
54
- // Route without alternate link
55
- i18nRoutes[`#${index}`] = route
56
- return i18nRoutes
57
- }
58
-
59
- let [page, lang, isDefault] = route.name.split(routesNameSeparator) // eslint-disable-line prefer-const
60
-
61
- // Get i18n route, or init it
62
- const i18nRoute = i18nRoutes[page] || { ...route }
63
-
64
- if (lang) {
65
- // Set main link
66
- if (isDefault) {
67
- lang = 'x-default'
68
- }
69
- if (lang === defaultLocale) {
70
- i18nRoute.url = route.url
71
- }
72
-
73
- // Set alternate links
74
- if (!i18nRoute.links) {
75
- i18nRoute.links = []
76
- }
77
-
78
- const locale = locales.find(({ code }) => code === lang) || { iso: lang }
79
- i18nRoute.links.push({
80
- lang: locale.iso,
81
- url: join('.', route.url),
82
- })
83
- } else {
84
- // No alternate link found
85
- i18nRoute.url = route.url
86
- }
87
-
88
- i18nRoutes[page] = i18nRoute
89
- return i18nRoutes
90
- }, {})
91
-
92
- routes = Object.values(i18nRoutes)
93
- }
94
-
95
- // Enable the custom filter function for each declared route
96
- if (typeof options.filter === 'function') {
97
- routes = options.filter({
98
- options: { ...sitemapConfig },
99
- routes,
100
- })
101
- }
102
-
103
- routes = routes.map((route) => {
104
- // Omit the router data
105
- const { chunkName, component, name, path, ...sitemapOptions } = route
106
-
107
- // Normalize to absolute path
108
- return {
109
- ...sitemapOptions,
110
- url: join('.', String(sitemapOptions.url)),
111
- }
112
- })
113
-
114
- // Set urls
115
- sitemapConfig.urls = routes
116
-
117
- // Create sitemap instance
118
- return sm.createSitemap(sitemapConfig)
119
- }
120
-
121
- /**
122
- * Initialize a fresh sitemapindex instance
123
- *
124
- * @param {Object} options
125
- * @param {string} base
126
- * @param {Request} req
127
- * @returns {string}
128
- */
129
- function createSitemapIndex(options, base = null, req = null) {
130
- const sitemapIndexConfig = {}
131
-
132
- // Set urls
133
- const defaultHostname = options.hostname
134
- sitemapIndexConfig.urls = options.sitemaps.map((options) => {
135
- // Normalize to absolute path
136
- const path = join('.', options.gzip ? `${options.path}.gz` : options.path)
137
- const hostname = getHostname(options.hostname ? options : { ...options, hostname: defaultHostname }, req, base)
138
- const url = new URL(path, hostname)
139
- return { url: url.href, lastmod: options.lastmod }
140
- })
141
-
142
- // Set lastmod for each sitemap
143
- sitemapIndexConfig.lastmod = options.lastmod
144
-
145
- // Set XML namespaces
146
- sitemapIndexConfig.xmlNs = options.xmlNs
147
-
148
- // Set XSL url
149
- sitemapIndexConfig.xslUrl = options.xslUrl
150
-
151
- // Create a sitemapindex
152
- return sm.buildSitemapIndex(sitemapIndexConfig)
153
- }
154
-
155
- /**
156
- * Determine the current hostname
157
- *
158
- * @param {Object} options
159
- * @param {Request} req
160
- * @param {string} base
161
- * @returns {string}
162
- */
163
- function getHostname(options, req, base) {
164
- /* istanbul ignore if */
165
- if (!options.hostname && !req) {
166
- logger.fatal('The `hostname` option is mandatory in your config on `spa` or `generate` build mode', options)
167
- }
168
- return join(
169
- options.hostname || (req && `${isHTTPS(req) ? 'https' : 'http'}://${req.headers.host}`) || `http://${hostname()}`,
170
- base
171
- )
172
- }
173
-
174
- 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 }