Skip to content

Commit 331fbf0

Browse files
wip: dark logo for sidebar
1 parent 61bc604 commit 331fbf0

File tree

6 files changed

+115
-24
lines changed

6 files changed

+115
-24
lines changed

src/core/brand/brand.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ export class Brand {
238238

239239
getLogoResource(name: string): BrandLogoExplicitResource {
240240
const entry = this.data.logo?.images?.[name];
241+
console.log(name, this.data.logo?.images);
241242
if (!entry) {
242243
return { path: name };
243244
}

src/project/types.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { ExecutionEngine, ExecutionTarget } from "../execute/types.ts";
1414
import { InspectedMdCell } from "../inspect/inspect-types.ts";
1515
import { NotebookContext } from "../render/notebook/notebook-types.ts";
1616
import {
17-
BrandLogoExplicitResource,
17+
LogoLightDarkSpecifier,
1818
NavigationItem as NavItem,
1919
NavigationItemObject,
2020
NavigationItemObject as SidebarTool,
@@ -150,11 +150,6 @@ export const kLogoHref = "logo-href";
150150

151151
export const kSidebarMenus = "sidebar-menus";
152152

153-
export interface LightDarkLogo {
154-
light?: BrandLogoExplicitResource;
155-
dark?: BrandLogoExplicitResource;
156-
}
157-
158153
export interface Navbar {
159154
title?: string | false;
160155
logo?: string;
@@ -203,7 +198,8 @@ export interface Sidebar {
203198
id?: string;
204199
title?: string;
205200
subtitle?: string;
206-
logo?: LightDarkLogo;
201+
logo?: LogoLightDarkSpecifier;
202+
[kLogoAlt]?: string;
207203
[kLogoHref]?: string;
208204
alignment?: "left" | "right" | "center";
209205
align?: "left" | "right" | "center"; // This is here only because older versions of Quarto used to use it even though it wasn't documented

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ import {
7676
SidebarItem,
7777
SidebarTool,
7878
} from "../../types.ts";
79+
import {
80+
NormalizedLogoLightDarkSpecifier,
81+
} from "../../../resources/types/schema-types.ts";
7982
import {
8083
normalizeSidebarItem,
8184
resolveHrefAttribute,
@@ -1012,12 +1015,14 @@ async function sidebarEjsData(project: ProjectContext, sidebar: Sidebar) {
10121015

10131016
// ensure title and search are present
10141017
sidebar.title = await sidebarTitle(sidebar, project) as string | undefined;
1015-
console.log("sidebar.logo", sidebar.logo);
1016-
if (sidebar.logo?.light) {
1017-
sidebar.logo.light.path = resolveLogo(sidebar.logo.light.path)!;
1018+
// sidebar logo has been normalized
1019+
const sidebarLogo = sidebar.logo as NormalizedLogoLightDarkSpecifier;
1020+
console.log("sidebar.logo", sidebarLogo);
1021+
if (sidebarLogo.light) {
1022+
sidebarLogo.light.path = resolveLogo(sidebarLogo.light.path)!;
10181023
}
1019-
if (sidebar.logo?.dark) {
1020-
sidebar.logo.dark.path = resolveLogo(sidebar.logo.dark.path)!;
1024+
if (sidebarLogo?.dark) {
1025+
sidebarLogo.dark.path = resolveLogo(sidebarLogo.dark.path)!;
10211026
}
10221027
const searchOpts = await searchOptions(project);
10231028
sidebar.search = sidebar.search !== undefined

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

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import {
2222
Sidebar,
2323
SidebarItem,
2424
} from "../../types.ts";
25+
import {
26+
LogoLightDarkSpecifier,
27+
NormalizedLogoLightDarkSpecifier,
28+
} from "../../../resources/types/schema-types.ts";
2529
import {
2630
kAnnouncement,
2731
kBodyFooter,
@@ -45,6 +49,7 @@ import { Format, FormatExtras } from "../../../config/types.ts";
4549
import { kPageTitle, kTitle, kTitlePrefix } from "../../../config/constants.ts";
4650
import { md5HashAsync } from "../../../core/hash.ts";
4751
export { type NavigationFooter } from "../../types.ts";
52+
import { assert } from "testing/asserts";
4853

4954
export interface Navigation {
5055
navbar?: Navbar;
@@ -108,6 +113,38 @@ export function computePageTitle(
108113
}
109114
}
110115

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+
111148
export function inputFileHref(href: string) {
112149
const [hrefDir, hrefStem] = dirAndStem(href);
113150
const htmlHref = "/" + join(hrefDir, `${hrefStem}.html`);
@@ -148,15 +185,8 @@ export async function websiteNavigationConfig(project: ProjectContext) {
148185
sidebars[0].tools = [];
149186
}
150187

151-
if (sidebars[0].logo) { // normalize to LightDarkLogo
152-
if (typeof (sidebars[0].logo) === "string") {
153-
sidebars[0].logo = {
154-
light: {
155-
path: sidebars[0].logo,
156-
alt: (sidebars[0] as unknown as { "logo-alt": string })["logo-alt"],
157-
},
158-
};
159-
}
188+
if (sidebars[0].logo) {
189+
sidebars[0].logo = normalizeLogoSpec(sidebars[0].logo);
160190
}
161191

162192
// convert contents: auto into items

src/resources/schema/definitions.yml

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,8 +1019,8 @@
10191019
- boolean
10201020
description: "The sidebar title. Uses the project title if none is specified."
10211021
logo:
1022-
path:
1023-
description: "Path to a logo image that will be displayed in the sidebar."
1022+
ref: logo-light-dark-specifier
1023+
description: "Speciffication of image that will be displayed in the sidebar."
10241024
logo-alt:
10251025
string:
10261026
description: "Alternate text for the logo image."
@@ -2599,6 +2599,65 @@
25992599
description: Names of customizeable logos
26002600
enum: [small, medium, large]
26012601

2602+
- id: logo-options
2603+
object:
2604+
closed: true # e.g. to allow typst location, padding, padding-*, width
2605+
properties:
2606+
path:
2607+
schema: path
2608+
description: >
2609+
Path or brand.yml logo resource name.
2610+
alt:
2611+
schema: string
2612+
description: >
2613+
Alternative text for the logo, used for accessibility.
2614+
required: [path]
2615+
2616+
- id: logo-specifier
2617+
anyOf:
2618+
- string
2619+
- schema:
2620+
ref: logo-options
2621+
2622+
- id: logo-light-dark-specifier
2623+
description: >
2624+
Any of the ways a logo can be specified: string, object, or light/dark object of
2625+
string or object
2626+
anyOf:
2627+
- ref: logo-specifier
2628+
- object:
2629+
closed: true
2630+
properties:
2631+
light:
2632+
schema:
2633+
ref: logo-specifier
2634+
description: >
2635+
Specification of a light logo
2636+
dark:
2637+
schema:
2638+
ref: logo-specifier
2639+
description: >
2640+
Specification of a dark logo
2641+
2642+
# normalized version of logo-light-dark-specifier
2643+
- id: normalized-logo-light-dark-specifier
2644+
description: >
2645+
Any of the ways a logo can be specified: string, object, or light/dark object of
2646+
string or object
2647+
object:
2648+
closed: true
2649+
properties:
2650+
light:
2651+
schema:
2652+
ref: logo-options
2653+
description: >
2654+
Options for a light logo
2655+
dark:
2656+
schema:
2657+
ref: logo-options
2658+
description: >
2659+
Options for a dark logo
2660+
26022661
- id: brand-color-value
26032662
schema: string
26042663

src/resources/schema/document-reveal-content.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
schema:
55
anyOf:
66
- string
7-
- object # typst: location, padding, padding-*, width, source
7+
- object
88
description: "Logo image (placed in bottom right corner of slides)"
99

1010
- name: footer

0 commit comments

Comments
 (0)