Skip to content

Add a logo to the navigation bar of the HTML rendered book - #1584

Closed
scattenlaeufer wants to merge 6 commits into
rust-lang:mainfrom
scattenlaeufer:logo
Closed

scattenlaeufer wants to merge 6 commits into
rust-lang:mainfrom
scattenlaeufer:logo

Conversation

@scattenlaeufer

Copy link
Copy Markdown

I added the option to add an image as logo to the navigation bar by adding a configuration parameter to the book table of the book.toml. This resolves #877

I also thought about adding the option of a project logo to the bottom of the navigation sidebar, but wanted to wait for feedback to this first edit before adding more code.

key in the configuration file.
- **language:** The main language of the book, which is used as a language attribute `<html lang="en">` for example.
- **logo:** Path to a logo to shown at the top of the navigation bar. If this
is given as a relative path, it's base directory is the source directory.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
is given as a relative path, it's base directory is the source directory.
is given as a relative path, its base directory is the source directory.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which content types do we support for the logo?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have to further look into that, but it seems like pixel as well as vector graphics are supported.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, img supports SVG. You can simply reference the HTML spec for img to state which image formats are supported.

description = "The example book covers examples."
src = "my-src" # the source files will be found in `root/my-src` instead of `root/src`
language = "en"
logo = "static/logo.png"

@sanmai-NL sanmai-NL Sep 5, 2021

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the SVG format is supported, I prefer to use an SVG example.
That way, we don't have to add a sample binary to the Git index, and save space, in addition to the general advantages of SVG logos (crispness, etc.).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quick test showed that SVG seems to be supported. Is there a logo I could use as a sample? If not, I'd just reuse the favicon.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think MdBook doesn't have a product logo yet. Using the favicon as sample seems fine, though .ico files may not be rendered correctly as source image for img-elements sometimes.

Comment thread src/config.rs
multilingual: true,
src: PathBuf::from("source"),
language: Some(String::from("ja")),
// TODO: add a test logo

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this comment be clarified further (in-source)?

Comment thread src/theme/css/chrome.css
right: 0;
padding: 10px 10px;
}
.sidebar .sidebar-scrollbox .sidebar-book-logo img {

@sanmai-NL sanmai-NL Sep 5, 2021

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sort the property names below.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Comment thread src/theme/index.hbs Outdated
<div class="sidebar-scrollbox">
{{#if book_logo }}
<div class="sidebar-book-logo">
<img src="{{ book_logo }}">

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an alt attribute for e.g., accessibility. Although its content could be generated, because of language differences and because of the principle of least surprise, I propose to add a config field containing the alt title.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@ehuss

ehuss commented Sep 28, 2021

Copy link
Copy Markdown
Contributor

I'm wondering, would it be possible to make this part of the SUMMARY instead of making it a configuration option? That is, before the chapter list, allow an image to be specified. It could be constrained to only specific events for now (like images and maybe HTML?). That would alleviate the issues with needing to specify alt text, image width/height, and other details. I'm a little concerned about trying to specify things in TOML since specifying details like those can be difficult.

@montyly

montyly commented Feb 24, 2023

Copy link
Copy Markdown

Hi. Is there any update on this PR? It's a neat addition

@Nelson-numerical-software

Copy link
Copy Markdown

Is there any chance to have this feature?

ch1bo added a commit to cardano-scaling/cardano-blueprint that referenced this pull request Mar 18, 2025
This is achieved by adding one line to the index.hbs. This is not ideal
as we fix the whole theme by it and we should make sure to keep it up to
date with upstream (using `mdbook init --theme`).

Modifications to index.hbs are indicated by <!-- MODIFICATION START -->
and <!-- MODIFICATION END -->.

There is this relevant issue upstream: rust-lang/mdBook#1584
ch1bo added a commit to cardano-scaling/cardano-blueprint that referenced this pull request Mar 18, 2025
This is achieved by adding one line to the index.hbs. This is not ideal
as we fix the whole theme by it and we should make sure to keep it up to
date with upstream (using `mdbook init --theme`).

Modifications to index.hbs are indicated by <!-- MODIFICATION START -->
and <!-- MODIFICATION END -->.

There is this relevant issue upstream: rust-lang/mdBook#1584
ch1bo added a commit to cardano-scaling/cardano-blueprint that referenced this pull request Mar 26, 2025
This is achieved by adding one line to the index.hbs. This is not ideal
as we fix the whole theme by it and we should make sure to keep it up to
date with upstream (using `mdbook init --theme`).

Modifications to index.hbs are indicated by <!-- MODIFICATION START -->
and <!-- MODIFICATION END -->.

There is this relevant issue upstream: rust-lang/mdBook#1584
ch1bo added a commit to cardano-scaling/cardano-blueprint that referenced this pull request Mar 26, 2025
This is achieved by adding one line to the index.hbs. This is not ideal
as we fix the whole theme by it and we should make sure to keep it up to
date with upstream (using `mdbook init --theme`).

Modifications to index.hbs are indicated by <!-- MODIFICATION START -->
and <!-- MODIFICATION END -->.

There is this relevant issue upstream: rust-lang/mdBook#1584
@ewof

ewof commented Apr 2, 2025

Copy link
Copy Markdown

4 years ago......... pls merge this

@rustbot

rustbot commented Apr 30, 2025

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (possibly #2681) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot rustbot added the S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. label Apr 30, 2025
@GuillaumeGomez

Copy link
Copy Markdown
Member

Sorry for the delay, we now have an mdbook team. I think this feature is a good idea. Nominating it for team discussion.

@GuillaumeGomez GuillaumeGomez added the A-needs-discussion This issue/PR needs to be discussed by the team label Aug 28, 2026
@GuillaumeGomez

Copy link
Copy Markdown
Member

cc @rust-lang/mdbook

@GuillaumeGomez

Copy link
Copy Markdown
Member

Superseded by #3214. @Chocorean cherry-picked your commit so authorship attribution will be kept. Thanks for working on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-needs-discussion This issue/PR needs to be discussed by the team S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Display project/book logo in table-of-contents sidebar

9 participants