multi-sitemap
Advanced tools
Comparing version 0.2.0-3 to 0.2.0
import { ISitemapReader } from '../../types'; | ||
export default class SitemapProductsReader implements ISitemapReader { | ||
i: number; | ||
private entriesPerChunk; | ||
constructor({entriesPerChunk}: { | ||
entriesPerChunk: number; | ||
}); | ||
hasNext(): boolean; | ||
getNext(): Promise<string[]>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SitemapProductsReader = /** @class */ (function () { | ||
function SitemapProductsReader() { | ||
function SitemapProductsReader(_a) { | ||
var _b = _a.entriesPerChunk, entriesPerChunk = _b === void 0 ? 1 : _b; | ||
this.i = 0; | ||
this.entriesPerChunk = entriesPerChunk; | ||
} | ||
@@ -11,3 +13,8 @@ SitemapProductsReader.prototype.hasNext = function () { | ||
SitemapProductsReader.prototype.getNext = function () { | ||
return Promise.resolve(["/products/" + this.i++]); | ||
var entries = []; | ||
var limit = this.i + this.entriesPerChunk; | ||
for (; this.i < limit; this.i++) { | ||
entries.push("/products/" + this.i); | ||
} | ||
return Promise.resolve(entries); | ||
}; | ||
@@ -14,0 +21,0 @@ return SitemapProductsReader; |
@@ -59,3 +59,3 @@ "use strict"; | ||
name: 'products', | ||
reader: new SitemapReaderMock_1.default() | ||
reader: new SitemapReaderMock_1.default({ entriesPerChunk: 1 }) | ||
}); | ||
@@ -62,0 +62,0 @@ expect(addDynamicResult).toBeInstanceOf(Promise); |
@@ -61,6 +61,8 @@ "use strict"; | ||
entries = _a.sent(); | ||
if (entries.length > this.maxEntriesPerFile) { | ||
throw new Error("The reader shouldn't return more entries than a single sitemap should contain."); | ||
} | ||
if (!(curStreamedEntries + entries.length > this.maxEntriesPerFile)) return [3 /*break*/, 3]; | ||
if (!stream) { | ||
if (!stream) | ||
throw new Error('No opened stream.'); | ||
} | ||
return [4 /*yield*/, stream.end()]; | ||
@@ -67,0 +69,0 @@ case 2: |
{ | ||
"name": "multi-sitemap", | ||
"version": "0.2.0-3", | ||
"version": "0.2.0", | ||
"description": "Painless creation of large dynamic sitemaps that consist of multiple files.", | ||
@@ -5,0 +5,0 @@ "author": "Jan Amann <jan@amann.me>", |
@@ -37,3 +37,3 @@ # multi-sitemap | ||
All methods of `SitemapProcessor` return promises that should be waited for before calling other methods. | ||
All methods of `SitemapProcessor` return promises that should be waited for before calling other methods. The `addIndex` method should be called last, as this is the time the processor knows about all child sitemaps. | ||
@@ -52,3 +52,3 @@ ## Adding dynamic data | ||
type SitemapEntryConfig = /* url*/ string | ISitemapEntry; | ||
type SitemapEntryConfig = /* url */ string | ISitemapEntry; | ||
@@ -55,0 +55,0 @@ interface ISitemapEntry { |
48540
917