UNPKG

2.2 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.Url = undefined;
7
8var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
9
10var _xml_escape = require("./xml_escape");
11
12function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
14var NOW = new Date();
15
16var Url = exports.Url = function () {
17 function Url(attributes) {
18 _classCallCheck(this, Url);
19
20 Object.assign(this, attributes);
21 if (this.lastModified && !(this.lastModified instanceof Date)) {
22 this.lastModified = new Date(this.lastModified);
23 } else if (!this.lastModified) {
24 this.lastModified = NOW;
25 }
26 }
27
28 _createClass(Url, [{
29 key: "toXml",
30 value: function toXml() {
31 var xml = "<url><loc>" + (0, _xml_escape.escapeXmlValue)(this.url) + "</loc>";
32 if (this.lastModified) {
33 xml += "<lastmod>" + this.lastModified.toISOString() + "</lastmod>";
34 }
35 if (this.changeFrequency) {
36 xml += "<changefreq>" + this.changeFrequency + "</changefreq>";
37 }
38 if (this.priority) {
39 xml += "<priority>" + this.priority + "</priority>";
40 }
41 if (this.imageUrl) {
42 xml += "<image:image><image:loc>" + (0, _xml_escape.escapeXmlValue)(this.imageUrl) + "</image:loc></image:image>";
43 }
44 if (this.linkTags) {
45 this.linkTags.forEach(function (linkTag) {
46 xml += "<xhtml:link rel=\"" + (0, _xml_escape.escapeXmlValue)(linkTag.rel) + "\" href=\"" + (0, _xml_escape.escapeXmlValue)(linkTag.href) + "\"/>";
47 });
48 }
49 xml += "</url>";
50 return xml;
51 }
52 }]);
53
54 return Url;
55}();
\No newline at end of file