chequear sources y otros elementos correctamente
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
parent
558d1e66b7
commit
ada8122f60
1 changed files with 63 additions and 5 deletions
68
src/index.ts
68
src/index.ts
|
@ -58,13 +58,65 @@ function recurseElement(page: Page, el: Element) {
|
|||
});
|
||||
}
|
||||
}
|
||||
if (
|
||||
["audio", "video", "img", "source", "iframe", "track"].includes(el.name)
|
||||
) {
|
||||
|
||||
if (["audio", "video"].includes(el.name)) {
|
||||
const sources = getSources(el);
|
||||
for (const source of sources) {
|
||||
if (source.attribs.src) {
|
||||
checkUrl(page, source, source.attribs.src);
|
||||
} else {
|
||||
report.things.push({
|
||||
type: "media-no-src",
|
||||
description: getHtml(rawHtml, source),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (["picture"].includes(el.name)) {
|
||||
const sources = getSources(el);
|
||||
for (const source of sources) {
|
||||
if (source.attribs.srcset) {
|
||||
// TODO: implementar srcset #3
|
||||
} else {
|
||||
report.things.push({
|
||||
type: "media-no-src",
|
||||
description: getHtml(rawHtml, source),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (["img"].includes(el.name)) {
|
||||
if (el.attribs.srcset) {
|
||||
// TODO: implementar srcset #3
|
||||
}
|
||||
}
|
||||
if (["audio", "video"].includes(el.name)) {
|
||||
const sources = getSources(el);
|
||||
if (sources.length > 0) {
|
||||
for (const source of sources) {
|
||||
if (source.attribs.src) {
|
||||
checkUrl(page, source, source.attribs.src);
|
||||
} else {
|
||||
report.things.push({
|
||||
type: "media-no-src",
|
||||
description: getHtml(rawHtml, source),
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (el.attribs.src) {
|
||||
checkUrl(page, el, el.attribs.src);
|
||||
} else {
|
||||
report.things.push({
|
||||
type: "media-no-src",
|
||||
description: getHtml(rawHtml, el),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (["img", "iframe", "track"].includes(el.name)) {
|
||||
if (el.attribs.src) {
|
||||
checkUrl(page, el, el.attribs.src);
|
||||
} else if (el.attribs.srcset) {
|
||||
// TODO: implementar srcset #3
|
||||
} else {
|
||||
report.things.push({
|
||||
type: "media-no-src",
|
||||
|
@ -80,6 +132,12 @@ function recurseElement(page: Page, el: Element) {
|
|||
}
|
||||
}
|
||||
|
||||
function getSources(el: Element) {
|
||||
return el.children.filter(
|
||||
(c) => c.type === "tag" && c.name === "source"
|
||||
) as Element[];
|
||||
}
|
||||
|
||||
function checkUrl({ report, rawHtml }: Page, el: Element, url: string) {
|
||||
if (isHttp(url)) {
|
||||
report.things.push({
|
||||
|
|
Loading…
Reference in a new issue