UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

113 lines (111 loc) 4.55 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: !0 }); }, __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target, mod)), __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var generateSitemap_exports = {}; __export(generateSitemap_exports, { generateSitemap: () => generateSitemap }); module.exports = __toCommonJS(generateSitemap_exports); var import_micromatch = __toESM(require("micromatch"), 1); function _instanceof(left, right) { return right != null && typeof Symbol < "u" && right[Symbol.hasInstance] ? !!right[Symbol.hasInstance](left) : left instanceof right; } function generateSitemap(routes, options) { var _options_baseUrl, _options_priority, envUrl = process.env.ONE_SERVER_URL, baseUrl = (_options_baseUrl = options.baseUrl) !== null && _options_baseUrl !== void 0 ? _options_baseUrl : envUrl && envUrl !== "undefined" ? envUrl : "", defaultPriority = (_options_priority = options.priority) !== null && _options_priority !== void 0 ? _options_priority : 0.5, defaultChangefreq = options.changefreq, excludePatterns = options.exclude || [], entries = [], _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0; try { for (var _iterator = routes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) { var route = _step.value, _ref, _ref1, { path, routeExport } = route; if (!routeExport?.exclude && !(excludePatterns.length > 0 && import_micromatch.default.isMatch(path, excludePatterns))) { var priority = (_ref = routeExport?.priority) !== null && _ref !== void 0 ? _ref : defaultPriority, changefreq = (_ref1 = routeExport?.changefreq) !== null && _ref1 !== void 0 ? _ref1 : defaultChangefreq, lastmod = routeExport?.lastmod; entries.push({ path, priority, changefreq, lastmod }); } } } catch (err) { _didIteratorError = !0, _iteratorError = err; } finally { try { !_iteratorNormalCompletion && _iterator.return != null && _iterator.return(); } finally { if (_didIteratorError) throw _iteratorError; } } return buildSitemapXml(entries, baseUrl); } function buildSitemapXml(entries, baseUrl) { var urlEntries = entries.map(function (entry) { var loc = baseUrl ? `${baseUrl.replace(/\/$/, "")}${entry.path}` : entry.path, xml = ` <url> <loc>${escapeXml(loc)}</loc>`; if (entry.lastmod) { var date = _instanceof(entry.lastmod, Date) ? entry.lastmod.toISOString().split("T")[0] : entry.lastmod; xml += ` <lastmod>${escapeXml(date)}</lastmod>`; } return entry.changefreq && (xml += ` <changefreq>${entry.changefreq}</changefreq>`), entry.priority !== void 0 && (xml += ` <priority>${entry.priority.toFixed(1)}</priority>`), xml += ` </url>`, xml; }).join(` `); return `<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> ${urlEntries} </urlset> `; } function escapeXml(str) { return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;"); } //# sourceMappingURL=generateSitemap.native.js.map