one
Version:
One is a new React Framework that makes Vite serve both native and web.
131 lines (129 loc) • 4.95 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__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: true
}) : target, mod));
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
value: true
}), 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) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
}
function generateSitemap(routes, options) {
var _options_baseUrl, _options_priority;
var envUrl = process.env.ONE_SERVER_URL;
var baseUrl = (_options_baseUrl = options.baseUrl) !== null && _options_baseUrl !== void 0 ? _options_baseUrl : envUrl && envUrl !== "undefined" ? envUrl : "";
var defaultPriority = (_options_priority = options.priority) !== null && _options_priority !== void 0 ? _options_priority : 0.5;
var defaultChangefreq = options.changefreq;
var excludePatterns = options.exclude || [];
var entries = [];
var _iteratorNormalCompletion = true,
_didIteratorError = false,
_iteratorError = void 0;
try {
for (var _iterator = routes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var route = _step.value;
var _ref, _ref1;
var {
path,
routeExport
} = route;
if (routeExport === null || routeExport === void 0 ? void 0 : routeExport.exclude) {
continue;
}
if (excludePatterns.length > 0 && import_micromatch.default.isMatch(path, excludePatterns)) {
continue;
}
var priority = (_ref = routeExport === null || routeExport === void 0 ? void 0 : routeExport.priority) !== null && _ref !== void 0 ? _ref : defaultPriority;
var changefreq = (_ref1 = routeExport === null || routeExport === void 0 ? void 0 : routeExport.changefreq) !== null && _ref1 !== void 0 ? _ref1 : defaultChangefreq;
var lastmod = routeExport === null || routeExport === void 0 ? void 0 : routeExport.lastmod;
entries.push({
path,
priority,
changefreq,
lastmod
});
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_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;
var 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>`;
}
if (entry.changefreq) {
xml += `
<changefreq>${entry.changefreq}</changefreq>`;
}
if (entry.priority !== void 0) {
xml += `
<priority>${entry.priority.toFixed(1)}</priority>`;
}
xml += "\n </url>";
return xml;
}).join("\n");
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, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
}
//# sourceMappingURL=generateSitemap.native.js.map