-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsitemap.js
More file actions
51 lines (51 loc) · 2.35 KB
/
sitemap.js
File metadata and controls
51 lines (51 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"use strict";
exports.__esModule = true;
var paths_1 = require("./data/paths");
var cssville_1 = require("cssville-generators/build/cssville");
var path = require('path');
var fs = require('fs');
function traversePaths(obj, basePath) {
if (basePath === void 0) { basePath = ''; }
var entries = [];
Object.keys(obj).forEach(function (key) {
var value = obj[key];
if (typeof value === 'string') {
// If the value is a string, it's a path
// Add /docs prefix for components and css-classes paths
var needsDocsPrefix = (basePath === 'components' || value.startsWith('components/') ||
value.startsWith('css-classes/') || basePath === 'intro' ||
value.startsWith('intro/'));
var prefix = needsDocsPrefix ? '/docs' : '';
entries.push({
loc: "".concat(prefix, "/").concat(value).replace(/\/+/g, '/'),
lastmod: new Date().toISOString().split('T')[0]
});
}
else if (typeof value === 'function' && key === 'cssClasses') {
// Special case for dynamic paths, such as cssClasses
entries.push.apply(entries, cssville_1.Cssville.generators.map(function (g) { return ({
loc: "/docs/".concat(value(g.name)).replace(/\/+/g, '/'),
lastmod: new Date().toISOString().split('T')[0]
}); }));
}
else if (typeof value === 'object') {
// If the value is an object, recurse
entries = entries.concat(traversePaths(value, key));
}
});
return entries;
}
// Generate the sitemap entries from the paths
function buildSitemapEntries() {
return traversePaths(paths_1.paths);
}
// Generate the sitemap entries
var urls = buildSitemapEntries();
var domain = "cssville.xyz";
var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n ".concat(urls
.map(function (url) { return "\n <url>\n <loc>".concat("https://".concat(domain).concat(url.loc), "</loc>\n <lastmod>").concat(url.lastmod, "</lastmod>\n </url>"); })
.join(''), "\n</urlset>");
// Write the sitemap.xml file to the public directory
var sitemapPath = path.resolve(__dirname, 'sitemap.xml');
fs.writeFileSync(sitemapPath, xml);
console.log('sitemap.xml has been generated at', sitemapPath);