one
Version:
One is a React framework for web, iOS, and Android apps.
1 lines • 3.41 kB
Source Map (JSON)
{"version":3,"file":"generateSitemap.js","names":[],"sources":["esm/cli/generateSitemap.js"],"sourcesContent":["import MicroMatch from \"micromatch\";\nfunction generateSitemap(routes, options) {\n const envUrl = process.env.ONE_SERVER_URL;\n const baseUrl = options.baseUrl ?? (envUrl && envUrl !== \"undefined\" ? envUrl : \"\");\n const defaultPriority = options.priority ?? 0.5;\n const defaultChangefreq = options.changefreq;\n const excludePatterns = options.exclude || [];\n const entries = [];\n for (const route of routes) {\n const { path, routeExport } = route;\n if (routeExport?.exclude) {\n continue;\n }\n if (excludePatterns.length > 0 && MicroMatch.isMatch(path, excludePatterns)) {\n continue;\n }\n const priority = routeExport?.priority ?? defaultPriority;\n const changefreq = routeExport?.changefreq ?? defaultChangefreq;\n const lastmod = routeExport?.lastmod;\n entries.push({\n path,\n priority,\n changefreq,\n lastmod\n });\n }\n return buildSitemapXml(entries, baseUrl);\n}\nfunction buildSitemapXml(entries, baseUrl) {\n const urlEntries = entries.map((entry) => {\n const loc = baseUrl ? `${baseUrl.replace(/\\/$/, \"\")}${entry.path}` : entry.path;\n let xml = ` <url>\n <loc>${escapeXml(loc)}</loc>`;\n if (entry.lastmod) {\n const date = entry.lastmod instanceof Date ? entry.lastmod.toISOString().split(\"T\")[0] : entry.lastmod;\n xml += `\n <lastmod>${escapeXml(date)}</lastmod>`;\n }\n if (entry.changefreq) {\n xml += `\n <changefreq>${entry.changefreq}</changefreq>`;\n }\n if (entry.priority !== void 0) {\n xml += `\n <priority>${entry.priority.toFixed(1)}</priority>`;\n }\n xml += \"\\n </url>\";\n return xml;\n }).join(\"\\n\");\n return `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n${urlEntries}\n</urlset>\n`;\n}\nfunction escapeXml(str) {\n return str.replace(/&/g, \"&\").replace(/</g, \"<\").replace(/>/g, \">\").replace(/\"/g, \""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