From 61c84131386baaacc1bfa5ddc85dcdf5fe5b2314 Mon Sep 17 00:00:00 2001 From: Gilles Rasigade Date: Fri, 1 May 2020 07:47:50 +0200 Subject: [PATCH 1/5] Allow to define own HTML attributes Create a `index.hbs` template file to render additional HTML attributes --- src/renderer/html_handlebars/hbs_renderer.rs | 3 + src/theme/head.hbs | 1 + src/theme/index.hbs | 552 ++++++++++--------- src/theme/mod.rs | 6 + 4 files changed, 299 insertions(+), 263 deletions(-) create mode 100644 src/theme/head.hbs diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 14012c12d4..cea3a9fdca 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -327,6 +327,9 @@ impl Renderer for HtmlHandlebars { debug!("Register the index handlebars template"); handlebars.register_template_string("index", String::from_utf8(theme.index.clone())?)?; + debug!("Register the head handlebars template"); + handlebars.register_partial("head", String::from_utf8(theme.head.clone())?)?; + debug!("Register the header handlebars template"); handlebars.register_partial("header", String::from_utf8(theme.header.clone())?)?; diff --git a/src/theme/head.hbs b/src/theme/head.hbs new file mode 100644 index 0000000000..cb1be1876c --- /dev/null +++ b/src/theme/head.hbs @@ -0,0 +1 @@ +{{!-- Put your head HTML text here --}} diff --git a/src/theme/index.hbs b/src/theme/index.hbs index 291e279659..9a0951a655 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -1,289 +1,315 @@ - - - - {{ title }} - {{#if is_print }} - - {{/if}} - - - - - - - - - - - - - - - - - - - - - - - - {{#each additional_css}} - - {{/each}} - - {{#if mathjax_support}} - - - {{/if}} - - - - - - - - - - - - - - + + + + {{ title }} + {{#if is_print }} + + {{/if}} + + + {{> head}} + + + + + + + + + + + + + + + + + + + + + + + + {{#each additional_css}} + + {{/each}} + + {{#if mathjax_support}} + + + {{/if}} + + + + + + + + + + + + + + + + + +
+ +
+ {{> header}} + +
- {{#if livereload}} - - - {{/if}} - - {{#if google_analytics}} - - - {{/if}} - - {{#if playpen_line_numbers}} - - {{/if}} - - {{#if playpen_copyable}} - - {{/if}} - - {{#if playpen_js}} - - - - - - {{/if}} - - {{#if search_js}} - - - - {{/if}} - - - - - - - {{#each additional_js}} - - {{/each}} - - {{#if is_print}} - {{#if mathjax_support}} - + {{/if}} + + {{#if google_analytics}} + + + {{/if}} + + {{#if playpen_line_numbers}} + + {{/if}} + + {{#if playpen_copyable}} + + {{/if}} + + {{#if playpen_js}} + + + + + + {{/if}} + + {{#if search_js}} + + + + {{/if}} + + + + + + + {{#each additional_js}} + + {{/each}} + + {{#if is_print}} + {{#if mathjax_support}} + - {{else}} - + {{else}} + - {{/if}} - {{/if}} + + {{/if}} + {{/if}} + + - diff --git a/src/theme/mod.rs b/src/theme/mod.rs index aab96db732..1172922ff8 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -12,6 +12,7 @@ use std::path::Path; use crate::errors::*; pub static INDEX: &[u8] = include_bytes!("index.hbs"); +pub static HEAD: &[u8] = include_bytes!("head.hbs"); pub static HEADER: &[u8] = include_bytes!("header.hbs"); pub static CHROME_CSS: &[u8] = include_bytes!("css/chrome.css"); pub static GENERAL_CSS: &[u8] = include_bytes!("css/general.css"); @@ -42,6 +43,7 @@ pub static FONT_AWESOME_OTF: &[u8] = include_bytes!("FontAwesome/fonts/FontAweso #[derive(Debug, PartialEq)] pub struct Theme { pub index: Vec, + pub head: Vec, pub header: Vec, pub chrome_css: Vec, pub general_css: Vec, @@ -72,6 +74,7 @@ impl Theme { { let files = vec![ (theme_dir.join("index.hbs"), &mut theme.index), + (theme_dir.join("head.hbs"), &mut theme.head), (theme_dir.join("header.hbs"), &mut theme.header), (theme_dir.join("book.js"), &mut theme.js), (theme_dir.join("css/chrome.css"), &mut theme.chrome_css), @@ -114,6 +117,7 @@ impl Default for Theme { fn default() -> Theme { Theme { index: INDEX.to_owned(), + head: HEAD.to_owned(), header: HEADER.to_owned(), chrome_css: CHROME_CSS.to_owned(), general_css: GENERAL_CSS.to_owned(), @@ -168,6 +172,7 @@ mod tests { fn theme_dir_overrides_defaults() { let files = [ "index.hbs", + "head.hbs", "header.hbs", "favicon.png", "css/chrome.css", @@ -194,6 +199,7 @@ mod tests { let empty = Theme { index: Vec::new(), + head: Vec::new(), header: Vec::new(), chrome_css: Vec::new(), general_css: Vec::new(), From f7e349d37f53d7a1479fafde1e8e68ae00bae37d Mon Sep 17 00:00:00 2001 From: Gilles Rasigade Date: Sun, 10 May 2020 09:31:30 +0200 Subject: [PATCH 2/5] Add `head.hbs` template documentation --- book-example/src/format/theme/README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/book-example/src/format/theme/README.md b/book-example/src/format/theme/README.md index f1fd303a8a..92eaa7f58b 100644 --- a/book-example/src/format/theme/README.md +++ b/book-example/src/format/theme/README.md @@ -11,16 +11,17 @@ and now that file will be used instead of the default file. Here are the files you can override: -- ***index.hbs*** is the handlebars template. -- ***book.css*** is the style used in the output. If you want to change the +- **_index.hbs_** is the handlebars template. +- **_head.hbs_** is appended to the HTML `` section +- **_book.css_** is the style used in the output. If you want to change the design of your book, this is probably the file you want to modify. Sometimes in conjunction with `index.hbs` when you want to radically change the layout. -- ***book.js*** is mostly used to add client side functionality, like hiding / +- **_book.js_** is mostly used to add client side functionality, like hiding / un-hiding the sidebar, changing the theme, ... -- ***highlight.js*** is the JavaScript that is used to highlight code snippets, - you should not need to modify this. -- ***highlight.css*** is the theme used for the code highlighting -- ***favicon.png*** the favicon that will be used +- **_highlight.js_** is the JavaScript that is used to highlight code snippets, + you should not need to modify this. +- **_highlight.css_** is the theme used for the code highlighting +- **_favicon.png_** the favicon that will be used Generally, when you want to tweak the theme, you don't need to override all the files. If you only need changes in the stylesheet, there is no point in From 1731779a8d3be9d3074be4e464345e48a64cb375 Mon Sep 17 00:00:00 2001 From: Gilles Rasigade Date: Sun, 10 May 2020 09:35:27 +0200 Subject: [PATCH 3/5] Add `header.hbs` template documentation --- book-example/src/format/theme/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book-example/src/format/theme/README.md b/book-example/src/format/theme/README.md index 92eaa7f58b..9e4d11195e 100644 --- a/book-example/src/format/theme/README.md +++ b/book-example/src/format/theme/README.md @@ -13,6 +13,7 @@ Here are the files you can override: - **_index.hbs_** is the handlebars template. - **_head.hbs_** is appended to the HTML `` section +- **_header.hbs_** content is appended on top of every book page - **_book.css_** is the style used in the output. If you want to change the design of your book, this is probably the file you want to modify. Sometimes in conjunction with `index.hbs` when you want to radically change the layout. From c2d58158da2594bc2d6701eb60b25075631262be Mon Sep 17 00:00:00 2001 From: Gilles Rasigade Date: Sun, 10 May 2020 09:39:13 +0200 Subject: [PATCH 4/5] Revert HTML auto-formatting --- src/theme/index.hbs | 555 +++++++++++++++++++++----------------------- 1 file changed, 266 insertions(+), 289 deletions(-) diff --git a/src/theme/index.hbs b/src/theme/index.hbs index 9a0951a655..e27f6aa354 100644 --- a/src/theme/index.hbs +++ b/src/theme/index.hbs @@ -1,315 +1,292 @@ - - - - - {{ title }} - {{#if is_print }} - - {{/if}} - - - {{> head}} - - - - - - - - - - - - - - - - - - - - - - - - {{#each additional_css}} - - {{/each}} - - {{#if mathjax_support}} - - - {{/if}} - - - - - - - - + {{/if}} + + + + + + + + + + + + + - - - - - - - - - -
- -
- {{> header}} - -