core/validators/source.page.validator.ts

core/validators/source.page.validator.ts is a file in Bane's Lab Build Scripts. 40 lines of code and 8 definitions.

import type { Finding, PageListing, Seen } from "#types/validation.types";
import { checkEncodings, checkSchema } from "#core/validators/metadata.validator";
import { checkFile, checkPageBytes, checkPageHeadings, isServedUrl } from "#core/validators/build.validator";
import { checkIndexable, checkLinks, checkPage, checkSitemap } from "#core/validators/site.validator";
import { SITE_URL } from "@banes-lab/web/core/assets/link.assets.ts";
import { fileForPath } from "#core/resolvers/page.resolver";
import { mapSettled } from "#core/adapters/document.adapter";
import { readArtifact } from "#core/converters/build.converter";
import { readOrNull } from "#core/loaders/build.loader";
import { sitemapPartFiles } from "#core/resolvers/route.resolver";

const servedPageFinding = function servedPageFinding(path: string, served: ReadonlySet<string>, seen: Seen): Finding[] {
    const file = fileForPath(path);
    return checkFile(file, (html) => {
        const artifact = readArtifact(html);
        const address = SITE_URL + path;
        return [
            ...checkPage(file, artifact, address, seen),
            ...checkIndexable(file, artifact, true),
            ...checkSchema(file, artifact, address),
            ...checkEncodings(file, artifact, isServedUrl),
            ...checkLinks(file, artifact, served),
            ...checkPageBytes(file, html),
            ...checkPageHeadings(file, html),
        ];
    });
};

export const servedPageFindings = async function servedPageFindings(
    paths: readonly string[],
    listing: PageListing,
    seen: Seen,
): Promise<Finding[]> {
    const file = listing.sitemap.slice(1);
    const listed = paths.filter(listing.listed).map((path) => SITE_URL + path);
    const parts = sitemapPartFiles(listing.sitemap, (part) => readOrNull(part) !== null);
    const pages = await mapSettled(paths, (path) => servedPageFinding(path, listing.served, seen));
    return [
        ...pages.flat(),
        ...checkFile(file, () => checkSitemap(file, parts.map((part) => readOrNull(part) ?? "").join("\n"), listed)),
    ];
};