Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions guide/src/format/configuration/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, its 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.svg"
```

### Rust options
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -428,6 +431,7 @@ impl Default for BookConfig {
src: PathBuf::from("src"),
multilingual: false,
language: Some(String::from("en")),
logo: None,
}
}
}
Expand Down Expand Up @@ -761,6 +765,8 @@ mod tests {
multilingual: true,
src: PathBuf::from("source"),
language: Some(String::from("ja")),
// TODO: add a test logo

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)?

logo: None,
};
let build_should_be = BuildConfig {
build_dir: PathBuf::from("outputs"),
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,10 @@ fn make_data(
"description".to_owned(),
json!(config.book.description.clone().unwrap_or_default()),
);
data.insert(
"book_logo".to_owned(),
json!(config.book.logo.clone().unwrap_or_default()),
);
if theme.favicon_png.is_some() {
data.insert("favicon_png".to_owned(), json!("favicon.png"));
}
Expand Down
7 changes: 7 additions & 0 deletions src/theme/css/chrome.css
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ ul#searchresults span.teaser em {
right: 0;
padding: 10px 10px;
}
.sidebar .sidebar-scrollbox .sidebar-book-logo img {
Copy link

@sanmai-NL sanmai-NL Sep 5, 2021

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.

display: block;
margin-left: auto;
margin-right: auto;
width: 100%;
max-width: max-content;
}
.sidebar .sidebar-resize-handle {
position: absolute;
cursor: col-resize;
Expand Down
5 changes: 5 additions & 0 deletions src/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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="{{ path_to_root }}{{ book_logo }}">
</div>
{{/if}}
{{#toc}}{{/toc}}
</div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
Expand Down