@ekino/rendr-sitemap
Advanced tools
Comparing version 0.0.21-alpha.1 to 1.0.0-alpha.0
/// <reference types="node" /> | ||
/// <reference types="express" /> | ||
declare module "types" { | ||
@@ -9,11 +8,6 @@ export type Options = { | ||
declare module "sitemap" { | ||
import { PageReference, StreamCreator, PageReferenceGenerator } from "@ekino/rendr-core"; | ||
import { PageBuilder } from "@ekino/rendr-loader"; | ||
import { PageReference, StreamCreator, PageReferenceGenerator, ResponsePage } from "@ekino/rendr-core"; | ||
import { Writable } from "stream"; | ||
import Express from "express"; | ||
import { Options } from "types"; | ||
import { ServerResponse } from "http"; | ||
export function sendSitemap(res: ServerResponse, generator: PageReferenceGenerator): Promise<void>; | ||
export function createSitemapPageBuilder(generator: PageReferenceGenerator): PageBuilder; | ||
export function createSitemapRequestHandler(generator: PageReferenceGenerator): Express.RequestHandler; | ||
export function createSitemapResponse(generator: PageReferenceGenerator): Promise<ResponsePage>; | ||
export function createSitemapWritable(createStream: StreamCreator, options: Options): Writable; | ||
@@ -20,0 +14,0 @@ export function toSitemapEntry(ref: PageReference): string; |
@@ -54,13 +54,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toSitemapIndexEntry = exports.toSitemapEntry = exports.createSitemapWritable = exports.createSitemapRequestHandler = exports.createSitemapPageBuilder = exports.sendSitemap = void 0; | ||
function sendSitemap(res, generator) { | ||
exports.toSitemapIndexEntry = exports.toSitemapEntry = exports.createSitemapWritable = exports.createSitemapResponse = void 0; | ||
function createSitemapResponse(generator) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var iter, sitemapWritable; | ||
var headers, iter, body, writable, sitemapWritable; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
res.setHeader("Content-Type", "application/xml"); | ||
res.setHeader("X-Rendr-Content-Type", "render/sitemap"); | ||
headers = { | ||
"Content-Type": "application/xml", | ||
"X-Rendr-Content-Type": "render/sitemap", | ||
}; | ||
iter = rendr_core_1.transformGenerator(generator(), toSitemapEntry); | ||
sitemapWritable = createSitemapWritable(function (name) { return res; }, { | ||
body = ""; | ||
writable = new stream_1.Writable({ | ||
write: function (chunk, encoding, cb) { | ||
body += chunk; | ||
if (cb) { | ||
cb(); | ||
} | ||
}, | ||
}); | ||
sitemapWritable = createSitemapWritable(function (name) { return writable; }, { | ||
basePathIndex: "", | ||
@@ -71,3 +82,3 @@ }); | ||
_a.sent(); | ||
return [2]; | ||
return [2, rendr_core_1.createResponsePage(200, headers, body)]; | ||
} | ||
@@ -77,31 +88,3 @@ }); | ||
} | ||
exports.sendSitemap = sendSitemap; | ||
function createSitemapPageBuilder(generator) { | ||
var _this = this; | ||
return function (ctx, page) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, sendSitemap(ctx.res, generator)]; | ||
case 1: | ||
_a.sent(); | ||
return [2]; | ||
} | ||
}); | ||
}); }; | ||
} | ||
exports.createSitemapPageBuilder = createSitemapPageBuilder; | ||
function createSitemapRequestHandler(generator) { | ||
var _this = this; | ||
return function (req, res, next) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, sendSitemap(res, generator)]; | ||
case 1: | ||
_a.sent(); | ||
return [2]; | ||
} | ||
}); | ||
}); }; | ||
} | ||
exports.createSitemapRequestHandler = createSitemapRequestHandler; | ||
exports.createSitemapResponse = createSitemapResponse; | ||
function createSitemapWritable(createStream, options) { | ||
@@ -108,0 +91,0 @@ var MAX_ENTRY_SITEMAP = 50000; |
/// <reference types="node" /> | ||
import { PageReference, StreamCreator, PageReferenceGenerator } from "@ekino/rendr-core"; | ||
import { PageBuilder } from "@ekino/rendr-loader"; | ||
import { PageReference, StreamCreator, PageReferenceGenerator, ResponsePage } from "@ekino/rendr-core"; | ||
import { Writable } from "stream"; | ||
import Express from "express"; | ||
import { Options } from "./types"; | ||
import { ServerResponse } from "http"; | ||
export declare function sendSitemap(res: ServerResponse, generator: PageReferenceGenerator): Promise<void>; | ||
export declare function createSitemapPageBuilder(generator: PageReferenceGenerator): PageBuilder; | ||
export declare function createSitemapRequestHandler(generator: PageReferenceGenerator): Express.RequestHandler; | ||
export declare function createSitemapResponse(generator: PageReferenceGenerator): Promise<ResponsePage>; | ||
export declare function createSitemapWritable(createStream: StreamCreator, options: Options): Writable; | ||
export declare function toSitemapEntry(ref: PageReference): string; | ||
export declare function toSitemapIndexEntry(options: Options, name: string): string; |
@@ -37,14 +37,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { transformGenerator, pipeIteratorToWritable, } from "@ekino/rendr-core"; | ||
import { transformGenerator, createResponsePage, pipeIteratorToWritable, } from "@ekino/rendr-core"; | ||
import { Writable } from "stream"; | ||
export function sendSitemap(res, generator) { | ||
export function createSitemapResponse(generator) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var iter, sitemapWritable; | ||
var headers, iter, body, writable, sitemapWritable; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
res.setHeader("Content-Type", "application/xml"); | ||
res.setHeader("X-Rendr-Content-Type", "render/sitemap"); | ||
headers = { | ||
"Content-Type": "application/xml", | ||
"X-Rendr-Content-Type": "render/sitemap", | ||
}; | ||
iter = transformGenerator(generator(), toSitemapEntry); | ||
sitemapWritable = createSitemapWritable(function (name) { return res; }, { | ||
body = ""; | ||
writable = new Writable({ | ||
write: function (chunk, encoding, cb) { | ||
body += chunk; | ||
if (cb) { | ||
cb(); | ||
} | ||
}, | ||
}); | ||
sitemapWritable = createSitemapWritable(function (name) { return writable; }, { | ||
basePathIndex: "", | ||
@@ -55,3 +66,3 @@ }); | ||
_a.sent(); | ||
return [2]; | ||
return [2, createResponsePage(200, headers, body)]; | ||
} | ||
@@ -61,28 +72,2 @@ }); | ||
} | ||
export function createSitemapPageBuilder(generator) { | ||
var _this = this; | ||
return function (ctx, page) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, sendSitemap(ctx.res, generator)]; | ||
case 1: | ||
_a.sent(); | ||
return [2]; | ||
} | ||
}); | ||
}); }; | ||
} | ||
export function createSitemapRequestHandler(generator) { | ||
var _this = this; | ||
return function (req, res, next) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, sendSitemap(res, generator)]; | ||
case 1: | ||
_a.sent(); | ||
return [2]; | ||
} | ||
}); | ||
}); }; | ||
} | ||
export function createSitemapWritable(createStream, options) { | ||
@@ -89,0 +74,0 @@ var MAX_ENTRY_SITEMAP = 50000; |
/// <reference types="node" /> | ||
import { PageReference, StreamCreator, PageReferenceGenerator } from "@ekino/rendr-core"; | ||
import { PageBuilder } from "@ekino/rendr-loader"; | ||
import { PageReference, StreamCreator, PageReferenceGenerator, ResponsePage } from "@ekino/rendr-core"; | ||
import { Writable } from "stream"; | ||
import Express from "express"; | ||
import { Options } from "./types"; | ||
import { ServerResponse } from "http"; | ||
export declare function sendSitemap(res: ServerResponse, generator: PageReferenceGenerator): Promise<void>; | ||
export declare function createSitemapPageBuilder(generator: PageReferenceGenerator): PageBuilder; | ||
export declare function createSitemapRequestHandler(generator: PageReferenceGenerator): Express.RequestHandler; | ||
export declare function createSitemapResponse(generator: PageReferenceGenerator): Promise<ResponsePage>; | ||
export declare function createSitemapWritable(createStream: StreamCreator, options: Options): Writable; | ||
export declare function toSitemapEntry(ref: PageReference): string; | ||
export declare function toSitemapIndexEntry(options: Options, name: string): string; |
@@ -39,15 +39,26 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toSitemapIndexEntry = exports.toSitemapEntry = exports.createSitemapWritable = exports.createSitemapRequestHandler = exports.createSitemapPageBuilder = exports.sendSitemap = void 0; | ||
exports.toSitemapIndexEntry = exports.toSitemapEntry = exports.createSitemapWritable = exports.createSitemapResponse = void 0; | ||
var rendr_core_1 = require("@ekino/rendr-core"); | ||
var stream_1 = require("stream"); | ||
function sendSitemap(res, generator) { | ||
function createSitemapResponse(generator) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var iter, sitemapWritable; | ||
var headers, iter, body, writable, sitemapWritable; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
res.setHeader("Content-Type", "application/xml"); | ||
res.setHeader("X-Rendr-Content-Type", "render/sitemap"); | ||
headers = { | ||
"Content-Type": "application/xml", | ||
"X-Rendr-Content-Type": "render/sitemap", | ||
}; | ||
iter = rendr_core_1.transformGenerator(generator(), toSitemapEntry); | ||
sitemapWritable = createSitemapWritable(function (name) { return res; }, { | ||
body = ""; | ||
writable = new stream_1.Writable({ | ||
write: function (chunk, encoding, cb) { | ||
body += chunk; | ||
if (cb) { | ||
cb(); | ||
} | ||
}, | ||
}); | ||
sitemapWritable = createSitemapWritable(function (name) { return writable; }, { | ||
basePathIndex: "", | ||
@@ -58,3 +69,3 @@ }); | ||
_a.sent(); | ||
return [2]; | ||
return [2, rendr_core_1.createResponsePage(200, headers, body)]; | ||
} | ||
@@ -64,31 +75,3 @@ }); | ||
} | ||
exports.sendSitemap = sendSitemap; | ||
function createSitemapPageBuilder(generator) { | ||
var _this = this; | ||
return function (ctx, page) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, sendSitemap(ctx.res, generator)]; | ||
case 1: | ||
_a.sent(); | ||
return [2]; | ||
} | ||
}); | ||
}); }; | ||
} | ||
exports.createSitemapPageBuilder = createSitemapPageBuilder; | ||
function createSitemapRequestHandler(generator) { | ||
var _this = this; | ||
return function (req, res, next) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, sendSitemap(res, generator)]; | ||
case 1: | ||
_a.sent(); | ||
return [2]; | ||
} | ||
}); | ||
}); }; | ||
} | ||
exports.createSitemapRequestHandler = createSitemapRequestHandler; | ||
exports.createSitemapResponse = createSitemapResponse; | ||
function createSitemapWritable(createStream, options) { | ||
@@ -95,0 +78,0 @@ var MAX_ENTRY_SITEMAP = 50000; |
{ | ||
"name": "@ekino/rendr-sitemap", | ||
"license": "MIT", | ||
"version": "0.0.21-alpha.1", | ||
"version": "1.0.0-alpha.0", | ||
"main": "dist/lib/index.js", | ||
@@ -19,7 +19,7 @@ "typing": "dist/lib/index.d.ts", | ||
"dependencies": { | ||
"@ekino/rendr-core": "0.0.21-alpha.1", | ||
"@ekino/rendr-loader": "0.0.21-alpha.1", | ||
"@ekino/rendr-core": "1.0.0-alpha.0", | ||
"@ekino/rendr-loader": "1.0.0-alpha.0", | ||
"express": "^4.16.4" | ||
}, | ||
"gitHead": "99576698a64b2fd9a95a902461813552106588c4" | ||
"gitHead": "69fbb418c854bdafb58808fa25a6edc19552f4f5" | ||
} |
@@ -6,54 +6,46 @@ import { | ||
transformGenerator, | ||
createResponsePage, | ||
pipeIteratorToWritable, | ||
ResponsePage, | ||
} from "@ekino/rendr-core"; | ||
import { PageBuilder } from "@ekino/rendr-loader"; | ||
import { Writable } from "stream"; | ||
import Express from "express"; | ||
import { Options } from "./types"; | ||
import { ServerResponse } from "http"; | ||
export async function sendSitemap( | ||
res: ServerResponse, | ||
export async function createSitemapResponse( | ||
generator: PageReferenceGenerator | ||
) { | ||
res.setHeader("Content-Type", "application/xml"); | ||
res.setHeader("X-Rendr-Content-Type", "render/sitemap"); | ||
): Promise<ResponsePage> { | ||
const headers = { | ||
"Content-Type": "application/xml", | ||
"X-Rendr-Content-Type": "render/sitemap", | ||
}; | ||
const iter = transformGenerator(generator(), toSitemapEntry); | ||
const sitemapWritable = createSitemapWritable((name: string) => res, { | ||
basePathIndex: "", | ||
/** | ||
* @todo Need to find a clever way to pass any bit written to a reader object | ||
* so there is no potential high memory usage. | ||
*/ | ||
let body = ""; | ||
const writable = new Writable({ | ||
write: (chunk, encoding, cb) => { | ||
body += chunk; | ||
if (cb) { | ||
cb(); | ||
} | ||
}, | ||
}); | ||
const sitemapWritable = createSitemapWritable((name: string) => writable, { | ||
basePathIndex: "", // no index | ||
}); | ||
await pipeIteratorToWritable(iter, sitemapWritable); | ||
} | ||
export function createSitemapPageBuilder( | ||
generator: PageReferenceGenerator | ||
): PageBuilder { | ||
return async (ctx, page) => { | ||
// we don't care about the page, we just return binary to the output content | ||
await sendSitemap(ctx.res, generator); | ||
}; | ||
return createResponsePage(200, headers, body); | ||
} | ||
/** | ||
* This function can be used to expose on sitemap with less than 50K items. | ||
* | ||
* If you have a bigger website, creating a sitemap index is suitable, but this cannot | ||
* be done on the fly. | ||
* | ||
* @param generator | ||
*/ | ||
export function createSitemapRequestHandler( | ||
generator: PageReferenceGenerator | ||
): Express.RequestHandler { | ||
return async (req, res, next) => { | ||
await sendSitemap(res, generator); | ||
}; | ||
} | ||
/** | ||
* This function is used as a proxy to open or close file as the | ||
@@ -60,0 +52,0 @@ * sitemap has hard contraints on the size or the number of element |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47970
757
+ Added@ekino/rendr-core@1.0.0-alpha.0(transitive)
+ Added@ekino/rendr-loader@1.0.0-alpha.0(transitive)
+ Addedaxios@0.21.4(transitive)
- Removed@ekino/rendr-core@0.0.21-alpha.1(transitive)
- Removed@ekino/rendr-loader@0.0.21-alpha.1(transitive)
- Removedaxios@0.20.0(transitive)