-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
24 lines (21 loc) · 813 Bytes
/
test.js
File metadata and controls
24 lines (21 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const { getPageMetadata } = require("./dist/metadata.js");
const { JSDOM } = require("jsdom");
const fs = require("fs");
const { assert } = require("console");
const dir = fs.readdirSync("./test");
const sanitizeHtml = (html) => {
return html
?.replace(/<style([\S\s]*?)>([\S\s]*?)<\/style>/gim, "")
?.replace(/<script([\S\s]*?)>([\S\s]*?)<\/script>/gim, "");
};
dir
.filter((file) => file.endsWith(".html"))
.forEach((file) => {
const html = fs.readFileSync(`./test/${file}`, { encoding: "utf8" });
const doc = new JSDOM(sanitizeHtml(html)).window.document;
const metadata = getPageMetadata(
doc,
`https://techcrunch.com/2022/05/19/god-of-war-ragnarok-sets-a-strong-example-for-next-gen-gaming-accessibility-options/`
);
console.info("Metadata", metadata);
});