forked from DustinBrett/daedalOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobots.js
More file actions
74 lines (63 loc) · 2.02 KB
/
robots.js
File metadata and controls
74 lines (63 loc) · 2.02 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const { readdirSync, statSync, writeFileSync } = require("fs");
const { extname, join } = require("path");
const { author } = require("../package.json");
const xmlUrls = [];
const buildAppSitemap = (path) => {
readdirSync(path).forEach((entry) => {
if (statSync(join(path, entry)).isDirectory()) {
xmlUrls.push(
`<url><loc>${author.url}/?app=${entry.replace(/-/g, "")}</loc></url>`
);
}
});
};
const buildFileSitemap = (path, excludePaths, callback) => {
const publicPath = join("public/", path);
readdirSync(publicPath).forEach((entry) => {
const entryPath = join(path, entry);
const urlEntryPath = entryPath.replace(/\\/g, "/");
const stats = statSync(join(publicPath, entry));
if (stats.isDirectory()) {
if (!excludePaths.includes(urlEntryPath)) {
buildFileSitemap(entryPath, excludePaths, callback);
}
} else if (![".ini", ".url"].includes(extname(entry).toLowerCase())) {
const encodedUrlEntryPath = encodeURI(urlEntryPath).replace(/'/g, "%27");
xmlUrls.push(
callback(
`${author.url}/?url=${encodedUrlEntryPath}`,
stats.mtime.toISOString().substring(0, 10),
`${author.url}/${encodedUrlEntryPath}`
)
);
}
});
};
buildAppSitemap("components/apps");
buildFileSitemap(
"Users/Public/Documents",
[],
(path, mtime) => `<url><loc>${path}</loc><lastmod>${mtime}</lastmod></url>`
);
buildFileSitemap(
"Users/Public/Pictures",
["Users/Public/Pictures/Blog"],
(path, mtime, url) =>
`<url><loc>${path}</loc><image:image><image:loc>${url}</image:loc></image:image><lastmod>${mtime}</lastmod></url>`
);
writeFileSync(
"public/sitemap.xml",
`<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">${xmlUrls.join(
""
)}</urlset>`,
{
flag: "w",
}
);
writeFileSync(
"public/robots.txt",
`User-agent: *\nAllow: /\n\nSitemap: ${author.url}/sitemap.xml\n`,
{
flag: "w",
}
);