Compare commits

...

5 commits

Author SHA1 Message Date
Cat /dev/Nulo a624f664ef Parallelize reading files
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-11-25 22:18:10 -03:00
Cat /dev/Nulo d36f62ea2b gitignore: ignore tsconfig cache 2022-11-25 22:17:03 -03:00
Cat /dev/Nulo 0c3fca6a21 Clean up 2022-11-25 22:11:35 -03:00
Cat /dev/Nulo 70a8125fa8 Clean up parameters 2022-11-25 22:09:41 -03:00
Cat /dev/Nulo 93c919afa4 Improve TypeScript config 2022-11-25 22:09:17 -03:00
4 changed files with 27 additions and 15 deletions

2
.gitignore vendored
View file

@ -5,4 +5,6 @@ node_modules/
# Contains publish secrets
.npmrc
tsconfig.tsbuildinfo
src/**.js

View file

@ -5,6 +5,8 @@
"description": "",
"main": "index.js",
"scripts": {
"watch": "tsc --watch",
"start": "node src/",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],

View file

@ -19,7 +19,13 @@ interface Report {
things: Thing[];
}
function recurseElement(report: Report, rawHtml: string, el: Element) {
interface Page {
report: Report;
rawHtml: string;
}
function recurseElement(page: Page, el: Element) {
const { report, rawHtml } = page;
if (el.name === "a") {
if (el.attribs.href !== undefined) {
if (isHttp(el.attribs.href)) {
@ -42,7 +48,7 @@ function recurseElement(report: Report, rawHtml: string, el: Element) {
}
if (["audio", "video", "img", "source"].includes(el.name)) {
if (el.attribs.src) {
checkUrl(report, rawHtml, el, el.attribs.src);
checkUrl(page, el, el.attribs.src);
} else {
report.things.push({
type: "media-no-src",
@ -53,12 +59,12 @@ function recurseElement(report: Report, rawHtml: string, el: Element) {
for (const child of el.children) {
if (child.type === "tag") {
recurseElement(report, rawHtml, child);
recurseElement(page, child);
}
}
}
function checkUrl(report: Report, rawHtml: string, el: Element, url: string) {
function checkUrl({ report, rawHtml }: Page, el: Element, url: string) {
if (isHttp(url)) {
report.things.push({
type: "media-http",
@ -104,7 +110,7 @@ function processFile(content: string): Promise<Report> {
};
for (const el of dom) {
if (el.type === "tag") {
recurseElement(report, content, el);
recurseElement({ report, rawHtml: content }, el);
}
}
resolve(report);
@ -123,15 +129,17 @@ interface Reports {
let reports: Reports = {};
async function recurseDirectory(reports: Reports, path: string) {
const dir = await readdir(path, { withFileTypes: true });
for (const file of dir) {
const filePath = join(path, file.name);
if (file.isDirectory()) await recurseDirectory(reports, filePath);
else {
if (!file.name.endsWith(".html")) continue;
const content = await readFile(filePath, "utf-8");
reports[filePath] = await processFile(content);
}
}
return await Promise.all(
dir.map(async (file) => {
const filePath = join(path, file.name);
if (file.isDirectory()) await recurseDirectory(reports, filePath);
else {
if (!file.name.endsWith(".html")) return;
const content = await readFile(filePath, "utf-8");
reports[filePath] = await processFile(content);
}
})
);
}
await recurseDirectory(reports, dirPath);
const totalThings = Object.values(reports)

View file

@ -4,7 +4,7 @@
/* Visit https://aka.ms/tsconfig to read more about this file */
/* Projects */
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
"incremental": true /* Save .tsbuildinfo files to allow for incremental compilation of projects. */,
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */