Skip to content

Commit 6ca4c9d

Browse files
committed
revealjs - don't add empty css file as dependency
This happens with `quarto-html` dependency, which can be emptied when it contains only the `quarto-variables-start` part. Detecting this helps reduce unneeded typescript processing, and inserting an empty file.
1 parent a538651 commit 6ca4c9d

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/command/render/pandoc-html.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,18 @@ export async function resolveSassBundles(
127127
}
128128

129129
for (const target of targets) {
130-
let cssPath = await compileSass(target.bundles, temp);
130+
let cssPath: string | undefined;
131+
cssPath = await compileSass(target.bundles, temp);
131132
// First, Clean CSS
132133
cleanSourceMappingUrl(cssPath);
133134
// look for a sentinel 'dark' value, extract variables
134135
const cssResult = processCssIntoExtras(cssPath, extras, temp);
135136
cssPath = cssResult.path;
137+
138+
// it can happen that processing generate an empty css file (e.g quarto-html deps with Quarto CSS variables)
139+
// in that case, no need to insert the cssPath in the dependency
140+
if (!cssPath) continue;
141+
136142
// Process attributes (forward on to the target)
137143
for (const bundle of target.bundles) {
138144
if (bundle.attribs) {
@@ -427,7 +433,7 @@ function generateThemeCssClasses(
427433
}
428434

429435
interface CSSResult {
430-
path: string;
436+
path: string | undefined;
431437
dark: boolean;
432438
}
433439

@@ -468,10 +474,14 @@ function processCssIntoExtras(
468474

469475
if (dirty) {
470476
const cleanedCss = css.replaceAll(kVariablesRegex, "");
471-
const hash = md5HashBytes(new TextEncoder().encode(cleanedCss));
472-
const newCssPath = temp.createFile({ suffix: `-${hash}.css` });
473-
474-
writeTextFileSyncPreserveMode(newCssPath, cleanedCss);
477+
let newCssPath: string | undefined;
478+
if (cleanedCss.trim() === "") {
479+
newCssPath = undefined;
480+
} else {
481+
const hash = md5HashBytes(new TextEncoder().encode(cleanedCss));
482+
newCssPath = temp.createFile({ suffix: `-${hash}.css` });
483+
writeTextFileSyncPreserveMode(newCssPath, cleanedCss);
484+
}
475485

476486
return {
477487
dark: hasDarkSentinel,

0 commit comments

Comments
 (0)