Skip to content

_brand.yml - pass colors to revealjs theme. use sass 'primary' variable for links in revealjs #10341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/command/render/pandoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
kHtmlFinalizers,
kHtmlPostprocessors,
kMarkdownAfterBody,
kSassBundles,
kTextHighlightingMode,
} from "../../config/types.ts";
import {
Expand Down Expand Up @@ -201,7 +200,6 @@ import {
MarkdownPipelineHandler,
} from "../../core/markdown-pipeline.ts";
import { getEnv } from "../../../package/src/util/utils.ts";
import { brandSassFormatExtras } from "../../core/sass/brand.ts";

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

const brandExtras: FormatExtras = await brandSassFormatExtras(
options.format,
options.project,
);

// start with the merge
const inputExtras = mergeConfigs(
projectExtras,
formatExtras,
brandExtras,
// project documentclass always wins
{
metadata: projectExtras.metadata?.[kDocumentClass]
? {
Expand Down
69 changes: 54 additions & 15 deletions src/core/sass/brand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,29 @@ import {
FormatExtras,
kSassBundles,
SassBundle,
SassBundleLayers,
} from "../../config/types.ts";
import { ProjectContext } from "../../project/types.ts";

export async function brandSassFormatExtras(
_format: Format,
export async function brandBootstrapSassBundles(
project: ProjectContext,
): Promise<FormatExtras> {
key: string,
): Promise<SassBundle[]> {
return (await brandBootstrapSassBundleLayers(project, key)).map(
(layer: SassBundleLayers) => {
return {
...layer,
dependency: "bootstrap",
};
},
);
}
export async function brandBootstrapSassBundleLayers(
project: ProjectContext,
key: string,
): Promise<SassBundleLayers[]> {
const brand = await project.resolveBrand();
if (!brand) {
return {};
}
const sassBundles: SassBundle[] = [];
const sassBundles: SassBundleLayers[] = [];

if (brand?.data.color) {
const colorVariables: string[] = ["/* color variables from _brand.yml */"];
Expand All @@ -40,9 +51,9 @@ export async function brandSassFormatExtras(
);
}
// const colorEntries = Object.keys(brand.color);
const colorBundle: SassBundle = {
key: "brand-color",
dependency: "bootstrap",
const colorBundle: SassBundleLayers = {
key,
// dependency: "bootstrap",
quarto: {
defaults: colorVariables.join("\n"),
uses: "",
Expand All @@ -54,9 +65,37 @@ export async function brandSassFormatExtras(
sassBundles.push(colorBundle);
}

return {
html: {
[kSassBundles]: sassBundles,
},
};
return sassBundles;
}

export async function brandRevealSassBundleLayers(
_format: Format,
project: ProjectContext,
): Promise<SassBundleLayers[]> {
return brandBootstrapSassBundleLayers(project, "reveal-theme");
}

export async function brandSassFormatExtras(
_format: Format,
project: ProjectContext,
): Promise<FormatExtras> {
const htmlSassBundleLayers = await brandBootstrapSassBundleLayers(
project,
"brand",
);
const htmlSassBundles: SassBundle[] = htmlSassBundleLayers.map((layer) => {
return {
...layer,
dependency: "bootstrap",
};
});
if (htmlSassBundles.length === 0) {
return {};
} else {
return {
html: {
[kSassBundles]: htmlSassBundles,
},
};
}
}
10 changes: 9 additions & 1 deletion src/format/dashboard/format-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ import { projectIsWebsite } from "../../project/project-shared.ts";
import { processShinyComponents } from "./format-dashboard-shiny.ts";
import { processToolbars } from "./format-dashboard-toolbar.ts";
import { processDatatables } from "./format-dashboard-tables.ts";
import { assert } from "testing/asserts.ts";
import { brandBootstrapSassBundles } from "../../core/sass/brand.ts";

const kDashboardClz = "quarto-dashboard";

Expand Down Expand Up @@ -94,6 +96,7 @@ export function dashboardFormat() {
project?: ProjectContext,
quiet?: boolean,
) => {
assert(project);
if (baseHtmlFormat.formatExtras) {
// Read the dashboard metadata
const dashboard = await dashboardMeta(format);
Expand Down Expand Up @@ -156,12 +159,17 @@ export function dashboardFormat() {
scrolling: dashboard.scrolling,
};

extras.html[kSassBundles] = extras.html[kSassBundles] || [];
if (!isWebsiteProject) {
// If this is a website project, it will inject the scss for dashboards
extras.html[kSassBundles] = extras.html[kSassBundles] || [];
extras.html[kSassBundles].unshift(dashboardScssLayer());
}

// add _brand.yml sass bundle
extras.html[kSassBundles].push(
...await brandBootstrapSassBundles(project, "bootstrap"),
);

const scripts: DependencyHtmlFile[] = [];
const stylesheets: DependencyHtmlFile[] = [];

Expand Down
2 changes: 2 additions & 0 deletions src/format/html/format-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ import {
} from "./format-html-types.ts";
import { kQuartoHtmlDependency } from "./format-html-constants.ts";
import { registerWriterFormatHandler } from "../format-handlers.ts";
import { brandSassFormatExtras } from "../../core/sass/brand.ts";

export function htmlFormat(
figwidth: number,
Expand Down Expand Up @@ -171,6 +172,7 @@ export function htmlFormat(
project,
quiet,
),
await brandSassFormatExtras(format, project),
{ [kFilterParams]: htmlFilterParams },
);
},
Expand Down
10 changes: 9 additions & 1 deletion src/format/reveal/format-reveal-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import { titleSlideScss } from "./format-reveal-title.ts";
import { asCssFont, asCssNumber } from "../../core/css.ts";
import { cssHasDarkModeSentinel } from "../../core/pandoc/css.ts";
import { pandocNativeStr } from "../../core/pandoc/codegen.ts";
import { ProjectContext } from "../../project/types.ts";
import { brandRevealSassBundleLayers } from "../../core/sass/brand.ts";

export const kRevealLightThemes = [
"white",
Expand All @@ -63,6 +65,7 @@ export async function revealTheme(
input: string,
libDir: string,
temp: TempContext,
project: ProjectContext,
) {
// metadata override to return
const metadata: Metadata = {};
Expand Down Expand Up @@ -175,8 +178,13 @@ export async function revealTheme(
loadPaths,
};

const brandLayers: SassBundleLayers[] = await brandRevealSassBundleLayers(
format,
project,
);

// compile sass
const css = await compileSass([bundleLayers], temp);
const css = await compileSass([bundleLayers, ...brandLayers], temp);
copyTo(
css,
join(revealDestDir, "dist", "theme", "quarto.css"),
Expand Down
8 changes: 7 additions & 1 deletion src/format/reveal/format-reveal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,13 @@ export function revealjsFormat() {
}

// get theme info (including text highlighing mode)
const theme = await revealTheme(format, input, libDir, services.temp);
const theme = await revealTheme(
format,
input,
libDir,
services.temp,
project,
);

const revealPluginData = await revealPluginExtras(
input,
Expand Down
3 changes: 2 additions & 1 deletion src/resources/formats/revealjs/quarto.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ $body-color: #222 !default;
$text-muted: lighten($body-color, 30%) !default;

// link colors
$link-color: #2a76dd !default;
$primary: #2a76dd !default;
$link-color: $primary !default;
$link-color-hover: lighten($link-color, 10%) !default;

// selection colors
Expand Down
Loading