Skip to content

Commit

Permalink
Merge pull request #12135 from quarto-dev/feature/brand-icon-small-fa…
Browse files Browse the repository at this point in the history
…vicon

[feature] brand - forward logo.small to favicon
  • Loading branch information
cscheid authored Feb 21, 2025
2 parents 3aec7d3 + f603379 commit b45b78c
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 1 deletion.
2 changes: 2 additions & 0 deletions news/changelog-1.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ All changes included in 1.7:
## Website projects

- ([#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.
- ([#12134](https://github.com/quarto-dev/quarto-cli/issues/12134)): Forward `logo.small` images in `_brand.yml` files to a website `favicon`.

## Blog projects

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

- ([#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.
- ([#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.

## `quarto check`

Expand Down
8 changes: 8 additions & 0 deletions src/core/brand/brand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,11 @@ export class Brand {
}
}
}

export const getFavicon = (brand: Brand): string | undefined => {
const logoInfo = brand.getLogo("small");
if (!logoInfo) {
return undefined;
}
return logoInfo.light.path;
};
7 changes: 7 additions & 0 deletions src/project/types/book/book-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import {
import { projectType } from "../project-types.ts";
import { BookRenderItem, BookRenderItemType } from "./book-types.ts";
import { isAbsoluteRef } from "../../../core/http.ts";
import { getFavicon } from "../../../core/brand/brand.ts";

export async function bookProjectConfig(
project: ProjectContext,
Expand All @@ -141,6 +142,12 @@ export async function bookProjectConfig(
if (book) {
site[kSiteTitle] = book[kSiteTitle];
site[kSiteFavicon] = book[kSiteFavicon];
if (!site[kSiteFavicon]) {
const brand = await project.resolveBrand();
if (brand) {
site[kSiteFavicon] = getFavicon(brand);
}
}
site[kSiteUrl] = book[kSiteUrl];
site[kSitePath] = book[kSitePath];
site[kSiteRepoUrl] = book[kSiteRepoUrl];
Expand Down
9 changes: 8 additions & 1 deletion src/project/types/website/website.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import { kFieldCategories } from "./listing/website-listing-shared.ts";
import { pandocNativeStr } from "../../../core/pandoc/codegen.ts";
import { asArray } from "../../../core/array.ts";
import { canonicalizeTitlePostprocessor } from "../../../format/html/format-html-title.ts";
import { getFavicon } from "../../../core/brand/brand.ts";

export const kSiteTemplateDefault = "default";
export const kSiteTemplateBlog = "blog";
Expand Down Expand Up @@ -178,7 +179,13 @@ export const websiteProjectType: ProjectType = {
}

// dependency for favicon if we have one
const favicon = websiteConfigString(kSiteFavicon, project.config);
let favicon = websiteConfigString(kSiteFavicon, project.config);
if (!favicon) {
const brand = await project.resolveBrand();
if (brand) {
favicon = getFavicon(brand);
}
}
if (favicon) {
const offset = projectOffset(project, source);
extras.html = extras.html || {};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.quarto/
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
logo:
small: logos/small.png
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
project:
type: book

book:
title: "brand-icon-small-favicon-book"
author: "Norah Jones"
date: "2/21/2025"
chapters:
- index.qmd
- intro.qmd
- summary.qmd
- references.qmd

bibliography: references.bib

format:
html:
theme:
- cosmo
- brand
pdf:
documentclass: scrreprt



Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
_quarto:
tests:
html:
ensureFileRegexMatches:
- ['<link href="./logos/small.png" rel="icon" type="image/png">']
- []
---

# Preface {.unnumbered}

This is a Quarto book.

To learn more about Quarto books visit <https://quarto.org/docs/books>.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Introduction

This is a book created from markdown and executable code.

See @knuth84 for additional discussion of literate programming.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@article{knuth84,
author = {Knuth, Donald E.},
title = {Literate Programming},
year = {1984},
issue_date = {May 1984},
publisher = {Oxford University Press, Inc.},
address = {USA},
volume = {27},
number = {2},
issn = {0010-4620},
url = {https://doi.org/10.1093/comjnl/27.2.97},
doi = {10.1093/comjnl/27.2.97},
journal = {Comput. J.},
month = may,
pages = {97–111},
numpages = {15}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# References {.unnumbered}

::: {#refs}
:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Summary

In summary, this book has no content whatsoever.
1 change: 1 addition & 0 deletions tests/docs/smoke-all/brand/logo/website-favicon/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.quarto/
2 changes: 2 additions & 0 deletions tests/docs/smoke-all/brand/logo/website-favicon/_brand.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
logo:
small: logos/small.png
21 changes: 21 additions & 0 deletions tests/docs/smoke-all/brand/logo/website-favicon/_quarto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
project:
type: website

website:
title: "test-brand-favicon"
navbar:
left:
- href: index.qmd
text: Home
- about.qmd

format:
html:
theme:
- cosmo
- brand
css: styles.css
toc: true



5 changes: 5 additions & 0 deletions tests/docs/smoke-all/brand/logo/website-favicon/about.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "About"
---

About this site
13 changes: 13 additions & 0 deletions tests/docs/smoke-all/brand/logo/website-favicon/index.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: "test-brand-favicon"
_quarto:
tests:
html:
ensureFileRegexMatches:
- ['<link href="./logos/small.png" rel="icon" type="image/png">']
- []
---

This is a Quarto website.

To learn more about Quarto websites visit <https://quarto.org/docs/websites>.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/docs/smoke-all/brand/logo/website-favicon/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* css styles */

0 comments on commit b45b78c

Please sign in to comment.