Compare commits
5 commits
d20d8fc238
...
a624f664ef
Author | SHA1 | Date | |
---|---|---|---|
a624f664ef | |||
d36f62ea2b | |||
0c3fca6a21 | |||
70a8125fa8 | |||
93c919afa4 |
4 changed files with 27 additions and 15 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -5,4 +5,6 @@ node_modules/
|
|||
# Contains publish secrets
|
||||
.npmrc
|
||||
|
||||
tsconfig.tsbuildinfo
|
||||
|
||||
src/**.js
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"watch": "tsc --watch",
|
||||
"start": "node src/",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
|
|
36
src/index.ts
36
src/index.ts
|
@ -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)
|
||||
|
|
|
@ -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. */
|
||||
|
|
Loading…
Reference in a new issue