Skip to content

Commit f7076fe

Browse files
do not emit dark stylesheets when there is no dark brand
properly handle absent light or dark brand do not emit empty light/dark brand bundles
1 parent 5df4e19 commit f7076fe

File tree

6 files changed

+68
-17
lines changed

6 files changed

+68
-17
lines changed

src/command/render/pandoc-html.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ export async function resolveSassBundles(
123123
}
124124
return bundle as SassBundle;
125125
});
126-
if (!foundBrand.light || !foundBrand.dark) {
126+
if (maybeBrandBundle && (!foundBrand.light || !foundBrand.dark)) {
127127
bundles.unshift({
128128
dependency,
129129
key: "brand",
130-
user: !foundBrand.light && maybeBrandBundle?.user as SassLayer[] || [],
131-
dark: !foundBrand.dark && maybeBrandBundle?.dark?.user && {
130+
user: !foundBrand.light && maybeBrandBundle.user as SassLayer[] || [],
131+
dark: !foundBrand.dark && maybeBrandBundle.dark?.user && {
132132
user: maybeBrandBundle.dark.user as SassLayer[],
133133
default: maybeBrandBundle.dark.default,
134134
} || undefined,

src/core/sass/brand.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -582,14 +582,16 @@ export async function brandSassLayers(
582582
dark: []
583583
};
584584

585-
for (const layer of [sassLayers.light, sassLayers.dark]) {
586-
layer.push({
587-
defaults: '$theme: "brand" !default;',
588-
uses: "",
589-
functions: "",
590-
mixins: "",
591-
rules: "",
592-
});
585+
for (const mode of ["light", "dark"] as Array<"dark" | "light">) {
586+
if (brand && brand[mode]) {
587+
sassLayers[mode].push({
588+
defaults: '$theme: "brand" !default;',
589+
uses: "",
590+
functions: "",
591+
mixins: "",
592+
rules: "",
593+
});
594+
}
593595
}
594596
if (brand?.light?.data.color) {
595597
sassLayers.light.push(brandColorLayer(brand?.light, nameMap));
@@ -658,10 +660,10 @@ export async function brandSassFormatExtras(
658660
key: "brand",
659661
dependency: "bootstrap",
660662
user: htmlSassBundleLayers.light,
661-
dark: {
663+
dark: htmlSassBundleLayers.dark.length ? {
662664
user: htmlSassBundleLayers.dark,
663665
default: darkModeDefault(format.metadata)
664-
}
666+
} : undefined
665667
},
666668
],
667669
},

src/project/project-shared.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,18 +602,18 @@ export async function projectResolveBrand(
602602
let light, dark;
603603
if (typeof brand.light === "string") {
604604
light = await loadRelativeBrand(brand.light);
605-
} else {
605+
} else if (brand.light) {
606606
light = new Brand(
607-
brand.light!,
607+
brand.light,
608608
dirname(fileName),
609609
project.dir,
610610
);
611611
}
612612
if (typeof brand.dark === "string") {
613613
dark = await loadRelativeBrand(brand.dark);
614-
} else {
614+
} else if(brand.dark) {
615615
dark = new Brand(
616-
brand.dark!,
616+
brand.dark,
617617
dirname(fileName),
618618
project.dir,
619619
);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
format: html
3+
brand:
4+
light: united-brand.yml
5+
_quarto:
6+
tests:
7+
html:
8+
ensureHtmlElements:
9+
- []
10+
- ["link[href*=\"-dark-\"]"]
11+
---
12+
13+
## Hello
14+
15+
```markdown
16+
![asdf](asd.png)
17+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
format: html
3+
theme:
4+
light: united
5+
_quarto:
6+
tests:
7+
html:
8+
ensureHtmlElements:
9+
- []
10+
- ["link[href*=\"-dark-\"]"]
11+
---
12+
13+
## Hello
14+
15+
```markdown
16+
![asdf](asd.png)
17+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
format: html
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
- []
8+
- ["link[href*=\"-dark-\"]"]
9+
---
10+
11+
## Hello
12+
13+
```markdown
14+
![asdf](asd.png)
15+
```

0 commit comments

Comments
 (0)