Skip to content

Commit 523c644

Browse files
dark logo: sidebar
1 parent 331fbf0 commit 523c644

File tree

28 files changed

+220
-43
lines changed

28 files changed

+220
-43
lines changed

src/core/brand/brand.ts

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ import {
2121
BrandTypographySingle,
2222
BrandTypographyUnified,
2323
BrandUnified,
24+
LogoLightDarkSpecifier,
25+
LogoOptions,
26+
NormalizedLogoLightDarkSpecifier,
2427
Zod,
2528
} from "../../resources/types/zod/schema-types.ts";
2629
import { InternalError } from "../lib/error.ts";
2730

2831
import { join, relative } from "../../deno_ral/path.ts";
2932
import { warnOnce } from "../log.ts";
3033
import { isCssColorName } from "../css/color-names.ts";
34+
import { assert } from "testing/asserts";
3135

3236
type ProcessedBrandData = {
3337
color: Record<string, string>;
@@ -238,7 +242,6 @@ export class Brand {
238242

239243
getLogoResource(name: string): BrandLogoExplicitResource {
240244
const entry = this.data.logo?.images?.[name];
241-
console.log(name, this.data.logo?.images);
242245
if (!entry) {
243246
return { path: name };
244247
}
@@ -279,6 +282,63 @@ export const getFavicon = (brand: Brand): string | undefined => {
279282
return logoInfo.path;
280283
};
281284

285+
export async function normalizeLogoSpec(
286+
spec: LogoLightDarkSpecifier,
287+
brand: LightDarkBrand | undefined,
288+
): Promise<NormalizedLogoLightDarkSpecifier> {
289+
const resolveLogo = (mode: "light" | "dark", name: string) => {
290+
const logo = brand?.[mode]?.processedData?.logo;
291+
return logo &&
292+
((Zod.BrandNamedLogo.options.includes(name as BrandNamedLogo) &&
293+
logo[name as BrandNamedLogo]) || logo.images[name]);
294+
};
295+
const resolveLogoOptions = (
296+
mode: "light" | "dark",
297+
logo: LogoOptions,
298+
): LogoOptions => {
299+
const logo2 = resolveLogo(mode, logo.path);
300+
if (logo2) {
301+
const { path: _, ...rest } = logo;
302+
return {
303+
...logo2,
304+
...rest,
305+
};
306+
}
307+
return logo;
308+
};
309+
if (typeof spec === "string") {
310+
return {
311+
light: resolveLogo("light", spec) || { path: spec },
312+
dark: resolveLogo("light", spec) || { path: spec },
313+
};
314+
}
315+
if ("path" in spec) {
316+
return {
317+
light: resolveLogoOptions("light", spec),
318+
dark: resolveLogoOptions("dark", spec),
319+
};
320+
}
321+
let light, dark;
322+
if (spec.light) {
323+
if (typeof spec.light === "string") {
324+
light = resolveLogo("light", spec.light) || { path: spec.light };
325+
} else {
326+
light = resolveLogoOptions("light", spec.light);
327+
}
328+
}
329+
if (spec.dark) {
330+
if (typeof spec.dark === "string") {
331+
dark = resolveLogo("dark", spec.dark) || { path: spec.dark };
332+
} else {
333+
dark = resolveLogoOptions("dark", spec.dark);
334+
}
335+
}
336+
return {
337+
light,
338+
dark,
339+
};
340+
}
341+
282342
function splitColorLightDark(
283343
bcld: BrandColorLightDark,
284344
): LightDarkColor {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,11 +1017,10 @@ async function sidebarEjsData(project: ProjectContext, sidebar: Sidebar) {
10171017
sidebar.title = await sidebarTitle(sidebar, project) as string | undefined;
10181018
// sidebar logo has been normalized
10191019
const sidebarLogo = sidebar.logo as NormalizedLogoLightDarkSpecifier;
1020-
console.log("sidebar.logo", sidebarLogo);
10211020
if (sidebarLogo.light) {
10221021
sidebarLogo.light.path = resolveLogo(sidebarLogo.light.path)!;
10231022
}
1024-
if (sidebarLogo?.dark) {
1023+
if (sidebarLogo.dark) {
10251024
sidebarLogo.dark.path = resolveLogo(sidebarLogo.dark.path)!;
10261025
}
10271026
const searchOpts = await searchOptions(project);

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

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ import {
2222
Sidebar,
2323
SidebarItem,
2424
} from "../../types.ts";
25-
import {
26-
LogoLightDarkSpecifier,
27-
NormalizedLogoLightDarkSpecifier,
28-
} from "../../../resources/types/schema-types.ts";
25+
import {} from "../../../resources/types/schema-types.ts";
2926
import {
3027
kAnnouncement,
3128
kBodyFooter,
@@ -49,7 +46,8 @@ import { Format, FormatExtras } from "../../../config/types.ts";
4946
import { kPageTitle, kTitle, kTitlePrefix } from "../../../config/constants.ts";
5047
import { md5HashAsync } from "../../../core/hash.ts";
5148
export { type NavigationFooter } from "../../types.ts";
52-
import { assert } from "testing/asserts";
49+
import { projectResolveBrand } from "../../project-shared.ts";
50+
import { normalizeLogoSpec } from "../../../core/brand/brand.ts";
5351

5452
export interface Navigation {
5553
navbar?: Navbar;
@@ -113,38 +111,6 @@ export function computePageTitle(
113111
}
114112
}
115113

116-
export function normalizeLogoSpec(
117-
spec: LogoLightDarkSpecifier,
118-
): NormalizedLogoLightDarkSpecifier {
119-
if (typeof spec === "string") {
120-
return {
121-
light: { path: spec },
122-
dark: { path: spec },
123-
};
124-
}
125-
if ("light" in spec || "dark" in spec) {
126-
return {
127-
light: typeof spec.light === "string"
128-
? {
129-
path: spec.light,
130-
}
131-
: spec.light,
132-
dark: typeof spec.dark === "string"
133-
? {
134-
path: spec.dark,
135-
}
136-
: spec.dark,
137-
};
138-
}
139-
if ("path" in spec) {
140-
return {
141-
light: spec,
142-
dark: spec,
143-
};
144-
}
145-
assert(false);
146-
}
147-
148114
export function inputFileHref(href: string) {
149115
const [hrefDir, hrefStem] = dirAndStem(href);
150116
const htmlHref = "/" + join(hrefDir, `${hrefStem}.html`);
@@ -186,7 +152,9 @@ export async function websiteNavigationConfig(project: ProjectContext) {
186152
}
187153

188154
if (sidebars[0].logo) {
189-
sidebars[0].logo = normalizeLogoSpec(sidebars[0].logo);
155+
// note no document-level customization of brand logo #11309
156+
const brand = await projectResolveBrand(project);
157+
sidebars[0].logo = await normalizeLogoSpec(sidebars[0].logo, brand);
190158
}
191159

192160
// convert contents: auto into items
@@ -236,7 +204,6 @@ export async function websiteNavigationConfig(project: ProjectContext) {
236204
if (logo) {
237205
navbar.logo = logo.path; // TODO: This needs smarts to work on light+dark themes
238206
navbar["logo-alt"] = logo.alt;
239-
console.log("navbar logo", logo);
240207
}
241208
}
242209

src/resources/schema/definitions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2601,7 +2601,7 @@
26012601

26022602
- id: logo-options
26032603
object:
2604-
closed: true # e.g. to allow typst location, padding, padding-*, width
2604+
closed: false # e.g. to allow typst location, padding, padding-*, width
26052605
properties:
26062606
path:
26072607
schema: path
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.quarto/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
color:
2+
background:
3+
light: "#fff"
4+
dark: "#111"
5+
foreground:
6+
light: "#111"
7+
dark: "#fff"
8+
logo:
9+
medium:
10+
light: sun-face.png
11+
dark: moon-face.png
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
project:
2+
type: website
3+
theme:
4+
light: brand
5+
dark: [brand, dark-fixups.scss]
6+
website:
7+
sidebar:
8+
style: "docked"
9+
search: true
10+
contents:
11+
- index.qmd
12+
- conclusion.qmd
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
title: conclusion
3+
---
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*-- scss:rules --*/
2+
3+
nav.sidebar.sidebar-navigation:not(.rollup) {
4+
background-color: #282B30;
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: intro
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
-
8+
- 'img[class*="light-content"][src="./sun-face.png"][alt=""]'
9+
- 'img[class*="dark-content"][src="./moon-face.png"][alt=""]'
10+
- []
11+
---

0 commit comments

Comments
 (0)