MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / collectExternalStyles

Function collectExternalStyles

packages/lint/src/project.ts:50–70  ·  view source on GitHub ↗
(
  projectDir: string,
  html: string,
  compSrcPath?: string,
)

Source from the content-addressed store, hash-verified

48}
49
50function collectExternalStyles(
51 projectDir: string,
52 html: string,
53 compSrcPath?: string,
54): Array<{ href: string; content: string }> {
55 const styles: Array<{ href: string; content: string }> = [];
56 const linkRe = /<link\b[^>]*>/gi;
57 let match: RegExpExecArray | null;
58 while ((match = linkRe.exec(html)) !== null) {
59 const tag = match[0];
60 const rel = tag.match(/\brel\s*=\s*["']([^"']+)["']/i)?.[1] ?? "";
61 if (!rel.split(/\s+/).some((part) => part.toLowerCase() === "stylesheet")) continue;
62 const href = tag.match(/\bhref\s*=\s*["']([^"']+)["']/i)?.[1] ?? "";
63 if (!isLocalStylesheetHref(href)) continue;
64 const rootRelative = compSrcPath ? join(dirname(compSrcPath), href) : href;
65 const stylesheet = resolveExistingLocalAsset(projectDir, rootRelative);
66 if (!stylesheet) continue;
67 styles.push({ href, content: readFileSync(stylesheet.resolved, "utf-8") });
68 }
69 return styles;
70}
71
72function collectCssSources(projectDir: string, html: string, compSrcPath?: string): CssSource[] {
73 const sources: CssSource[] = [];

Callers 1

lintProjectFunction · 0.85

Calls 2

isLocalStylesheetHrefFunction · 0.85

Tested by

no test coverage detected