-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a logo to the navigation bar of the HTML rendered book #1584
base: master
Are you sure you want to change the base?
Changes from 3 commits
a5ec0da
b391d93
bf5b900
7a6f7c3
ff42463
db0499d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,15 +46,19 @@ This is general information about your book. | |
`src` directly under the root folder. But this is configurable with the `src` | ||
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. | ||
|
||
**book.toml** | ||
|
||
```toml | ||
[book] | ||
title = "Example book" | ||
authors = ["John Doe", "Jane Doe"] | ||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
``` | ||
|
||
### Rust options | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -417,6 +417,9 @@ pub struct BookConfig { | |
pub multilingual: bool, | ||
/// The main language of the book. | ||
pub language: Option<String>, | ||
/// A logo to be displayed on top of the navigation bar. The path is relative to the source | ||
/// path | ||
pub logo: Option<PathBuf>, | ||
} | ||
|
||
impl Default for BookConfig { | ||
|
@@ -428,6 +431,7 @@ impl Default for BookConfig { | |
src: PathBuf::from("src"), | ||
multilingual: false, | ||
language: Some(String::from("en")), | ||
logo: None, | ||
} | ||
} | ||
} | ||
|
@@ -761,6 +765,8 @@ mod tests { | |
multilingual: true, | ||
src: PathBuf::from("source"), | ||
language: Some(String::from("ja")), | ||
// TODO: add a test logo | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this comment be clarified further (in-source)? |
||
logo: None, | ||
}; | ||
let build_should_be = BuildConfig { | ||
build_dir: PathBuf::from("outputs"), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,6 +344,13 @@ ul#searchresults span.teaser em { | |
right: 0; | ||
padding: 10px 10px; | ||
} | ||
.sidebar .sidebar-scrollbox .sidebar-book-logo img { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please sort the property names below. |
||
display: block; | ||
margin-left: auto; | ||
margin-right: auto; | ||
width: 100%; | ||
max-width: max-content; | ||
} | ||
.sidebar .sidebar-resize-handle { | ||
position: absolute; | ||
cursor: col-resize; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,11 @@ | |
|
||
<nav id="sidebar" class="sidebar" aria-label="Table of contents"> | ||
<div class="sidebar-scrollbox"> | ||
{{#if book_logo }} | ||
<div class="sidebar-book-logo"> | ||
<img src="{{ book_logo }}"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add an |
||
</div> | ||
{{/if}} | ||
{{#toc}}{{/toc}} | ||
</div> | ||
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 forimg
to state which image formats are supported.