Skip to content

Add before_body_end handlebars partial #1531

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

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions guide/src/format/theme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Here are the files you can override:
- **_index.hbs_** is the handlebars template.
- **_head.hbs_** is appended to the HTML `<head>` section.
- **_header.hbs_** content is appended on top of every book page.
- **_before_body_end.hbs_** content is appended before body closing tag.
- **_css/_** contains the CSS files for styling the book.
- **_css/chrome.css_** is for UI elements.
- **_css/general.css_** is the base styles.
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ impl Renderer for HtmlHandlebars {
debug!("Register the header handlebars template");
handlebars.register_partial("header", String::from_utf8(theme.header.clone())?)?;

debug!("Register the before_body_end handlebars template");
handlebars.register_partial("before_body_end", String::from_utf8(theme.before_body_end.clone())?)?;

debug!("Register handlebars helpers");
self.register_hbs_helpers(&mut handlebars, &html_config);

Expand Down
1 change: 1 addition & 0 deletions src/theme/before_body_end.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{!-- Put your before_body_end HTML text here --}}
2 changes: 2 additions & 0 deletions src/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,7 @@
{{/if}}
{{/if}}

{{> before_body_end}}

</body>
</html>
6 changes: 6 additions & 0 deletions src/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub static INDEX: &[u8] = include_bytes!("index.hbs");
pub static HEAD: &[u8] = include_bytes!("head.hbs");
pub static REDIRECT: &[u8] = include_bytes!("redirect.hbs");
pub static HEADER: &[u8] = include_bytes!("header.hbs");
pub static BEFORE_BODY_END: &[u8] = include_bytes!("before_body_end.hbs");
pub static CHROME_CSS: &[u8] = include_bytes!("css/chrome.css");
pub static GENERAL_CSS: &[u8] = include_bytes!("css/general.css");
pub static PRINT_CSS: &[u8] = include_bytes!("css/print.css");
Expand Down Expand Up @@ -50,6 +51,7 @@ pub struct Theme {
pub head: Vec<u8>,
pub redirect: Vec<u8>,
pub header: Vec<u8>,
pub before_body_end: Vec<u8>,
pub chrome_css: Vec<u8>,
pub general_css: Vec<u8>,
pub print_css: Vec<u8>,
Expand Down Expand Up @@ -83,6 +85,7 @@ impl Theme {
(theme_dir.join("head.hbs"), &mut theme.head),
(theme_dir.join("redirect.hbs"), &mut theme.redirect),
(theme_dir.join("header.hbs"), &mut theme.header),
(theme_dir.join("before_body_end.hbs"), &mut theme.before_body_end),
(theme_dir.join("book.js"), &mut theme.js),
(theme_dir.join("css/chrome.css"), &mut theme.chrome_css),
(theme_dir.join("css/general.css"), &mut theme.general_css),
Expand Down Expand Up @@ -149,6 +152,7 @@ impl Default for Theme {
head: HEAD.to_owned(),
redirect: REDIRECT.to_owned(),
header: HEADER.to_owned(),
before_body_end: BEFORE_BODY_END.to_owned(),
chrome_css: CHROME_CSS.to_owned(),
general_css: GENERAL_CSS.to_owned(),
print_css: PRINT_CSS.to_owned(),
Expand Down Expand Up @@ -206,6 +210,7 @@ mod tests {
"head.hbs",
"redirect.hbs",
"header.hbs",
"before_body_end.hbs",
"favicon.png",
"favicon.svg",
"css/chrome.css",
Expand Down Expand Up @@ -236,6 +241,7 @@ mod tests {
head: Vec::new(),
redirect: Vec::new(),
header: Vec::new(),
before_body_end: Vec::new(),
chrome_css: Vec::new(),
general_css: Vec::new(),
print_css: Vec::new(),
Expand Down