Skip to content

Commit f603379

Browse files
committed
[feature] brand - forward logo.small to favicon
1 parent 3aec7d3 commit f603379

File tree

20 files changed

+141
-1
lines changed

20 files changed

+141
-1
lines changed

news/changelog-1.7.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ All changes included in 1.7:
1717
## Website projects
1818

1919
- ([#11701](https://github.com/quarto-dev/quarto-cli/issues/11701)): Wrap HTML emitted by EJS templates in `{=html}` blocks to avoid memory blowup issues with Pandoc's parser.
20+
- ([#12134](https://github.com/quarto-dev/quarto-cli/issues/12134)): Forward `logo.small` images in `_brand.yml` files to a website `favicon`.
2021

2122
## Blog projects
2223

@@ -25,6 +26,7 @@ All changes included in 1.7:
2526
## Book projects
2627

2728
- ([#11520](https://github.com/quarto-dev/quarto-cli/issues/11520)): Book's cover image now escapes lightbox treatment, which was incorrectly applied to it when `lightbox: true` was set in the book's configuration.
29+
- ([#12134](https://github.com/quarto-dev/quarto-cli/issues/12134)): Forward `logo.small` images in `_brand.yml` files to the `favicon` of the book's website.
2830

2931
## `quarto check`
3032

src/core/brand/brand.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,11 @@ export class Brand {
283283
}
284284
}
285285
}
286+
287+
export const getFavicon = (brand: Brand): string | undefined => {
288+
const logoInfo = brand.getLogo("small");
289+
if (!logoInfo) {
290+
return undefined;
291+
}
292+
return logoInfo.light.path;
293+
};

src/project/types/book/book-config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ import {
125125
import { projectType } from "../project-types.ts";
126126
import { BookRenderItem, BookRenderItemType } from "./book-types.ts";
127127
import { isAbsoluteRef } from "../../../core/http.ts";
128+
import { getFavicon } from "../../../core/brand/brand.ts";
128129

129130
export async function bookProjectConfig(
130131
project: ProjectContext,
@@ -141,6 +142,12 @@ export async function bookProjectConfig(
141142
if (book) {
142143
site[kSiteTitle] = book[kSiteTitle];
143144
site[kSiteFavicon] = book[kSiteFavicon];
145+
if (!site[kSiteFavicon]) {
146+
const brand = await project.resolveBrand();
147+
if (brand) {
148+
site[kSiteFavicon] = getFavicon(brand);
149+
}
150+
}
144151
site[kSiteUrl] = book[kSiteUrl];
145152
site[kSitePath] = book[kSitePath];
146153
site[kSiteRepoUrl] = book[kSiteRepoUrl];

src/project/types/website/website.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import { kFieldCategories } from "./listing/website-listing-shared.ts";
9090
import { pandocNativeStr } from "../../../core/pandoc/codegen.ts";
9191
import { asArray } from "../../../core/array.ts";
9292
import { canonicalizeTitlePostprocessor } from "../../../format/html/format-html-title.ts";
93+
import { getFavicon } from "../../../core/brand/brand.ts";
9394

9495
export const kSiteTemplateDefault = "default";
9596
export const kSiteTemplateBlog = "blog";
@@ -178,7 +179,13 @@ export const websiteProjectType: ProjectType = {
178179
}
179180

180181
// dependency for favicon if we have one
181-
const favicon = websiteConfigString(kSiteFavicon, project.config);
182+
let favicon = websiteConfigString(kSiteFavicon, project.config);
183+
if (!favicon) {
184+
const brand = await project.resolveBrand();
185+
if (brand) {
186+
favicon = getFavicon(brand);
187+
}
188+
}
182189
if (favicon) {
183190
const offset = projectOffset(project, source);
184191
extras.html = extras.html || {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.quarto/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
logo:
2+
small: logos/small.png
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
project:
2+
type: book
3+
4+
book:
5+
title: "brand-icon-small-favicon-book"
6+
author: "Norah Jones"
7+
date: "2/21/2025"
8+
chapters:
9+
- index.qmd
10+
- intro.qmd
11+
- summary.qmd
12+
- references.qmd
13+
14+
bibliography: references.bib
15+
16+
format:
17+
html:
18+
theme:
19+
- cosmo
20+
- brand
21+
pdf:
22+
documentclass: scrreprt
23+
24+
25+
50 KB
Loading
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
_quarto:
3+
tests:
4+
html:
5+
ensureFileRegexMatches:
6+
- ['<link href="./logos/small.png" rel="icon" type="image/png">']
7+
- []
8+
---
9+
10+
# Preface {.unnumbered}
11+
12+
This is a Quarto book.
13+
14+
To learn more about Quarto books visit <https://quarto.org/docs/books>.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Introduction
2+
3+
This is a book created from markdown and executable code.
4+
5+
See @knuth84 for additional discussion of literate programming.

0 commit comments

Comments
 (0)