UNPKG

@prezly/theme-kit-core

Version:

Data layer and utility library for developing Prezly themes with JavaScript

22 lines (21 loc) 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.stringify = stringify; function stringify(sitemap) { return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.w3.org/TR/xhtml11/xhtml11_schema.html http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd\" \n xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" \n xmlns:xhtml=\"http://www.w3.org/TR/xhtml11/xhtml11_schema.html\">\n ".concat(sitemap.map(stringifyEntry).join('\n'), "\n </urlset>\n "); } function stringifyEntry(entry) { var _entry$alternate; return "<url>\n <loc>".concat(entry.url, "</loc>\n ").concat(entry.lastModified ? "<lastmod>".concat(stringifyDate(entry.lastModified), "</lastmod>") : '', "\n ").concat(entry.changeFrequency ? "<changefreq>".concat(entry.changeFrequency, "</changefreq>") : '', "\n ").concat(entry.priority ? "<priority>".concat(entry.priority, "</priority>") : '', "\n ").concat(((_entry$alternate = entry.alternate) !== null && _entry$alternate !== void 0 ? _entry$alternate : []).map(stringifyAlternateLink).join(''), "\n </url>"); } function stringifyAlternateLink(alt) { return "<xhtml:link rel=\"alternate\" hreflang=\"".concat(alt.lang, "\" href=\"").concat(alt.url, "\" />"); } function stringifyDate(date) { if (date instanceof Date) { return date.toISOString(); } return date; }