UNPKG

website-scrap-engine

Version:
34 lines 1.23 kB
import parseCssUrls from 'css-url-parser'; import { ResourceType } from '../resource.js'; import { toString } from '../util.js'; export async function processCssText(cssText, res, options, pipeline, depth, resources) { const cssUrls = parseCssUrls(cssText); let rawUrl, r; // noinspection DuplicatedCode for (let i = 0, l = cssUrls.length; i < l; i++) { rawUrl = cssUrls[i]; r = await pipeline.createAndProcessResource(rawUrl, ResourceType.Binary, depth, null, res); if (!r) continue; if (!r.shouldBeDiscardedFromDownload) { resources.push(r); } cssText = cssText.split(rawUrl).join(r.replacePath); } return cssText; } export async function processCss(res, submit, options, pipeline) { if (res.type !== ResourceType.Css) { return res; } const depth = res.depth + 1; const resources = []; let cssText = toString(res.body, res.encoding || options.encoding[ResourceType.Css]); cssText = await processCssText(cssText, res, options, pipeline, depth, resources); res.body = cssText; res.meta.cssProcessed = 1; await submit(resources); return res; } //# sourceMappingURL=process-css.js.map