UNPKG

one

Version:

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

70 lines (69 loc) 3.35 kB
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 generateSitemap(routes, options) { const envUrl = process.env.ONE_SERVER_URL, baseUrl = options.baseUrl ?? (envUrl && envUrl !== "undefined" ? envUrl : ""), defaultPriority = options.priority ?? 0.5, defaultChangefreq = options.changefreq, excludePatterns = options.exclude || [], entries = []; for (const route of routes) { const { path, routeExport } = route; if (routeExport?.exclude || excludePatterns.length > 0 && import_micromatch.default.isMatch(path, excludePatterns)) continue; const priority = routeExport?.priority ?? defaultPriority, changefreq = routeExport?.changefreq ?? defaultChangefreq, lastmod = routeExport?.lastmod; entries.push({ path, priority, changefreq, lastmod }); } return buildSitemapXml(entries, baseUrl); } function buildSitemapXml(entries, baseUrl) { return `<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> ${entries.map((entry) => { const loc = baseUrl ? `${baseUrl.replace(/\/$/, "")}${entry.path}` : entry.path; let xml = ` <url> <loc>${escapeXml(loc)}</loc>`; if (entry.lastmod) { const date = entry.lastmod instanceof 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(` `)} </urlset> `; } function escapeXml(str) { return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;"); } //# sourceMappingURL=generateSitemap.js.map