Skip to content

Commit

Permalink
fix: inject styles and scripts in given order
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhaenisch committed Apr 7, 2021
1 parent 1ce3c7a commit e1b6003
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"@typescript-eslint/prefer-readonly-parameter-types": "off",
"camelcase": "off",
"capitalized-comments": "off",
"no-await-in-loop": "off",
"no-promise-executor-return": "off",
"node/no-unsupported-features/es-syntax": "off",
"unicorn/no-array-callback-reference": "off",
Expand Down
17 changes: 10 additions & 7 deletions src/lib/generate-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ export async function generateOutput(html: string, relativePath: string, config:
await page.goto(`http://localhost:${config.port!}${relativePath}`); // make sure relative paths work as expected
await page.setContent(html); // overwrite the page content with what was generated from the markdown

await Promise.all([
...config.stylesheet.map(
async (stylesheet) => page.addStyleTag(isHttpUrl(stylesheet) ? { url: stylesheet } : { path: stylesheet }), // add each stylesheet
),
config.css ? page.addStyleTag({ content: config.css }) : undefined, // add custom css
]);
for (const stylesheet of config.stylesheet) {
await page.addStyleTag(isHttpUrl(stylesheet) ? { url: stylesheet } : { path: stylesheet });
}

await Promise.all(config.script.map(async (scriptTagOptions) => page.addScriptTag(scriptTagOptions)));
if (config.css) {
await page.addStyleTag({ content: config.css });
}

for (const scriptTagOptions of config.script) {
await page.addScriptTag(scriptTagOptions);
}

/**
* Trick to wait for network to be idle.
Expand Down

0 comments on commit e1b6003

Please sign in to comment.