Skip to content

Commit 7a555bd

Browse files
committed
brand - pass colors to revealjs theme. use sass 'primary' variable for link color in reveal if defined
1 parent 4255c0c commit 7a555bd

File tree

7 files changed

+83
-28
lines changed

7 files changed

+83
-28
lines changed

src/command/render/pandoc.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
kHtmlFinalizers,
3131
kHtmlPostprocessors,
3232
kMarkdownAfterBody,
33-
kSassBundles,
3433
kTextHighlightingMode,
3534
} from "../../config/types.ts";
3635
import {
@@ -201,7 +200,6 @@ import {
201200
MarkdownPipelineHandler,
202201
} from "../../core/markdown-pipeline.ts";
203202
import { getEnv } from "../../../package/src/util/utils.ts";
204-
import { brandSassFormatExtras } from "../../core/sass/brand.ts";
205203

206204
// in case we are running multiple pandoc processes
207205
// we need to make sure we capture all of the trace files
@@ -405,17 +403,10 @@ export async function runPandoc(
405403
))
406404
: {};
407405

408-
const brandExtras: FormatExtras = await brandSassFormatExtras(
409-
options.format,
410-
options.project,
411-
);
412-
413406
// start with the merge
414407
const inputExtras = mergeConfigs(
415408
projectExtras,
416409
formatExtras,
417-
brandExtras,
418-
// project documentclass always wins
419410
{
420411
metadata: projectExtras.metadata?.[kDocumentClass]
421412
? {

src/core/sass/brand.ts

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,29 @@ import {
1111
FormatExtras,
1212
kSassBundles,
1313
SassBundle,
14+
SassBundleLayers,
1415
} from "../../config/types.ts";
1516
import { ProjectContext } from "../../project/types.ts";
1617

17-
export async function brandSassFormatExtras(
18-
_format: Format,
18+
export async function brandBootstrapSassBundles(
1919
project: ProjectContext,
20-
): Promise<FormatExtras> {
20+
key: string,
21+
): Promise<SassBundle[]> {
22+
return (await brandBootstrapSassBundleLayers(project, key)).map(
23+
(layer: SassBundleLayers) => {
24+
return {
25+
...layer,
26+
dependency: "bootstrap",
27+
};
28+
},
29+
);
30+
}
31+
export async function brandBootstrapSassBundleLayers(
32+
project: ProjectContext,
33+
key: string,
34+
): Promise<SassBundleLayers[]> {
2135
const brand = await project.resolveBrand();
22-
if (!brand) {
23-
return {};
24-
}
25-
const sassBundles: SassBundle[] = [];
36+
const sassBundles: SassBundleLayers[] = [];
2637

2738
if (brand?.data.color) {
2839
const colorVariables: string[] = ["/* color variables from _brand.yml */"];
@@ -40,9 +51,9 @@ export async function brandSassFormatExtras(
4051
);
4152
}
4253
// const colorEntries = Object.keys(brand.color);
43-
const colorBundle: SassBundle = {
44-
key: "brand-color",
45-
dependency: "bootstrap",
54+
const colorBundle: SassBundleLayers = {
55+
key,
56+
// dependency: "bootstrap",
4657
quarto: {
4758
defaults: colorVariables.join("\n"),
4859
uses: "",
@@ -54,9 +65,37 @@ export async function brandSassFormatExtras(
5465
sassBundles.push(colorBundle);
5566
}
5667

57-
return {
58-
html: {
59-
[kSassBundles]: sassBundles,
60-
},
61-
};
68+
return sassBundles;
69+
}
70+
71+
export async function brandRevealSassBundleLayers(
72+
_format: Format,
73+
project: ProjectContext,
74+
): Promise<SassBundleLayers[]> {
75+
return brandBootstrapSassBundleLayers(project, "reveal-theme");
76+
}
77+
78+
export async function brandSassFormatExtras(
79+
_format: Format,
80+
project: ProjectContext,
81+
): Promise<FormatExtras> {
82+
const htmlSassBundleLayers = await brandBootstrapSassBundleLayers(
83+
project,
84+
"brand",
85+
);
86+
const htmlSassBundles: SassBundle[] = htmlSassBundleLayers.map((layer) => {
87+
return {
88+
...layer,
89+
dependency: "bootstrap",
90+
};
91+
});
92+
if (htmlSassBundles.length === 0) {
93+
return {};
94+
} else {
95+
return {
96+
html: {
97+
[kSassBundles]: htmlSassBundles,
98+
},
99+
};
100+
}
62101
}

src/format/dashboard/format-dashboard.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ import { projectIsWebsite } from "../../project/project-shared.ts";
6161
import { processShinyComponents } from "./format-dashboard-shiny.ts";
6262
import { processToolbars } from "./format-dashboard-toolbar.ts";
6363
import { processDatatables } from "./format-dashboard-tables.ts";
64+
import { assert } from "testing/asserts.ts";
65+
import { brandBootstrapSassBundles } from "../../core/sass/brand.ts";
6466

6567
const kDashboardClz = "quarto-dashboard";
6668

@@ -94,6 +96,7 @@ export function dashboardFormat() {
9496
project?: ProjectContext,
9597
quiet?: boolean,
9698
) => {
99+
assert(project);
97100
if (baseHtmlFormat.formatExtras) {
98101
// Read the dashboard metadata
99102
const dashboard = await dashboardMeta(format);
@@ -156,12 +159,17 @@ export function dashboardFormat() {
156159
scrolling: dashboard.scrolling,
157160
};
158161

162+
extras.html[kSassBundles] = extras.html[kSassBundles] || [];
159163
if (!isWebsiteProject) {
160164
// If this is a website project, it will inject the scss for dashboards
161-
extras.html[kSassBundles] = extras.html[kSassBundles] || [];
162165
extras.html[kSassBundles].unshift(dashboardScssLayer());
163166
}
164167

168+
// add _brand.yml sass bundle
169+
extras.html[kSassBundles].push(
170+
...await brandBootstrapSassBundles(project, "bootstrap"),
171+
);
172+
165173
const scripts: DependencyHtmlFile[] = [];
166174
const stylesheets: DependencyHtmlFile[] = [];
167175

src/format/html/format-html.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ import {
113113
} from "./format-html-types.ts";
114114
import { kQuartoHtmlDependency } from "./format-html-constants.ts";
115115
import { registerWriterFormatHandler } from "../format-handlers.ts";
116+
import { brandSassFormatExtras } from "../../core/sass/brand.ts";
116117

117118
export function htmlFormat(
118119
figwidth: number,
@@ -171,6 +172,7 @@ export function htmlFormat(
171172
project,
172173
quiet,
173174
),
175+
await brandSassFormatExtras(format, project),
174176
{ [kFilterParams]: htmlFilterParams },
175177
);
176178
},

src/format/reveal/format-reveal-theme.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import { titleSlideScss } from "./format-reveal-title.ts";
3838
import { asCssFont, asCssNumber } from "../../core/css.ts";
3939
import { cssHasDarkModeSentinel } from "../../core/pandoc/css.ts";
4040
import { pandocNativeStr } from "../../core/pandoc/codegen.ts";
41+
import { ProjectContext } from "../../project/types.ts";
42+
import { brandRevealSassBundleLayers } from "../../core/sass/brand.ts";
4143

4244
export const kRevealLightThemes = [
4345
"white",
@@ -63,6 +65,7 @@ export async function revealTheme(
6365
input: string,
6466
libDir: string,
6567
temp: TempContext,
68+
project: ProjectContext,
6669
) {
6770
// metadata override to return
6871
const metadata: Metadata = {};
@@ -175,8 +178,13 @@ export async function revealTheme(
175178
loadPaths,
176179
};
177180

181+
const brandLayers: SassBundleLayers[] = await brandRevealSassBundleLayers(
182+
format,
183+
project,
184+
);
185+
178186
// compile sass
179-
const css = await compileSass([bundleLayers], temp);
187+
const css = await compileSass([bundleLayers, ...brandLayers], temp);
180188
copyTo(
181189
css,
182190
join(revealDestDir, "dist", "theme", "quarto.css"),

src/format/reveal/format-reveal.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,13 @@ export function revealjsFormat() {
150150
}
151151

152152
// get theme info (including text highlighing mode)
153-
const theme = await revealTheme(format, input, libDir, services.temp);
153+
const theme = await revealTheme(
154+
format,
155+
input,
156+
libDir,
157+
services.temp,
158+
project,
159+
);
154160

155161
const revealPluginData = await revealPluginExtras(
156162
input,

src/resources/formats/revealjs/quarto.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ $body-color: #222 !default;
1919
$text-muted: lighten($body-color, 30%) !default;
2020

2121
// link colors
22-
$link-color: #2a76dd !default;
22+
$primary: #2a76dd !default;
23+
$link-color: $primary !default;
2324
$link-color-hover: lighten($link-color, 10%) !default;
2425

2526
// selection colors

0 commit comments

Comments
 (0)