Skip to content

Commit 0d2e0a4

Browse files
WIP: dark logo: dashboards
not working yet, checkpoint for weekend & CI!
1 parent 05b8e6a commit 0d2e0a4

File tree

7 files changed

+76
-44
lines changed

7 files changed

+76
-44
lines changed

src/core/brand/brand.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,22 @@ export async function normalizeLogoSpec(
339339
};
340340
}
341341

342+
export function findLogo(
343+
brand: LightDarkBrand,
344+
mode: "light" | "dark",
345+
order: BrandNamedLogo[],
346+
): LogoOptions | undefined {
347+
if (brand[mode]) {
348+
for (const size of order) {
349+
const logo = brand[mode].processedData.logo[size];
350+
if (logo) {
351+
return logo;
352+
}
353+
}
354+
}
355+
return undefined;
356+
}
357+
342358
function splitColorLightDark(
343359
bcld: BrandColorLightDark,
344360
): LightDarkColor {

src/format/dashboard/format-dashboard.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
kFilterParams,
1414
kIncludeAfterBody,
1515
kIpynbShellInteractivity,
16+
kLogo,
1617
kPlotlyConnected,
1718
kTemplate,
1819
kTheme,
@@ -32,7 +33,7 @@ import { mergeConfigs } from "../../core/config.ts";
3233
import { Document, Element } from "../../core/deno-dom.ts";
3334
import { InternalError } from "../../core/lib/error.ts";
3435
import { formatResourcePath } from "../../core/resources.ts";
35-
import { ProjectContext } from "../../project/types.ts";
36+
import { kLogoAlt, ProjectContext } from "../../project/types.ts";
3637
import { registerWriterFormatHandler } from "../format-handlers.ts";
3738
import { kPageLayout, kPageLayoutCustom } from "../html/format-html-shared.ts";
3839
import { htmlFormat } from "../html/format-html.ts";
@@ -64,6 +65,7 @@ import { processToolbars } from "./format-dashboard-toolbar.ts";
6465
import { processDatatables } from "./format-dashboard-tables.ts";
6566
import { assert } from "testing/asserts";
6667
import { brandBootstrapSassBundles } from "../../core/sass/brand.ts";
68+
import { findLogo, normalizeLogoSpec } from "../../core/brand/brand.ts";
6769

6870
const kDashboardClz = "quarto-dashboard";
6971

@@ -119,6 +121,19 @@ export function dashboardFormat() {
119121
}
120122
}
121123

124+
const brand = await project.resolveBrand(input);
125+
if (format.metadata[kLogo]) {
126+
format.metadata[kLogo] = await normalizeLogoSpec(
127+
brand,
128+
format.metadata[kLogo],
129+
);
130+
console.log("logo", format.metadata[kLogo]);
131+
} else if (brand) {
132+
const light = findLogo(brand, "light", ["small", "medium", "large"]);
133+
const dark = findLogo(brand, "dark", ["small", "medium", "large"]);
134+
format.metadata[kLogo] = { light, dark };
135+
}
136+
122137
const extras: FormatExtras = await baseHtmlFormat.formatExtras(
123138
input,
124139
markdown,

src/project/types/website/website-navigation.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ async function navbarEjsData(
12491249
? searchOpts.type
12501250
: false,
12511251
background: navbar.background || "primary",
1252-
logo: navbar.logo,
1252+
logo: ld.cloneDeep(navbar.logo),
12531253
[kLogoAlt]: navbar[kLogoAlt],
12541254
[kLogoHref]: navbar[kLogoHref],
12551255
collapse,
@@ -1259,9 +1259,8 @@ async function navbarEjsData(
12591259
pinned: navbar.pinned !== undefined ? !!navbar.pinned : false,
12601260
};
12611261
if (data.logo) {
1262-
console.log("navbar logo", navbar.logo);
12631262
// navbar logo has been normalized
1264-
const navbarLogo = navbar.logo as NormalizedLogoLightDarkSpecifier;
1263+
const navbarLogo = data.logo as NormalizedLogoLightDarkSpecifier;
12651264
if (navbarLogo.light) {
12661265
navbarLogo.light.path = resolveLogo(navbarLogo.light.path)!;
12671266
}

src/project/types/website/website-shared.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import { Format, FormatExtras } from "../../../config/types.ts";
4747
import { kPageTitle, kTitle, kTitlePrefix } from "../../../config/constants.ts";
4848
import { md5HashAsync } from "../../../core/hash.ts";
4949
export { type NavigationFooter } from "../../types.ts";
50-
import { projectResolveBrand } from "../../project-shared.ts";
5150
import { normalizeLogoSpec } from "../../../core/brand/brand.ts";
5251

5352
export interface Navigation {
@@ -137,7 +136,7 @@ export async function websiteNavigationConfig(project: ProjectContext) {
137136
}
138137

139138
// note no document-level customization of brand logo #11309
140-
const brand = await projectResolveBrand(project);
139+
const brand = await project.resolveBrand();
141140
navbar.logo = await normalizeLogoSpec(brand, logo);
142141
}
143142
// read sidebar
@@ -191,7 +190,7 @@ export async function websiteNavigationConfig(project: ProjectContext) {
191190
// }
192191
}
193192
// note no document-level customization of brand logo #11309
194-
const brand = await projectResolveBrand(project);
193+
const brand = await project.resolveBrand();
195194
sidebars[0].logo = await normalizeLogoSpec(brand, logo);
196195
}
197196

src/resources/filters/quarto-post/dashboard.lua

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -737,40 +737,41 @@ function render_dashboard()
737737
return doc
738738
end
739739
end
740-
}, {
741-
-- todo: dark mode
742-
Meta = function(meta)
743-
local logo = meta.logo
744-
local resolved
745-
if logo then
746-
if pandoc.utils.type(logo) == 'Inlines' then
747-
resolved = _quarto.modules.brand.get_logo('light', logo[1].text)
748-
elseif type(logo) == 'table' then
749-
local brandLogo = _quarto.modules.brand.get_logo('light', logo.path[1].text)
750-
if brandLogo then
751-
resolved = {
752-
path = brandLogo.path,
753-
alt = logo.alt or brandLogo.alt
754-
}
755-
else
756-
resolved = {
757-
path = logo.path,
758-
alt = logo.alt
759-
}
760-
end
761-
end
762-
else
763-
resolved = _quarto.modules.brand.get_logo('light', 'small')
764-
or _quarto.modules.brand.get_logo('light', 'medium')
765-
or _quarto.modules.brand.get_logo('light', 'large')
766-
end
767-
if resolved then
768-
meta.logo = resolved.path
769-
meta['logo-alt'] = resolved.alt
770-
end
771-
772-
return meta
773-
end
774740
}
741+
-- , {
742+
-- -- todo: dark mode
743+
-- Meta = function(meta)
744+
-- local logo = meta.logo
745+
-- local resolved
746+
-- if logo then
747+
-- if pandoc.utils.type(logo) == 'Inlines' then
748+
-- resolved = _quarto.modules.brand.get_logo('light', logo[1].text)
749+
-- elseif type(logo) == 'table' then
750+
-- local brandLogo = _quarto.modules.brand.get_logo('light', logo.path[1].text)
751+
-- if brandLogo then
752+
-- resolved = {
753+
-- path = brandLogo.path,
754+
-- alt = logo.alt or brandLogo.alt
755+
-- }
756+
-- else
757+
-- resolved = {
758+
-- path = logo.path,
759+
-- alt = logo.alt
760+
-- }
761+
-- end
762+
-- end
763+
-- else
764+
-- resolved = _quarto.modules.brand.get_logo('light', 'small')
765+
-- or _quarto.modules.brand.get_logo('light', 'medium')
766+
-- or _quarto.modules.brand.get_logo('light', 'large')
767+
-- end
768+
-- if resolved then
769+
-- meta.logo = resolved.path
770+
-- meta['logo-alt'] = resolved.alt
771+
-- end
772+
773+
-- return meta
774+
-- end
775+
-- }
775776
}
776777
end

src/resources/formats/dashboard/_nav-container.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
<div class="navbar-brand-container">
3-
$if(logo)$ <a href="#"><img src="$logo$" alt="$logo-alt$" class="navbar-logo d-inline-block"></a>$endif$
3+
$if(logo.light)$ <a href="#"><img src="$logo.light.path$" alt="$logo.light.alt$" class="navbar-logo light-content d-inline-block"></a>$endif$
4+
$if(logo.dark)$ <a href="#"><img src="$logo.dark.path$" alt="$logo.dark.alt$" class="navbar-logo dark-content d-inline-block"></a>$endif$
45
<div class="navbar-title">
56
$if(title)$<div class="navbar-title-text"><a href="#">$title$</a></div>$endif$
67
$if(subtitle)$<div class="navbar-subtitle">$subtitle$</div>$endif$

src/resources/schema/document-dashboard.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
- name: logo
22
tags:
33
formats: [dashboard]
4-
schema: path
5-
description: "Logo image (placed on the left side of the navigation bar)"
4+
schema:
5+
ref: logo-light-dark-specifier
6+
description: "Logo image(s) (placed on the left side of the navigation bar)"
67

78
- name: orientation
89
tags:

0 commit comments

Comments
 (0)