| 103 | } |
| 104 | |
| 105 | async function inlineStyles(html, baseDir) { |
| 106 | const linkRegex = /<link\s+rel=["']stylesheet["']\s+href=["'](.+?)["']\s*\/?>(?:\s*<\/link>)?/gi; |
| 107 | let result = html; |
| 108 | let match; |
| 109 | while ((match = linkRegex.exec(html)) !== null) { |
| 110 | const href = match[1]; |
| 111 | const cssPath = path.resolve(baseDir, href); |
| 112 | const cssContent = await fs.readFile(cssPath, 'utf-8'); |
| 113 | const styleTag = `<style>\n${cssContent}\n</style>`; |
| 114 | result = result.replace(match[0], styleTag); |
| 115 | } |
| 116 | return result; |
| 117 | } |
| 118 | |
| 119 | async function inlineScripts(html, scripts) { |
| 120 | let result = html; |