-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.js
58 lines (47 loc) · 1.45 KB
/
build.js
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
const fs = require("fs").promises;
const glob = require("glob");
const cheerio = require("cheerio");
const content = `
<script src="https://cdn.tailwindcss.com"></script>
<script defer src="https://unpkg.com/@lottiefiles/[email protected]/dist/lottie-player.js"></script>
`;
const allowedDomains = [
"https://tailwind.besoeasy.com/",
"https://cdn.tailwindcss.com",
"https://unpkg.com",
"https://i.ibb.co",
"https://images.unsplash.com/",
];
async function checkAssetsForDomains(filePath) {
try {
const fileContent = await fs.readFile(filePath, "utf8");
const $ = cheerio.load(fileContent);
$("img, script[src], link[href]").each(function () {
const assetSrc = $(this).attr("src") || $(this).attr("href");
if (
assetSrc &&
!allowedDomains.some((domain) => assetSrc.startsWith(domain))
) {
console.log(
`File: ${filePath} contains asset not from the specified domain: ${assetSrc}`
);
}
});
} catch (err) {
console.error("Error reading file or checking assets:", err);
}
}
async function buildPages() {
try {
const files = await glob.sync("dist/**/*.html");
console.log("Total Components:", files.length);
for (const filename of files) {
await checkAssetsForDomains(filename);
await fs.appendFile(filename, content);
}
console.log("Tags Injected");
} catch (err) {
console.error("Error building pages:", err);
}
}
buildPages();