shaman-website-compiler
Version:
Compile raw HTML, CSS and Javascript into the smallest possible, SEO friendly website.
54 lines • 3.42 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebsiteRouter = void 0;
var sitemap_1 = require("sitemap");
var inversify_1 = require("inversify");
var app_composition_1 = require("./composition/app.composition");
var models_1 = require("./models");
var WebsiteRouter = /** @class */ (function () {
function WebsiteRouter() {
var _this = this;
this.getAllRoutes = function () {
var files = _this.context.models.files.filter(function (file) { var _a; return file.route && !((_a = file.model.shaman) === null || _a === void 0 ? void 0 : _a.private); });
var bundles = _this.context.models.bundles.filter(function (b) { return !!b.content; });
var routes = files.map(function (f) { var _a; return new models_1.Route(f.routePath, f.content, f.extension, (_a = f.model.shaman) === null || _a === void 0 ? void 0 : _a.extensionless); });
routes = routes.concat(bundles.map(function (b) { return new models_1.Route(b.path, b.content, b.type); }));
routes = routes.concat(_this.getDynamicRoutes());
return _this.createSitemap(routes);
};
this.getDynamicRoutes = function () {
var routes = _this.context.models.dynamicRoutes.filter(function (r) { return !!r.content; });
return routes.map(function (r) { return new models_1.Route(r.path, r.content, "html"); });
};
this.createSitemap = function (routes) {
var paths = routes.filter(function (r) { return r.extension == 'html'; }).map(function (r) { return r.path; });
paths = [''].concat(paths.filter(function (p) { return p != 'index.html'; }));
var links = paths.map(function (p) { return ({ url: p, changefreq: 'weekly', priority: 0.8 }); });
var stream = new sitemap_1.SitemapStream(_this.config.sitemap);
links.forEach(function (link) { return stream.write(link); });
stream.end();
return (0, sitemap_1.streamToPromise)(stream).then(function (data) {
var route = new models_1.Route('sitemap.xml', data.toString(), 'xml');
return [route].concat(routes);
});
};
this.context = app_composition_1.IoC.get(app_composition_1.TYPES.CompilerDataContext);
this.config = app_composition_1.IoC.get(app_composition_1.TYPES.WebsiteConfig);
}
WebsiteRouter = __decorate([
(0, inversify_1.injectable)(),
__metadata("design:paramtypes", [])
], WebsiteRouter);
return WebsiteRouter;
}());
exports.WebsiteRouter = WebsiteRouter;
//# sourceMappingURL=website-router.js.map