Skip to content

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

Open
Chocorean wants to merge 19 commits into
rust-lang:mainfrom
Chocorean:dev_logo
Open

Add a logo to the navigation bar of the HTML rendered book#3214
Chocorean wants to merge 19 commits into
rust-lang:mainfrom
Chocorean:dev_logo

Conversation

@Chocorean

Copy link
Copy Markdown
Contributor

Supersedes #1584, fixes #877

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.


I have not addressed the comments (I have just rebased the original commits on top of main and fixed the failing tests, preserving the original author's contribution):

  • logo = "static/logo.png"

An SVG would be prefered; maybe mdbook-html/front-end/images/favicon.svg could be a good candidate

  • // TODO: add a test logo

Also there is no test at all at the moment.

  • Please sort the property names below.

Done during rebase

  • 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.

This has not been addressed further ; a simple default value could be alt="{{ book_title }}"

@GuillaumeGomez

Copy link
Copy Markdown
Member

So it's still waiting for you to fix the review comments, right?

@Chocorean

Chocorean commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Yes, although it does not look great right now, I will try to add it the the scrollbox of the sidebar

Any suggestion regarding position/size? maybe ~30/40% of the sidebar width, centered?
I took inspiration from rustdoc
image

And I will add some tests

@Chocorean

Copy link
Copy Markdown
Contributor Author

I think I am good feature-wise, I'll write some tests next. I am not familiar with goml at all, but I will try to take care of that soon

Comment thread guide/src/images/logo.svg

@Chocorean Chocorean Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a copy of crates/mdbook-html/front-end/images/favicon.svg

Should I replace it with a symlink instead to avoid dups?

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes please.

@Chocorean

Copy link
Copy Markdown
Contributor Author

So if I understand correctly, goml is used here to simulate user input? In that case I assume I should only need to write tests under tests/testsuite, am I correct?

@GuillaumeGomez

Copy link
Copy Markdown
Member

It's used for GUI tests more globally. It allows you to query HTML states. It's easier to read than comparing plain HTML.

@Chocorean

Copy link
Copy Markdown
Contributor Author

@GuillaumeGomez I believe it is ready for review

Another thing that I am not sure about is, if the logo does not exist, the book will still build without a warning

@GuillaumeGomez

Copy link
Copy Markdown
Member

If it's a local file, we should definitely fail the build.

Comment thread crates/mdbook-html/front-end/templates/toc.js.hbs Outdated
Comment thread tests/gui/sidebar-logo.goml Outdated
Comment thread tests/gui/sidebar-logo.goml
Comment thread guide/src/format/configuration/general.md Outdated
@Chocorean

Copy link
Copy Markdown
Contributor Author

@GuillaumeGomez I have addressed your comments, and added a check command to the Config struct, which will crash the process if the logo file does not exist.

check is called after the config is loaded and updated by the envvars

@GuillaumeGomez

Copy link
Copy Markdown
Member

One question I just stumbled upon: is the logo image copied to the generated book? Because if not, it should (and it should be tested of course :3).

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

Labels

S-waiting-on-review Status: waiting on a review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants