summaryrefslogtreecommitdiff
path: root/src/build/static.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/build/static.ts')
-rw-r--r--src/build/static.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/build/static.ts b/src/build/static.ts
new file mode 100644
index 000000000..f7518c7be
--- /dev/null
+++ b/src/build/static.ts
@@ -0,0 +1,26 @@
+import type {Element} from 'domhandler';
+import cheerio from 'cheerio';
+
+export function collectStatics(html: string) {
+ const statics = new Set<string>();
+
+ const $ = cheerio.load(html);
+
+ const append = (el: Element, attr: string) => {
+ const value: string = $(el).attr(attr)!;
+ if(value.startsWith('http')) {
+ return;
+ }
+ statics.add(value);
+ }
+
+ $('link[href]').each((i, el) => {
+ append(el, 'href');
+ });
+
+ $('img[src]').each((i, el) => {
+ append(el, 'src');
+ });
+
+ return statics;
+} \ No newline at end of file