vite-plugin-sitemap 0.6.0 → 0.6.1
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/dist/index.js +317 -192
- package/dist/index.mjs +317 -192
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import require$$0$2 from 'path';
|
|
|
7
7
|
import require$$1 from 'child_process';
|
|
8
8
|
import { createRequire } from 'module';
|
|
9
9
|
import require$$1$1 from 'string_decoder';
|
|
10
|
-
import require$$1
|
|
10
|
+
import require$$3$1 from 'zlib';
|
|
11
11
|
import require$$0$3 from 'util';
|
|
12
12
|
import { isAbsolute, resolve, parse as parse$4, join } from 'node:path';
|
|
13
13
|
import require$$0$4 from 'os';
|
|
@@ -1083,8 +1083,12 @@ utils$l.normalizeURL = normalizeURL;
|
|
|
1083
1083
|
this.hasHeadOutput = true;
|
|
1084
1084
|
this.push(getURLSetNs(this.xmlNS, this.xslUrl));
|
|
1085
1085
|
}
|
|
1086
|
-
this.smiStream.write((0, utils_1.validateSMIOptions)((0, utils_1.normalizeURL)(item, this.hostname, this.lastmodDateOnly), this.level, this.errorHandler))
|
|
1087
|
-
|
|
1086
|
+
if (!this.smiStream.write((0, utils_1.validateSMIOptions)((0, utils_1.normalizeURL)(item, this.hostname, this.lastmodDateOnly), this.level, this.errorHandler))) {
|
|
1087
|
+
this.smiStream.once('drain', callback);
|
|
1088
|
+
}
|
|
1089
|
+
else {
|
|
1090
|
+
process.nextTick(callback);
|
|
1091
|
+
}
|
|
1088
1092
|
}
|
|
1089
1093
|
_flush(cb) {
|
|
1090
1094
|
if (!this.hasHeadOutput) {
|
|
@@ -1098,19 +1102,31 @@ utils$l.normalizeURL = normalizeURL;
|
|
|
1098
1102
|
}
|
|
1099
1103
|
exports.SitemapStream = SitemapStream;
|
|
1100
1104
|
/**
|
|
1101
|
-
*
|
|
1102
|
-
*
|
|
1105
|
+
* Converts a readable stream into a promise that resolves with the concatenated data from the stream.
|
|
1106
|
+
*
|
|
1107
|
+
* The function listens for 'data' events from the stream, and when the stream ends, it resolves the promise with the concatenated data. If an error occurs while reading from the stream, the promise is rejected with the error.
|
|
1108
|
+
*
|
|
1109
|
+
* ⚠️ CAUTION: This function should not generally be used in production / when writing to files as it holds a copy of the entire file contents in memory until finished.
|
|
1110
|
+
*
|
|
1111
|
+
* @param {Readable} stream - The readable stream to convert to a promise.
|
|
1112
|
+
* @returns {Promise<Buffer>} A promise that resolves with the concatenated data from the stream as a Buffer, or rejects with an error if one occurred while reading from the stream. If the stream is empty, the promise is rejected with an EmptyStream error.
|
|
1113
|
+
* @throws {EmptyStream} If the stream is empty.
|
|
1103
1114
|
*/
|
|
1104
1115
|
function streamToPromise(stream) {
|
|
1105
1116
|
return new Promise((resolve, reject) => {
|
|
1106
1117
|
const drain = [];
|
|
1107
1118
|
stream
|
|
1119
|
+
// Error propagation is not automatic
|
|
1120
|
+
// Bubble up errors on the read stream
|
|
1121
|
+
.on('error', reject)
|
|
1108
1122
|
.pipe(new stream_1.Writable({
|
|
1109
1123
|
write(chunk, enc, next) {
|
|
1110
1124
|
drain.push(chunk);
|
|
1111
1125
|
next();
|
|
1112
1126
|
},
|
|
1113
1127
|
}))
|
|
1128
|
+
// This bubbles up errors when writing to the internal buffer
|
|
1129
|
+
// This is unlikely to happen, but we have this for completeness
|
|
1114
1130
|
.on('error', reject)
|
|
1115
1131
|
.on('finish', () => {
|
|
1116
1132
|
if (!drain.length) {
|
|
@@ -1142,7 +1158,27 @@ utils$l.normalizeURL = normalizeURL;
|
|
|
1142
1158
|
const sitemapIndexTagStart = '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
|
|
1143
1159
|
const closetag = '</sitemapindex>';
|
|
1144
1160
|
const defaultStreamOpts = {};
|
|
1161
|
+
/**
|
|
1162
|
+
* `SitemapIndexStream` is a Transform stream that takes `IndexItem`s or sitemap URL strings and outputs a stream of sitemap index XML.
|
|
1163
|
+
*
|
|
1164
|
+
* It automatically handles the XML declaration and the opening and closing tags for the sitemap index.
|
|
1165
|
+
*
|
|
1166
|
+
* ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
|
|
1167
|
+
* before `finish` will be emitted. Failure to read the stream will result in hangs.
|
|
1168
|
+
*
|
|
1169
|
+
* @extends {Transform}
|
|
1170
|
+
*/
|
|
1145
1171
|
class SitemapIndexStream extends stream_1.Transform {
|
|
1172
|
+
/**
|
|
1173
|
+
* `SitemapIndexStream` is a Transform stream that takes `IndexItem`s or sitemap URL strings and outputs a stream of sitemap index XML.
|
|
1174
|
+
*
|
|
1175
|
+
* It automatically handles the XML declaration and the opening and closing tags for the sitemap index.
|
|
1176
|
+
*
|
|
1177
|
+
* ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
|
|
1178
|
+
* before `finish` will be emitted. Failure to read the stream will result in hangs.
|
|
1179
|
+
*
|
|
1180
|
+
* @param {SitemapIndexStreamOptions} [opts=defaultStreamOpts] - Stream options.
|
|
1181
|
+
*/
|
|
1146
1182
|
constructor(opts = defaultStreamOpts) {
|
|
1147
1183
|
var _a;
|
|
1148
1184
|
opts.objectMode = true;
|
|
@@ -1152,14 +1188,17 @@ utils$l.normalizeURL = normalizeURL;
|
|
|
1152
1188
|
this.level = (_a = opts.level) !== null && _a !== void 0 ? _a : types_1.ErrorLevel.WARN;
|
|
1153
1189
|
this.xslUrl = opts.xslUrl;
|
|
1154
1190
|
}
|
|
1191
|
+
writeHeadOutput() {
|
|
1192
|
+
this.hasHeadOutput = true;
|
|
1193
|
+
let stylesheet = '';
|
|
1194
|
+
if (this.xslUrl) {
|
|
1195
|
+
stylesheet = (0, sitemap_stream_1.stylesheetInclude)(this.xslUrl);
|
|
1196
|
+
}
|
|
1197
|
+
this.push(xmlDec + stylesheet + sitemapIndexTagStart);
|
|
1198
|
+
}
|
|
1155
1199
|
_transform(item, encoding, callback) {
|
|
1156
1200
|
if (!this.hasHeadOutput) {
|
|
1157
|
-
this.
|
|
1158
|
-
let stylesheet = '';
|
|
1159
|
-
if (this.xslUrl) {
|
|
1160
|
-
stylesheet = (0, sitemap_stream_1.stylesheetInclude)(this.xslUrl);
|
|
1161
|
-
}
|
|
1162
|
-
this.push(xmlDec + stylesheet + sitemapIndexTagStart);
|
|
1201
|
+
this.writeHeadOutput();
|
|
1163
1202
|
}
|
|
1164
1203
|
this.push((0, sitemap_xml_1.otag)(IndexTagNames.sitemap));
|
|
1165
1204
|
if (typeof item === 'string') {
|
|
@@ -1176,55 +1215,143 @@ utils$l.normalizeURL = normalizeURL;
|
|
|
1176
1215
|
callback();
|
|
1177
1216
|
}
|
|
1178
1217
|
_flush(cb) {
|
|
1218
|
+
if (!this.hasHeadOutput) {
|
|
1219
|
+
this.writeHeadOutput();
|
|
1220
|
+
}
|
|
1179
1221
|
this.push(closetag);
|
|
1180
1222
|
cb();
|
|
1181
1223
|
}
|
|
1182
1224
|
}
|
|
1183
1225
|
exports.SitemapIndexStream = SitemapIndexStream;
|
|
1184
|
-
|
|
1226
|
+
/**
|
|
1227
|
+
* `SitemapAndIndexStream` is a Transform stream that takes in sitemap items,
|
|
1228
|
+
* writes them to sitemap files, adds the sitemap files to a sitemap index,
|
|
1229
|
+
* and creates new sitemap files when the count limit is reached.
|
|
1230
|
+
*
|
|
1231
|
+
* It waits for the target stream of the current sitemap file to finish before
|
|
1232
|
+
* moving on to the next if the target stream is returned by the `getSitemapStream`
|
|
1233
|
+
* callback in the 3rd position of the tuple.
|
|
1234
|
+
*
|
|
1235
|
+
* ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
|
|
1236
|
+
* before `finish` will be emitted. Failure to read the stream will result in hangs.
|
|
1237
|
+
*
|
|
1238
|
+
* @extends {SitemapIndexStream}
|
|
1239
|
+
*/
|
|
1185
1240
|
class SitemapAndIndexStream extends SitemapIndexStream {
|
|
1241
|
+
/**
|
|
1242
|
+
* `SitemapAndIndexStream` is a Transform stream that takes in sitemap items,
|
|
1243
|
+
* writes them to sitemap files, adds the sitemap files to a sitemap index,
|
|
1244
|
+
* and creates new sitemap files when the count limit is reached.
|
|
1245
|
+
*
|
|
1246
|
+
* It waits for the target stream of the current sitemap file to finish before
|
|
1247
|
+
* moving on to the next if the target stream is returned by the `getSitemapStream`
|
|
1248
|
+
* callback in the 3rd position of the tuple.
|
|
1249
|
+
*
|
|
1250
|
+
* ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
|
|
1251
|
+
* before `finish` will be emitted. Failure to read the stream will result in hangs.
|
|
1252
|
+
*
|
|
1253
|
+
* @param {SitemapAndIndexStreamOptions} opts - Stream options.
|
|
1254
|
+
*/
|
|
1186
1255
|
constructor(opts) {
|
|
1187
1256
|
var _a;
|
|
1188
1257
|
opts.objectMode = true;
|
|
1189
1258
|
super(opts);
|
|
1190
|
-
this.
|
|
1259
|
+
this.itemsWritten = 0;
|
|
1191
1260
|
this.getSitemapStream = opts.getSitemapStream;
|
|
1192
|
-
[this.idxItem, this.currentSitemap, this.currentSitemapPipeline] =
|
|
1193
|
-
this.getSitemapStream(0);
|
|
1194
1261
|
this.limit = (_a = opts.limit) !== null && _a !== void 0 ? _a : 45000;
|
|
1195
1262
|
}
|
|
1196
|
-
_writeSMI(item) {
|
|
1197
|
-
this.currentSitemap.write(item);
|
|
1198
|
-
this.i++;
|
|
1199
|
-
}
|
|
1200
1263
|
_transform(item, encoding, callback) {
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1264
|
+
if (this.itemsWritten % this.limit === 0) {
|
|
1265
|
+
if (this.currentSitemap) {
|
|
1266
|
+
const onFinish = new Promise((resolve, reject) => {
|
|
1267
|
+
var _a, _b, _c;
|
|
1268
|
+
(_a = this.currentSitemap) === null || _a === void 0 ? void 0 : _a.on('finish', resolve);
|
|
1269
|
+
(_b = this.currentSitemap) === null || _b === void 0 ? void 0 : _b.on('error', reject);
|
|
1270
|
+
(_c = this.currentSitemap) === null || _c === void 0 ? void 0 : _c.end();
|
|
1271
|
+
});
|
|
1272
|
+
const onPipelineFinish = this.currentSitemapPipeline
|
|
1273
|
+
? new Promise((resolve, reject) => {
|
|
1274
|
+
var _a, _b;
|
|
1275
|
+
(_a = this.currentSitemapPipeline) === null || _a === void 0 ? void 0 : _a.on('finish', resolve);
|
|
1276
|
+
(_b = this.currentSitemapPipeline) === null || _b === void 0 ? void 0 : _b.on('error', reject);
|
|
1277
|
+
})
|
|
1278
|
+
: Promise.resolve();
|
|
1279
|
+
Promise.all([onFinish, onPipelineFinish])
|
|
1280
|
+
.then(() => {
|
|
1281
|
+
this.createSitemap(encoding);
|
|
1282
|
+
this.writeItem(item, callback);
|
|
1283
|
+
})
|
|
1284
|
+
.catch(callback);
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
else {
|
|
1288
|
+
this.createSitemap(encoding);
|
|
1289
|
+
}
|
|
1205
1290
|
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
(_a = this.currentSitemapPipeline) === null || _a === void 0 ? void 0 : _a.on('finish', onFinish);
|
|
1216
|
-
this.currentSitemap.end(!this.currentSitemapPipeline ? onFinish : undefined);
|
|
1291
|
+
this.writeItem(item, callback);
|
|
1292
|
+
}
|
|
1293
|
+
writeItem(item, callback) {
|
|
1294
|
+
if (!this.currentSitemap) {
|
|
1295
|
+
callback(new Error('No sitemap stream available'));
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
if (!this.currentSitemap.write(item)) {
|
|
1299
|
+
this.currentSitemap.once('drain', callback);
|
|
1217
1300
|
}
|
|
1218
1301
|
else {
|
|
1219
|
-
|
|
1220
|
-
callback();
|
|
1302
|
+
process.nextTick(callback);
|
|
1221
1303
|
}
|
|
1304
|
+
// Increment the count of items written
|
|
1305
|
+
this.itemsWritten++;
|
|
1222
1306
|
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Called when the stream is finished.
|
|
1309
|
+
* If there is a current sitemap, we wait for it to finish before calling the callback.
|
|
1310
|
+
*
|
|
1311
|
+
* @param cb
|
|
1312
|
+
*/
|
|
1223
1313
|
_flush(cb) {
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1314
|
+
const onFinish = new Promise((resolve, reject) => {
|
|
1315
|
+
if (this.currentSitemap) {
|
|
1316
|
+
this.currentSitemap.on('finish', resolve);
|
|
1317
|
+
this.currentSitemap.on('error', reject);
|
|
1318
|
+
this.currentSitemap.end();
|
|
1319
|
+
}
|
|
1320
|
+
else {
|
|
1321
|
+
resolve();
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
const onPipelineFinish = new Promise((resolve, reject) => {
|
|
1325
|
+
if (this.currentSitemapPipeline) {
|
|
1326
|
+
this.currentSitemapPipeline.on('finish', resolve);
|
|
1327
|
+
this.currentSitemapPipeline.on('error', reject);
|
|
1328
|
+
// The pipeline (pipe target) will get it's end() call
|
|
1329
|
+
// from the sitemap stream ending.
|
|
1330
|
+
}
|
|
1331
|
+
else {
|
|
1332
|
+
resolve();
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1335
|
+
Promise.all([onFinish, onPipelineFinish])
|
|
1336
|
+
.then(() => {
|
|
1337
|
+
super._flush(cb);
|
|
1338
|
+
})
|
|
1339
|
+
.catch((err) => {
|
|
1340
|
+
cb(err);
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
createSitemap(encoding) {
|
|
1344
|
+
const [idxItem, currentSitemap, currentSitemapPipeline] = this.getSitemapStream(this.itemsWritten / this.limit);
|
|
1345
|
+
currentSitemap.on('error', (err) => this.emit('error', err));
|
|
1346
|
+
this.currentSitemap = currentSitemap;
|
|
1347
|
+
this.currentSitemapPipeline = currentSitemapPipeline;
|
|
1348
|
+
super._transform(idxItem, encoding, () => {
|
|
1349
|
+
// We are not too fussed about waiting for the index item to be written
|
|
1350
|
+
// we we'll wait for the file to finish at the end
|
|
1351
|
+
// and index file write volume tends to be small in comprarison to sitemap
|
|
1352
|
+
// writes.
|
|
1353
|
+
// noop
|
|
1354
|
+
});
|
|
1228
1355
|
}
|
|
1229
1356
|
}
|
|
1230
1357
|
exports.SitemapAndIndexStream = SitemapAndIndexStream;
|
|
@@ -3283,12 +3410,17 @@ class XMLToSitemapItemStream extends stream_1$7.Transform {
|
|
|
3283
3410
|
}
|
|
3284
3411
|
_transform(data, encoding, callback) {
|
|
3285
3412
|
try {
|
|
3413
|
+
const cb = () => callback(this.level === types_1$1.ErrorLevel.THROW ? this.error : null);
|
|
3286
3414
|
// correcting the type here can be done without making it a breaking change
|
|
3287
3415
|
// TODO fix this
|
|
3288
3416
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3289
3417
|
// @ts-ignore
|
|
3290
|
-
this.saxStream.write(data, encoding)
|
|
3291
|
-
|
|
3418
|
+
if (!this.saxStream.write(data, encoding)) {
|
|
3419
|
+
this.saxStream.once('drain', cb);
|
|
3420
|
+
}
|
|
3421
|
+
else {
|
|
3422
|
+
process.nextTick(cb);
|
|
3423
|
+
}
|
|
3292
3424
|
}
|
|
3293
3425
|
catch (error) {
|
|
3294
3426
|
callback(error);
|
|
@@ -3557,152 +3689,138 @@ sitemapIndexParser.IndexObjectStreamToJSON = IndexObjectStreamToJSON;
|
|
|
3557
3689
|
|
|
3558
3690
|
var sitemapSimple = {};
|
|
3559
3691
|
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
}
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
Object.defineProperty(exports, "parseSitemap", { enumerable: true, get: function () { return sitemap_parser_1.parseSitemap; } });
|
|
3693
|
-
Object.defineProperty(exports, "XMLToSitemapItemStream", { enumerable: true, get: function () { return sitemap_parser_1.XMLToSitemapItemStream; } });
|
|
3694
|
-
Object.defineProperty(exports, "ObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_parser_1.ObjectStreamToJSON; } });
|
|
3695
|
-
var sitemap_index_parser_1 = sitemapIndexParser;
|
|
3696
|
-
Object.defineProperty(exports, "parseSitemapIndex", { enumerable: true, get: function () { return sitemap_index_parser_1.parseSitemapIndex; } });
|
|
3697
|
-
Object.defineProperty(exports, "XMLToSitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_parser_1.XMLToSitemapIndexStream; } });
|
|
3698
|
-
Object.defineProperty(exports, "IndexObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_index_parser_1.IndexObjectStreamToJSON; } });
|
|
3699
|
-
var sitemap_simple_1 = requireSitemapSimple();
|
|
3700
|
-
Object.defineProperty(exports, "simpleSitemapAndIndex", { enumerable: true, get: function () { return sitemap_simple_1.simpleSitemapAndIndex; } });
|
|
3701
|
-
} (dist));
|
|
3702
|
-
return dist;
|
|
3703
|
-
}
|
|
3704
|
-
|
|
3705
|
-
var distExports = requireDist();
|
|
3692
|
+
(function (exports) {
|
|
3693
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3694
|
+
exports.simpleSitemapAndIndex = void 0;
|
|
3695
|
+
const sitemap_index_stream_1 = sitemapIndexStream;
|
|
3696
|
+
const sitemap_stream_1 = sitemapStream;
|
|
3697
|
+
const utils_1 = utils$l;
|
|
3698
|
+
const zlib_1 = require$$3$1;
|
|
3699
|
+
const fs_1 = require$$0$1;
|
|
3700
|
+
const path_1 = require$$0$2;
|
|
3701
|
+
const stream_1 = require$$0;
|
|
3702
|
+
const util_1 = require$$0$3;
|
|
3703
|
+
const url_1 = require$$3;
|
|
3704
|
+
const pipeline = (0, util_1.promisify)(stream_1.pipeline);
|
|
3705
|
+
/**
|
|
3706
|
+
*
|
|
3707
|
+
* @param {object} options -
|
|
3708
|
+
* @param {string} options.hostname - The hostname for all URLs
|
|
3709
|
+
* @param {string} [options.sitemapHostname] - The hostname for the sitemaps if different than hostname
|
|
3710
|
+
* @param {SitemapItemLoose[] | string | Readable | string[]} options.sourceData - The urls you want to make a sitemap out of.
|
|
3711
|
+
* @param {string} options.destinationDir - where to write the sitemaps and index
|
|
3712
|
+
* @param {string} [options.publicBasePath] - where the sitemaps are relative to the hostname. Defaults to root.
|
|
3713
|
+
* @param {number} [options.limit] - how many URLs to write before switching to a new file. Defaults to 50k
|
|
3714
|
+
* @param {boolean} [options.gzip] - whether to compress the written files. Defaults to true
|
|
3715
|
+
* @returns {Promise<void>} an empty promise that resolves when everything is done
|
|
3716
|
+
*/
|
|
3717
|
+
const simpleSitemapAndIndex = async ({ hostname, sitemapHostname = hostname, // if different
|
|
3718
|
+
/**
|
|
3719
|
+
* Pass a line separated list of sitemap items or a stream or an array
|
|
3720
|
+
*/
|
|
3721
|
+
sourceData, destinationDir, limit = 50000, gzip = true, publicBasePath = './', }) => {
|
|
3722
|
+
await fs_1.promises.mkdir(destinationDir, { recursive: true });
|
|
3723
|
+
const sitemapAndIndexStream = new sitemap_index_stream_1.SitemapAndIndexStream({
|
|
3724
|
+
limit,
|
|
3725
|
+
getSitemapStream: (i) => {
|
|
3726
|
+
const sitemapStream = new sitemap_stream_1.SitemapStream({
|
|
3727
|
+
hostname,
|
|
3728
|
+
});
|
|
3729
|
+
const path = `./sitemap-${i}.xml`;
|
|
3730
|
+
const writePath = (0, path_1.resolve)(destinationDir, path + (gzip ? '.gz' : ''));
|
|
3731
|
+
if (!publicBasePath.endsWith('/')) {
|
|
3732
|
+
publicBasePath += '/';
|
|
3733
|
+
}
|
|
3734
|
+
const publicPath = (0, path_1.normalize)(publicBasePath + path);
|
|
3735
|
+
let pipeline;
|
|
3736
|
+
if (gzip) {
|
|
3737
|
+
pipeline = sitemapStream
|
|
3738
|
+
.pipe((0, zlib_1.createGzip)()) // compress the output of the sitemap
|
|
3739
|
+
.pipe((0, fs_1.createWriteStream)(writePath)); // write it to sitemap-NUMBER.xml
|
|
3740
|
+
}
|
|
3741
|
+
else {
|
|
3742
|
+
pipeline = sitemapStream.pipe((0, fs_1.createWriteStream)(writePath)); // write it to sitemap-NUMBER.xml
|
|
3743
|
+
}
|
|
3744
|
+
return [
|
|
3745
|
+
new url_1.URL(`${publicPath}${gzip ? '.gz' : ''}`, sitemapHostname).toString(),
|
|
3746
|
+
sitemapStream,
|
|
3747
|
+
pipeline,
|
|
3748
|
+
];
|
|
3749
|
+
},
|
|
3750
|
+
});
|
|
3751
|
+
let src;
|
|
3752
|
+
if (typeof sourceData === 'string') {
|
|
3753
|
+
src = (0, utils_1.lineSeparatedURLsToSitemapOptions)((0, fs_1.createReadStream)(sourceData));
|
|
3754
|
+
}
|
|
3755
|
+
else if (sourceData instanceof stream_1.Readable) {
|
|
3756
|
+
src = sourceData;
|
|
3757
|
+
}
|
|
3758
|
+
else if (Array.isArray(sourceData)) {
|
|
3759
|
+
src = stream_1.Readable.from(sourceData);
|
|
3760
|
+
}
|
|
3761
|
+
else {
|
|
3762
|
+
throw new Error("unhandled source type. You've passed in data that is not supported");
|
|
3763
|
+
}
|
|
3764
|
+
const writePath = (0, path_1.resolve)(destinationDir, `./sitemap-index.xml${gzip ? '.gz' : ''}`);
|
|
3765
|
+
if (gzip) {
|
|
3766
|
+
return pipeline(src, sitemapAndIndexStream, (0, zlib_1.createGzip)(), (0, fs_1.createWriteStream)(writePath));
|
|
3767
|
+
}
|
|
3768
|
+
else {
|
|
3769
|
+
return pipeline(src, sitemapAndIndexStream, (0, fs_1.createWriteStream)(writePath));
|
|
3770
|
+
}
|
|
3771
|
+
};
|
|
3772
|
+
exports.simpleSitemapAndIndex = simpleSitemapAndIndex;
|
|
3773
|
+
exports.default = exports.simpleSitemapAndIndex;
|
|
3774
|
+
} (sitemapSimple));
|
|
3775
|
+
|
|
3776
|
+
(function (exports) {
|
|
3777
|
+
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3778
|
+
if (k2 === undefined) k2 = k;
|
|
3779
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
3780
|
+
}) : (function(o, m, k, k2) {
|
|
3781
|
+
if (k2 === undefined) k2 = k;
|
|
3782
|
+
o[k2] = m[k];
|
|
3783
|
+
}));
|
|
3784
|
+
var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
|
|
3785
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
3786
|
+
};
|
|
3787
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3788
|
+
exports.simpleSitemapAndIndex = exports.IndexObjectStreamToJSON = exports.XMLToSitemapIndexStream = exports.parseSitemapIndex = exports.ObjectStreamToJSON = exports.XMLToSitemapItemStream = exports.parseSitemap = exports.xmlLint = exports.ReadlineStream = exports.normalizeURL = exports.validateSMIOptions = exports.mergeStreams = exports.lineSeparatedURLsToSitemapOptions = exports.SitemapStream = exports.streamToPromise = exports.SitemapAndIndexStream = exports.SitemapIndexStream = exports.IndexTagNames = exports.SitemapItemStream = void 0;
|
|
3789
|
+
/*!
|
|
3790
|
+
* Sitemap
|
|
3791
|
+
* Copyright(c) 2011 Eugene Kalinin
|
|
3792
|
+
* MIT Licensed
|
|
3793
|
+
*/
|
|
3794
|
+
var sitemap_item_stream_1 = sitemapItemStream;
|
|
3795
|
+
Object.defineProperty(exports, "SitemapItemStream", { enumerable: true, get: function () { return sitemap_item_stream_1.SitemapItemStream; } });
|
|
3796
|
+
var sitemap_index_stream_1 = sitemapIndexStream;
|
|
3797
|
+
Object.defineProperty(exports, "IndexTagNames", { enumerable: true, get: function () { return sitemap_index_stream_1.IndexTagNames; } });
|
|
3798
|
+
Object.defineProperty(exports, "SitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapIndexStream; } });
|
|
3799
|
+
Object.defineProperty(exports, "SitemapAndIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapAndIndexStream; } });
|
|
3800
|
+
var sitemap_stream_1 = sitemapStream;
|
|
3801
|
+
Object.defineProperty(exports, "streamToPromise", { enumerable: true, get: function () { return sitemap_stream_1.streamToPromise; } });
|
|
3802
|
+
Object.defineProperty(exports, "SitemapStream", { enumerable: true, get: function () { return sitemap_stream_1.SitemapStream; } });
|
|
3803
|
+
__exportStar(errors, exports);
|
|
3804
|
+
__exportStar(types, exports);
|
|
3805
|
+
var utils_1 = utils$l;
|
|
3806
|
+
Object.defineProperty(exports, "lineSeparatedURLsToSitemapOptions", { enumerable: true, get: function () { return utils_1.lineSeparatedURLsToSitemapOptions; } });
|
|
3807
|
+
Object.defineProperty(exports, "mergeStreams", { enumerable: true, get: function () { return utils_1.mergeStreams; } });
|
|
3808
|
+
Object.defineProperty(exports, "validateSMIOptions", { enumerable: true, get: function () { return utils_1.validateSMIOptions; } });
|
|
3809
|
+
Object.defineProperty(exports, "normalizeURL", { enumerable: true, get: function () { return utils_1.normalizeURL; } });
|
|
3810
|
+
Object.defineProperty(exports, "ReadlineStream", { enumerable: true, get: function () { return utils_1.ReadlineStream; } });
|
|
3811
|
+
var xmllint_1 = xmllint;
|
|
3812
|
+
Object.defineProperty(exports, "xmlLint", { enumerable: true, get: function () { return xmllint_1.xmlLint; } });
|
|
3813
|
+
var sitemap_parser_1 = sitemapParser;
|
|
3814
|
+
Object.defineProperty(exports, "parseSitemap", { enumerable: true, get: function () { return sitemap_parser_1.parseSitemap; } });
|
|
3815
|
+
Object.defineProperty(exports, "XMLToSitemapItemStream", { enumerable: true, get: function () { return sitemap_parser_1.XMLToSitemapItemStream; } });
|
|
3816
|
+
Object.defineProperty(exports, "ObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_parser_1.ObjectStreamToJSON; } });
|
|
3817
|
+
var sitemap_index_parser_1 = sitemapIndexParser;
|
|
3818
|
+
Object.defineProperty(exports, "parseSitemapIndex", { enumerable: true, get: function () { return sitemap_index_parser_1.parseSitemapIndex; } });
|
|
3819
|
+
Object.defineProperty(exports, "XMLToSitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_parser_1.XMLToSitemapIndexStream; } });
|
|
3820
|
+
Object.defineProperty(exports, "IndexObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_index_parser_1.IndexObjectStreamToJSON; } });
|
|
3821
|
+
var sitemap_simple_1 = sitemapSimple;
|
|
3822
|
+
Object.defineProperty(exports, "simpleSitemapAndIndex", { enumerable: true, get: function () { return sitemap_simple_1.simpleSitemapAndIndex; } });
|
|
3823
|
+
} (dist));
|
|
3706
3824
|
|
|
3707
3825
|
var cjs$1 = {exports: {}};
|
|
3708
3826
|
|
|
@@ -10986,8 +11104,15 @@ function getFormattedSitemap(options, routes) {
|
|
|
10986
11104
|
priority: getOptionByRoute(options.priority, route) ?? defaultOptions.priority,
|
|
10987
11105
|
lastmod: getOptionByRoute(options.lastmod, route) ?? defaultOptions.lastmod
|
|
10988
11106
|
};
|
|
10989
|
-
if (options.i18n)
|
|
10990
|
-
|
|
11107
|
+
if (options.i18n) {
|
|
11108
|
+
const languages = options.i18n.languages.map((str) => ({
|
|
11109
|
+
lang: str,
|
|
11110
|
+
url: str === options.i18n?.defaultLanguage ? url : `${url}/${str}`
|
|
11111
|
+
}));
|
|
11112
|
+
return Object.assign(formattedSitemap, {
|
|
11113
|
+
links: options.i18n.defaultLanguage ? [...languages, { lang: "x-default", url }] : languages
|
|
11114
|
+
});
|
|
11115
|
+
}
|
|
10991
11116
|
return formattedSitemap;
|
|
10992
11117
|
});
|
|
10993
11118
|
}
|
|
@@ -11003,9 +11128,9 @@ function generateSitemap(options = {}) {
|
|
|
11003
11128
|
if (!routes.length)
|
|
11004
11129
|
return;
|
|
11005
11130
|
const formattedSitemap = getFormattedSitemap(resolvedOptions, routes);
|
|
11006
|
-
const stream = new
|
|
11131
|
+
const stream = new dist.SitemapStream();
|
|
11007
11132
|
formattedSitemap.forEach((item) => stream.write(item));
|
|
11008
|
-
|
|
11133
|
+
dist.streamToPromise(stream).then((sitemap) => {
|
|
11009
11134
|
const utfSitemap = sitemap.toString("utf-8");
|
|
11010
11135
|
const formattedSitemap2 = resolvedOptions.readable ? format(utfSitemap) : utfSitemap;
|
|
11011
11136
|
writeFileSync(getResolvedPath("sitemap.xml", resolvedOptions), formattedSitemap2);
|
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import require$$0$2 from 'path';
|
|
|
7
7
|
import require$$1 from 'child_process';
|
|
8
8
|
import { createRequire } from 'module';
|
|
9
9
|
import require$$1$1 from 'string_decoder';
|
|
10
|
-
import require$$1
|
|
10
|
+
import require$$3$1 from 'zlib';
|
|
11
11
|
import require$$0$3 from 'util';
|
|
12
12
|
import { isAbsolute, resolve, parse as parse$4, join } from 'node:path';
|
|
13
13
|
import require$$0$4 from 'os';
|
|
@@ -1083,8 +1083,12 @@ utils$l.normalizeURL = normalizeURL;
|
|
|
1083
1083
|
this.hasHeadOutput = true;
|
|
1084
1084
|
this.push(getURLSetNs(this.xmlNS, this.xslUrl));
|
|
1085
1085
|
}
|
|
1086
|
-
this.smiStream.write((0, utils_1.validateSMIOptions)((0, utils_1.normalizeURL)(item, this.hostname, this.lastmodDateOnly), this.level, this.errorHandler))
|
|
1087
|
-
|
|
1086
|
+
if (!this.smiStream.write((0, utils_1.validateSMIOptions)((0, utils_1.normalizeURL)(item, this.hostname, this.lastmodDateOnly), this.level, this.errorHandler))) {
|
|
1087
|
+
this.smiStream.once('drain', callback);
|
|
1088
|
+
}
|
|
1089
|
+
else {
|
|
1090
|
+
process.nextTick(callback);
|
|
1091
|
+
}
|
|
1088
1092
|
}
|
|
1089
1093
|
_flush(cb) {
|
|
1090
1094
|
if (!this.hasHeadOutput) {
|
|
@@ -1098,19 +1102,31 @@ utils$l.normalizeURL = normalizeURL;
|
|
|
1098
1102
|
}
|
|
1099
1103
|
exports.SitemapStream = SitemapStream;
|
|
1100
1104
|
/**
|
|
1101
|
-
*
|
|
1102
|
-
*
|
|
1105
|
+
* Converts a readable stream into a promise that resolves with the concatenated data from the stream.
|
|
1106
|
+
*
|
|
1107
|
+
* The function listens for 'data' events from the stream, and when the stream ends, it resolves the promise with the concatenated data. If an error occurs while reading from the stream, the promise is rejected with the error.
|
|
1108
|
+
*
|
|
1109
|
+
* ⚠️ CAUTION: This function should not generally be used in production / when writing to files as it holds a copy of the entire file contents in memory until finished.
|
|
1110
|
+
*
|
|
1111
|
+
* @param {Readable} stream - The readable stream to convert to a promise.
|
|
1112
|
+
* @returns {Promise<Buffer>} A promise that resolves with the concatenated data from the stream as a Buffer, or rejects with an error if one occurred while reading from the stream. If the stream is empty, the promise is rejected with an EmptyStream error.
|
|
1113
|
+
* @throws {EmptyStream} If the stream is empty.
|
|
1103
1114
|
*/
|
|
1104
1115
|
function streamToPromise(stream) {
|
|
1105
1116
|
return new Promise((resolve, reject) => {
|
|
1106
1117
|
const drain = [];
|
|
1107
1118
|
stream
|
|
1119
|
+
// Error propagation is not automatic
|
|
1120
|
+
// Bubble up errors on the read stream
|
|
1121
|
+
.on('error', reject)
|
|
1108
1122
|
.pipe(new stream_1.Writable({
|
|
1109
1123
|
write(chunk, enc, next) {
|
|
1110
1124
|
drain.push(chunk);
|
|
1111
1125
|
next();
|
|
1112
1126
|
},
|
|
1113
1127
|
}))
|
|
1128
|
+
// This bubbles up errors when writing to the internal buffer
|
|
1129
|
+
// This is unlikely to happen, but we have this for completeness
|
|
1114
1130
|
.on('error', reject)
|
|
1115
1131
|
.on('finish', () => {
|
|
1116
1132
|
if (!drain.length) {
|
|
@@ -1142,7 +1158,27 @@ utils$l.normalizeURL = normalizeURL;
|
|
|
1142
1158
|
const sitemapIndexTagStart = '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
|
|
1143
1159
|
const closetag = '</sitemapindex>';
|
|
1144
1160
|
const defaultStreamOpts = {};
|
|
1161
|
+
/**
|
|
1162
|
+
* `SitemapIndexStream` is a Transform stream that takes `IndexItem`s or sitemap URL strings and outputs a stream of sitemap index XML.
|
|
1163
|
+
*
|
|
1164
|
+
* It automatically handles the XML declaration and the opening and closing tags for the sitemap index.
|
|
1165
|
+
*
|
|
1166
|
+
* ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
|
|
1167
|
+
* before `finish` will be emitted. Failure to read the stream will result in hangs.
|
|
1168
|
+
*
|
|
1169
|
+
* @extends {Transform}
|
|
1170
|
+
*/
|
|
1145
1171
|
class SitemapIndexStream extends stream_1.Transform {
|
|
1172
|
+
/**
|
|
1173
|
+
* `SitemapIndexStream` is a Transform stream that takes `IndexItem`s or sitemap URL strings and outputs a stream of sitemap index XML.
|
|
1174
|
+
*
|
|
1175
|
+
* It automatically handles the XML declaration and the opening and closing tags for the sitemap index.
|
|
1176
|
+
*
|
|
1177
|
+
* ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
|
|
1178
|
+
* before `finish` will be emitted. Failure to read the stream will result in hangs.
|
|
1179
|
+
*
|
|
1180
|
+
* @param {SitemapIndexStreamOptions} [opts=defaultStreamOpts] - Stream options.
|
|
1181
|
+
*/
|
|
1146
1182
|
constructor(opts = defaultStreamOpts) {
|
|
1147
1183
|
var _a;
|
|
1148
1184
|
opts.objectMode = true;
|
|
@@ -1152,14 +1188,17 @@ utils$l.normalizeURL = normalizeURL;
|
|
|
1152
1188
|
this.level = (_a = opts.level) !== null && _a !== void 0 ? _a : types_1.ErrorLevel.WARN;
|
|
1153
1189
|
this.xslUrl = opts.xslUrl;
|
|
1154
1190
|
}
|
|
1191
|
+
writeHeadOutput() {
|
|
1192
|
+
this.hasHeadOutput = true;
|
|
1193
|
+
let stylesheet = '';
|
|
1194
|
+
if (this.xslUrl) {
|
|
1195
|
+
stylesheet = (0, sitemap_stream_1.stylesheetInclude)(this.xslUrl);
|
|
1196
|
+
}
|
|
1197
|
+
this.push(xmlDec + stylesheet + sitemapIndexTagStart);
|
|
1198
|
+
}
|
|
1155
1199
|
_transform(item, encoding, callback) {
|
|
1156
1200
|
if (!this.hasHeadOutput) {
|
|
1157
|
-
this.
|
|
1158
|
-
let stylesheet = '';
|
|
1159
|
-
if (this.xslUrl) {
|
|
1160
|
-
stylesheet = (0, sitemap_stream_1.stylesheetInclude)(this.xslUrl);
|
|
1161
|
-
}
|
|
1162
|
-
this.push(xmlDec + stylesheet + sitemapIndexTagStart);
|
|
1201
|
+
this.writeHeadOutput();
|
|
1163
1202
|
}
|
|
1164
1203
|
this.push((0, sitemap_xml_1.otag)(IndexTagNames.sitemap));
|
|
1165
1204
|
if (typeof item === 'string') {
|
|
@@ -1176,55 +1215,143 @@ utils$l.normalizeURL = normalizeURL;
|
|
|
1176
1215
|
callback();
|
|
1177
1216
|
}
|
|
1178
1217
|
_flush(cb) {
|
|
1218
|
+
if (!this.hasHeadOutput) {
|
|
1219
|
+
this.writeHeadOutput();
|
|
1220
|
+
}
|
|
1179
1221
|
this.push(closetag);
|
|
1180
1222
|
cb();
|
|
1181
1223
|
}
|
|
1182
1224
|
}
|
|
1183
1225
|
exports.SitemapIndexStream = SitemapIndexStream;
|
|
1184
|
-
|
|
1226
|
+
/**
|
|
1227
|
+
* `SitemapAndIndexStream` is a Transform stream that takes in sitemap items,
|
|
1228
|
+
* writes them to sitemap files, adds the sitemap files to a sitemap index,
|
|
1229
|
+
* and creates new sitemap files when the count limit is reached.
|
|
1230
|
+
*
|
|
1231
|
+
* It waits for the target stream of the current sitemap file to finish before
|
|
1232
|
+
* moving on to the next if the target stream is returned by the `getSitemapStream`
|
|
1233
|
+
* callback in the 3rd position of the tuple.
|
|
1234
|
+
*
|
|
1235
|
+
* ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
|
|
1236
|
+
* before `finish` will be emitted. Failure to read the stream will result in hangs.
|
|
1237
|
+
*
|
|
1238
|
+
* @extends {SitemapIndexStream}
|
|
1239
|
+
*/
|
|
1185
1240
|
class SitemapAndIndexStream extends SitemapIndexStream {
|
|
1241
|
+
/**
|
|
1242
|
+
* `SitemapAndIndexStream` is a Transform stream that takes in sitemap items,
|
|
1243
|
+
* writes them to sitemap files, adds the sitemap files to a sitemap index,
|
|
1244
|
+
* and creates new sitemap files when the count limit is reached.
|
|
1245
|
+
*
|
|
1246
|
+
* It waits for the target stream of the current sitemap file to finish before
|
|
1247
|
+
* moving on to the next if the target stream is returned by the `getSitemapStream`
|
|
1248
|
+
* callback in the 3rd position of the tuple.
|
|
1249
|
+
*
|
|
1250
|
+
* ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
|
|
1251
|
+
* before `finish` will be emitted. Failure to read the stream will result in hangs.
|
|
1252
|
+
*
|
|
1253
|
+
* @param {SitemapAndIndexStreamOptions} opts - Stream options.
|
|
1254
|
+
*/
|
|
1186
1255
|
constructor(opts) {
|
|
1187
1256
|
var _a;
|
|
1188
1257
|
opts.objectMode = true;
|
|
1189
1258
|
super(opts);
|
|
1190
|
-
this.
|
|
1259
|
+
this.itemsWritten = 0;
|
|
1191
1260
|
this.getSitemapStream = opts.getSitemapStream;
|
|
1192
|
-
[this.idxItem, this.currentSitemap, this.currentSitemapPipeline] =
|
|
1193
|
-
this.getSitemapStream(0);
|
|
1194
1261
|
this.limit = (_a = opts.limit) !== null && _a !== void 0 ? _a : 45000;
|
|
1195
1262
|
}
|
|
1196
|
-
_writeSMI(item) {
|
|
1197
|
-
this.currentSitemap.write(item);
|
|
1198
|
-
this.i++;
|
|
1199
|
-
}
|
|
1200
1263
|
_transform(item, encoding, callback) {
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1264
|
+
if (this.itemsWritten % this.limit === 0) {
|
|
1265
|
+
if (this.currentSitemap) {
|
|
1266
|
+
const onFinish = new Promise((resolve, reject) => {
|
|
1267
|
+
var _a, _b, _c;
|
|
1268
|
+
(_a = this.currentSitemap) === null || _a === void 0 ? void 0 : _a.on('finish', resolve);
|
|
1269
|
+
(_b = this.currentSitemap) === null || _b === void 0 ? void 0 : _b.on('error', reject);
|
|
1270
|
+
(_c = this.currentSitemap) === null || _c === void 0 ? void 0 : _c.end();
|
|
1271
|
+
});
|
|
1272
|
+
const onPipelineFinish = this.currentSitemapPipeline
|
|
1273
|
+
? new Promise((resolve, reject) => {
|
|
1274
|
+
var _a, _b;
|
|
1275
|
+
(_a = this.currentSitemapPipeline) === null || _a === void 0 ? void 0 : _a.on('finish', resolve);
|
|
1276
|
+
(_b = this.currentSitemapPipeline) === null || _b === void 0 ? void 0 : _b.on('error', reject);
|
|
1277
|
+
})
|
|
1278
|
+
: Promise.resolve();
|
|
1279
|
+
Promise.all([onFinish, onPipelineFinish])
|
|
1280
|
+
.then(() => {
|
|
1281
|
+
this.createSitemap(encoding);
|
|
1282
|
+
this.writeItem(item, callback);
|
|
1283
|
+
})
|
|
1284
|
+
.catch(callback);
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
else {
|
|
1288
|
+
this.createSitemap(encoding);
|
|
1289
|
+
}
|
|
1205
1290
|
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
(_a = this.currentSitemapPipeline) === null || _a === void 0 ? void 0 : _a.on('finish', onFinish);
|
|
1216
|
-
this.currentSitemap.end(!this.currentSitemapPipeline ? onFinish : undefined);
|
|
1291
|
+
this.writeItem(item, callback);
|
|
1292
|
+
}
|
|
1293
|
+
writeItem(item, callback) {
|
|
1294
|
+
if (!this.currentSitemap) {
|
|
1295
|
+
callback(new Error('No sitemap stream available'));
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
if (!this.currentSitemap.write(item)) {
|
|
1299
|
+
this.currentSitemap.once('drain', callback);
|
|
1217
1300
|
}
|
|
1218
1301
|
else {
|
|
1219
|
-
|
|
1220
|
-
callback();
|
|
1302
|
+
process.nextTick(callback);
|
|
1221
1303
|
}
|
|
1304
|
+
// Increment the count of items written
|
|
1305
|
+
this.itemsWritten++;
|
|
1222
1306
|
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Called when the stream is finished.
|
|
1309
|
+
* If there is a current sitemap, we wait for it to finish before calling the callback.
|
|
1310
|
+
*
|
|
1311
|
+
* @param cb
|
|
1312
|
+
*/
|
|
1223
1313
|
_flush(cb) {
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1314
|
+
const onFinish = new Promise((resolve, reject) => {
|
|
1315
|
+
if (this.currentSitemap) {
|
|
1316
|
+
this.currentSitemap.on('finish', resolve);
|
|
1317
|
+
this.currentSitemap.on('error', reject);
|
|
1318
|
+
this.currentSitemap.end();
|
|
1319
|
+
}
|
|
1320
|
+
else {
|
|
1321
|
+
resolve();
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
const onPipelineFinish = new Promise((resolve, reject) => {
|
|
1325
|
+
if (this.currentSitemapPipeline) {
|
|
1326
|
+
this.currentSitemapPipeline.on('finish', resolve);
|
|
1327
|
+
this.currentSitemapPipeline.on('error', reject);
|
|
1328
|
+
// The pipeline (pipe target) will get it's end() call
|
|
1329
|
+
// from the sitemap stream ending.
|
|
1330
|
+
}
|
|
1331
|
+
else {
|
|
1332
|
+
resolve();
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1335
|
+
Promise.all([onFinish, onPipelineFinish])
|
|
1336
|
+
.then(() => {
|
|
1337
|
+
super._flush(cb);
|
|
1338
|
+
})
|
|
1339
|
+
.catch((err) => {
|
|
1340
|
+
cb(err);
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
createSitemap(encoding) {
|
|
1344
|
+
const [idxItem, currentSitemap, currentSitemapPipeline] = this.getSitemapStream(this.itemsWritten / this.limit);
|
|
1345
|
+
currentSitemap.on('error', (err) => this.emit('error', err));
|
|
1346
|
+
this.currentSitemap = currentSitemap;
|
|
1347
|
+
this.currentSitemapPipeline = currentSitemapPipeline;
|
|
1348
|
+
super._transform(idxItem, encoding, () => {
|
|
1349
|
+
// We are not too fussed about waiting for the index item to be written
|
|
1350
|
+
// we we'll wait for the file to finish at the end
|
|
1351
|
+
// and index file write volume tends to be small in comprarison to sitemap
|
|
1352
|
+
// writes.
|
|
1353
|
+
// noop
|
|
1354
|
+
});
|
|
1228
1355
|
}
|
|
1229
1356
|
}
|
|
1230
1357
|
exports.SitemapAndIndexStream = SitemapAndIndexStream;
|
|
@@ -3283,12 +3410,17 @@ class XMLToSitemapItemStream extends stream_1$7.Transform {
|
|
|
3283
3410
|
}
|
|
3284
3411
|
_transform(data, encoding, callback) {
|
|
3285
3412
|
try {
|
|
3413
|
+
const cb = () => callback(this.level === types_1$1.ErrorLevel.THROW ? this.error : null);
|
|
3286
3414
|
// correcting the type here can be done without making it a breaking change
|
|
3287
3415
|
// TODO fix this
|
|
3288
3416
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3289
3417
|
// @ts-ignore
|
|
3290
|
-
this.saxStream.write(data, encoding)
|
|
3291
|
-
|
|
3418
|
+
if (!this.saxStream.write(data, encoding)) {
|
|
3419
|
+
this.saxStream.once('drain', cb);
|
|
3420
|
+
}
|
|
3421
|
+
else {
|
|
3422
|
+
process.nextTick(cb);
|
|
3423
|
+
}
|
|
3292
3424
|
}
|
|
3293
3425
|
catch (error) {
|
|
3294
3426
|
callback(error);
|
|
@@ -3557,152 +3689,138 @@ sitemapIndexParser.IndexObjectStreamToJSON = IndexObjectStreamToJSON;
|
|
|
3557
3689
|
|
|
3558
3690
|
var sitemapSimple = {};
|
|
3559
3691
|
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
}
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
Object.defineProperty(exports, "parseSitemap", { enumerable: true, get: function () { return sitemap_parser_1.parseSitemap; } });
|
|
3693
|
-
Object.defineProperty(exports, "XMLToSitemapItemStream", { enumerable: true, get: function () { return sitemap_parser_1.XMLToSitemapItemStream; } });
|
|
3694
|
-
Object.defineProperty(exports, "ObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_parser_1.ObjectStreamToJSON; } });
|
|
3695
|
-
var sitemap_index_parser_1 = sitemapIndexParser;
|
|
3696
|
-
Object.defineProperty(exports, "parseSitemapIndex", { enumerable: true, get: function () { return sitemap_index_parser_1.parseSitemapIndex; } });
|
|
3697
|
-
Object.defineProperty(exports, "XMLToSitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_parser_1.XMLToSitemapIndexStream; } });
|
|
3698
|
-
Object.defineProperty(exports, "IndexObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_index_parser_1.IndexObjectStreamToJSON; } });
|
|
3699
|
-
var sitemap_simple_1 = requireSitemapSimple();
|
|
3700
|
-
Object.defineProperty(exports, "simpleSitemapAndIndex", { enumerable: true, get: function () { return sitemap_simple_1.simpleSitemapAndIndex; } });
|
|
3701
|
-
} (dist));
|
|
3702
|
-
return dist;
|
|
3703
|
-
}
|
|
3704
|
-
|
|
3705
|
-
var distExports = requireDist();
|
|
3692
|
+
(function (exports) {
|
|
3693
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3694
|
+
exports.simpleSitemapAndIndex = void 0;
|
|
3695
|
+
const sitemap_index_stream_1 = sitemapIndexStream;
|
|
3696
|
+
const sitemap_stream_1 = sitemapStream;
|
|
3697
|
+
const utils_1 = utils$l;
|
|
3698
|
+
const zlib_1 = require$$3$1;
|
|
3699
|
+
const fs_1 = require$$0$1;
|
|
3700
|
+
const path_1 = require$$0$2;
|
|
3701
|
+
const stream_1 = require$$0;
|
|
3702
|
+
const util_1 = require$$0$3;
|
|
3703
|
+
const url_1 = require$$3;
|
|
3704
|
+
const pipeline = (0, util_1.promisify)(stream_1.pipeline);
|
|
3705
|
+
/**
|
|
3706
|
+
*
|
|
3707
|
+
* @param {object} options -
|
|
3708
|
+
* @param {string} options.hostname - The hostname for all URLs
|
|
3709
|
+
* @param {string} [options.sitemapHostname] - The hostname for the sitemaps if different than hostname
|
|
3710
|
+
* @param {SitemapItemLoose[] | string | Readable | string[]} options.sourceData - The urls you want to make a sitemap out of.
|
|
3711
|
+
* @param {string} options.destinationDir - where to write the sitemaps and index
|
|
3712
|
+
* @param {string} [options.publicBasePath] - where the sitemaps are relative to the hostname. Defaults to root.
|
|
3713
|
+
* @param {number} [options.limit] - how many URLs to write before switching to a new file. Defaults to 50k
|
|
3714
|
+
* @param {boolean} [options.gzip] - whether to compress the written files. Defaults to true
|
|
3715
|
+
* @returns {Promise<void>} an empty promise that resolves when everything is done
|
|
3716
|
+
*/
|
|
3717
|
+
const simpleSitemapAndIndex = async ({ hostname, sitemapHostname = hostname, // if different
|
|
3718
|
+
/**
|
|
3719
|
+
* Pass a line separated list of sitemap items or a stream or an array
|
|
3720
|
+
*/
|
|
3721
|
+
sourceData, destinationDir, limit = 50000, gzip = true, publicBasePath = './', }) => {
|
|
3722
|
+
await fs_1.promises.mkdir(destinationDir, { recursive: true });
|
|
3723
|
+
const sitemapAndIndexStream = new sitemap_index_stream_1.SitemapAndIndexStream({
|
|
3724
|
+
limit,
|
|
3725
|
+
getSitemapStream: (i) => {
|
|
3726
|
+
const sitemapStream = new sitemap_stream_1.SitemapStream({
|
|
3727
|
+
hostname,
|
|
3728
|
+
});
|
|
3729
|
+
const path = `./sitemap-${i}.xml`;
|
|
3730
|
+
const writePath = (0, path_1.resolve)(destinationDir, path + (gzip ? '.gz' : ''));
|
|
3731
|
+
if (!publicBasePath.endsWith('/')) {
|
|
3732
|
+
publicBasePath += '/';
|
|
3733
|
+
}
|
|
3734
|
+
const publicPath = (0, path_1.normalize)(publicBasePath + path);
|
|
3735
|
+
let pipeline;
|
|
3736
|
+
if (gzip) {
|
|
3737
|
+
pipeline = sitemapStream
|
|
3738
|
+
.pipe((0, zlib_1.createGzip)()) // compress the output of the sitemap
|
|
3739
|
+
.pipe((0, fs_1.createWriteStream)(writePath)); // write it to sitemap-NUMBER.xml
|
|
3740
|
+
}
|
|
3741
|
+
else {
|
|
3742
|
+
pipeline = sitemapStream.pipe((0, fs_1.createWriteStream)(writePath)); // write it to sitemap-NUMBER.xml
|
|
3743
|
+
}
|
|
3744
|
+
return [
|
|
3745
|
+
new url_1.URL(`${publicPath}${gzip ? '.gz' : ''}`, sitemapHostname).toString(),
|
|
3746
|
+
sitemapStream,
|
|
3747
|
+
pipeline,
|
|
3748
|
+
];
|
|
3749
|
+
},
|
|
3750
|
+
});
|
|
3751
|
+
let src;
|
|
3752
|
+
if (typeof sourceData === 'string') {
|
|
3753
|
+
src = (0, utils_1.lineSeparatedURLsToSitemapOptions)((0, fs_1.createReadStream)(sourceData));
|
|
3754
|
+
}
|
|
3755
|
+
else if (sourceData instanceof stream_1.Readable) {
|
|
3756
|
+
src = sourceData;
|
|
3757
|
+
}
|
|
3758
|
+
else if (Array.isArray(sourceData)) {
|
|
3759
|
+
src = stream_1.Readable.from(sourceData);
|
|
3760
|
+
}
|
|
3761
|
+
else {
|
|
3762
|
+
throw new Error("unhandled source type. You've passed in data that is not supported");
|
|
3763
|
+
}
|
|
3764
|
+
const writePath = (0, path_1.resolve)(destinationDir, `./sitemap-index.xml${gzip ? '.gz' : ''}`);
|
|
3765
|
+
if (gzip) {
|
|
3766
|
+
return pipeline(src, sitemapAndIndexStream, (0, zlib_1.createGzip)(), (0, fs_1.createWriteStream)(writePath));
|
|
3767
|
+
}
|
|
3768
|
+
else {
|
|
3769
|
+
return pipeline(src, sitemapAndIndexStream, (0, fs_1.createWriteStream)(writePath));
|
|
3770
|
+
}
|
|
3771
|
+
};
|
|
3772
|
+
exports.simpleSitemapAndIndex = simpleSitemapAndIndex;
|
|
3773
|
+
exports.default = exports.simpleSitemapAndIndex;
|
|
3774
|
+
} (sitemapSimple));
|
|
3775
|
+
|
|
3776
|
+
(function (exports) {
|
|
3777
|
+
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3778
|
+
if (k2 === undefined) k2 = k;
|
|
3779
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
3780
|
+
}) : (function(o, m, k, k2) {
|
|
3781
|
+
if (k2 === undefined) k2 = k;
|
|
3782
|
+
o[k2] = m[k];
|
|
3783
|
+
}));
|
|
3784
|
+
var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
|
|
3785
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
3786
|
+
};
|
|
3787
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3788
|
+
exports.simpleSitemapAndIndex = exports.IndexObjectStreamToJSON = exports.XMLToSitemapIndexStream = exports.parseSitemapIndex = exports.ObjectStreamToJSON = exports.XMLToSitemapItemStream = exports.parseSitemap = exports.xmlLint = exports.ReadlineStream = exports.normalizeURL = exports.validateSMIOptions = exports.mergeStreams = exports.lineSeparatedURLsToSitemapOptions = exports.SitemapStream = exports.streamToPromise = exports.SitemapAndIndexStream = exports.SitemapIndexStream = exports.IndexTagNames = exports.SitemapItemStream = void 0;
|
|
3789
|
+
/*!
|
|
3790
|
+
* Sitemap
|
|
3791
|
+
* Copyright(c) 2011 Eugene Kalinin
|
|
3792
|
+
* MIT Licensed
|
|
3793
|
+
*/
|
|
3794
|
+
var sitemap_item_stream_1 = sitemapItemStream;
|
|
3795
|
+
Object.defineProperty(exports, "SitemapItemStream", { enumerable: true, get: function () { return sitemap_item_stream_1.SitemapItemStream; } });
|
|
3796
|
+
var sitemap_index_stream_1 = sitemapIndexStream;
|
|
3797
|
+
Object.defineProperty(exports, "IndexTagNames", { enumerable: true, get: function () { return sitemap_index_stream_1.IndexTagNames; } });
|
|
3798
|
+
Object.defineProperty(exports, "SitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapIndexStream; } });
|
|
3799
|
+
Object.defineProperty(exports, "SitemapAndIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapAndIndexStream; } });
|
|
3800
|
+
var sitemap_stream_1 = sitemapStream;
|
|
3801
|
+
Object.defineProperty(exports, "streamToPromise", { enumerable: true, get: function () { return sitemap_stream_1.streamToPromise; } });
|
|
3802
|
+
Object.defineProperty(exports, "SitemapStream", { enumerable: true, get: function () { return sitemap_stream_1.SitemapStream; } });
|
|
3803
|
+
__exportStar(errors, exports);
|
|
3804
|
+
__exportStar(types, exports);
|
|
3805
|
+
var utils_1 = utils$l;
|
|
3806
|
+
Object.defineProperty(exports, "lineSeparatedURLsToSitemapOptions", { enumerable: true, get: function () { return utils_1.lineSeparatedURLsToSitemapOptions; } });
|
|
3807
|
+
Object.defineProperty(exports, "mergeStreams", { enumerable: true, get: function () { return utils_1.mergeStreams; } });
|
|
3808
|
+
Object.defineProperty(exports, "validateSMIOptions", { enumerable: true, get: function () { return utils_1.validateSMIOptions; } });
|
|
3809
|
+
Object.defineProperty(exports, "normalizeURL", { enumerable: true, get: function () { return utils_1.normalizeURL; } });
|
|
3810
|
+
Object.defineProperty(exports, "ReadlineStream", { enumerable: true, get: function () { return utils_1.ReadlineStream; } });
|
|
3811
|
+
var xmllint_1 = xmllint;
|
|
3812
|
+
Object.defineProperty(exports, "xmlLint", { enumerable: true, get: function () { return xmllint_1.xmlLint; } });
|
|
3813
|
+
var sitemap_parser_1 = sitemapParser;
|
|
3814
|
+
Object.defineProperty(exports, "parseSitemap", { enumerable: true, get: function () { return sitemap_parser_1.parseSitemap; } });
|
|
3815
|
+
Object.defineProperty(exports, "XMLToSitemapItemStream", { enumerable: true, get: function () { return sitemap_parser_1.XMLToSitemapItemStream; } });
|
|
3816
|
+
Object.defineProperty(exports, "ObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_parser_1.ObjectStreamToJSON; } });
|
|
3817
|
+
var sitemap_index_parser_1 = sitemapIndexParser;
|
|
3818
|
+
Object.defineProperty(exports, "parseSitemapIndex", { enumerable: true, get: function () { return sitemap_index_parser_1.parseSitemapIndex; } });
|
|
3819
|
+
Object.defineProperty(exports, "XMLToSitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_parser_1.XMLToSitemapIndexStream; } });
|
|
3820
|
+
Object.defineProperty(exports, "IndexObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_index_parser_1.IndexObjectStreamToJSON; } });
|
|
3821
|
+
var sitemap_simple_1 = sitemapSimple;
|
|
3822
|
+
Object.defineProperty(exports, "simpleSitemapAndIndex", { enumerable: true, get: function () { return sitemap_simple_1.simpleSitemapAndIndex; } });
|
|
3823
|
+
} (dist));
|
|
3706
3824
|
|
|
3707
3825
|
var cjs$1 = {exports: {}};
|
|
3708
3826
|
|
|
@@ -10986,8 +11104,15 @@ function getFormattedSitemap(options, routes) {
|
|
|
10986
11104
|
priority: getOptionByRoute(options.priority, route) ?? defaultOptions.priority,
|
|
10987
11105
|
lastmod: getOptionByRoute(options.lastmod, route) ?? defaultOptions.lastmod
|
|
10988
11106
|
};
|
|
10989
|
-
if (options.i18n)
|
|
10990
|
-
|
|
11107
|
+
if (options.i18n) {
|
|
11108
|
+
const languages = options.i18n.languages.map((str) => ({
|
|
11109
|
+
lang: str,
|
|
11110
|
+
url: str === options.i18n?.defaultLanguage ? url : `${url}/${str}`
|
|
11111
|
+
}));
|
|
11112
|
+
return Object.assign(formattedSitemap, {
|
|
11113
|
+
links: options.i18n.defaultLanguage ? [...languages, { lang: "x-default", url }] : languages
|
|
11114
|
+
});
|
|
11115
|
+
}
|
|
10991
11116
|
return formattedSitemap;
|
|
10992
11117
|
});
|
|
10993
11118
|
}
|
|
@@ -11003,9 +11128,9 @@ function generateSitemap(options = {}) {
|
|
|
11003
11128
|
if (!routes.length)
|
|
11004
11129
|
return;
|
|
11005
11130
|
const formattedSitemap = getFormattedSitemap(resolvedOptions, routes);
|
|
11006
|
-
const stream = new
|
|
11131
|
+
const stream = new dist.SitemapStream();
|
|
11007
11132
|
formattedSitemap.forEach((item) => stream.write(item));
|
|
11008
|
-
|
|
11133
|
+
dist.streamToPromise(stream).then((sitemap) => {
|
|
11009
11134
|
const utfSitemap = sitemap.toString("utf-8");
|
|
11010
11135
|
const formattedSitemap2 = resolvedOptions.readable ? format(utfSitemap) : utfSitemap;
|
|
11011
11136
|
writeFileSync(getResolvedPath("sitemap.xml", resolvedOptions), formattedSitemap2);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-sitemap",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.1",
|
|
5
5
|
"packageManager": "pnpm@9.1.2",
|
|
6
6
|
"description": "Sitemap generator plugin for Vite",
|
|
7
7
|
"main": "dist/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"eslint-plugin-format": "^0.1.1",
|
|
28
28
|
"pkgroll": "^2.1.1",
|
|
29
29
|
"pnpm": "^9.1.2",
|
|
30
|
-
"sitemap-ts": "^1.7.
|
|
30
|
+
"sitemap-ts": "^1.7.1",
|
|
31
31
|
"taze": "^0.13.8",
|
|
32
32
|
"typescript": "^5.4.5",
|
|
33
33
|
"vite": "^5.2.11",
|