Merge pull request #1169 from rossmacarthur/ft/no-print
Add config option to disable print html, css, and icon
This commit is contained in:
commit
d1f5ecc103
|
@ -187,6 +187,9 @@ The following configuration options are available:
|
||||||
- **additional-js:** If you need to add some behaviour to your book without
|
- **additional-js:** If you need to add some behaviour to your book without
|
||||||
removing the current behaviour, you can specify a set of JavaScript files that
|
removing the current behaviour, you can specify a set of JavaScript files that
|
||||||
will be loaded alongside the default one.
|
will be loaded alongside the default one.
|
||||||
|
- **print:** A subtable for configuration print settings. mdBook by default adds
|
||||||
|
support for printing out the book as a single page. This is accessed using the
|
||||||
|
print icon on the top right of the book.
|
||||||
- **no-section-label:** mdBook by defaults adds section label in table of
|
- **no-section-label:** mdBook by defaults adds section label in table of
|
||||||
contents column. For example, "1.", "2.1". Set this option to true to disable
|
contents column. For example, "1.", "2.1". Set this option to true to disable
|
||||||
those labels. Defaults to `false`.
|
those labels. Defaults to `false`.
|
||||||
|
@ -217,6 +220,11 @@ The following configuration options are available:
|
||||||
|
|
||||||
[custom domain]: https://docs.github.com/en/github/working-with-github-pages/managing-a-custom-domain-for-your-github-pages-site
|
[custom domain]: https://docs.github.com/en/github/working-with-github-pages/managing-a-custom-domain-for-your-github-pages-site
|
||||||
|
|
||||||
|
Available configuration options for the `[output.html.print]` table:
|
||||||
|
|
||||||
|
- **enable:** Enable print support. When `false`, all print support will not be
|
||||||
|
rendered. Defaults to `true`.
|
||||||
|
|
||||||
Available configuration options for the `[output.html.fold]` table:
|
Available configuration options for the `[output.html.fold]` table:
|
||||||
|
|
||||||
- **enable:** Enable section-folding. When off, all folds are open.
|
- **enable:** Enable section-folding. When off, all folds are open.
|
||||||
|
@ -282,6 +290,9 @@ site-url = "/example-book/"
|
||||||
cname = "myproject.rs"
|
cname = "myproject.rs"
|
||||||
input-404 = "not-found.md"
|
input-404 = "not-found.md"
|
||||||
|
|
||||||
|
[output.html.print]
|
||||||
|
enable = true
|
||||||
|
|
||||||
[output.html.fold]
|
[output.html.fold]
|
||||||
enable = false
|
enable = false
|
||||||
level = 0
|
level = 0
|
||||||
|
|
|
@ -109,10 +109,9 @@ impl BookBuilder {
|
||||||
fn copy_across_theme(&self) -> Result<()> {
|
fn copy_across_theme(&self) -> Result<()> {
|
||||||
debug!("Copying theme");
|
debug!("Copying theme");
|
||||||
|
|
||||||
let themedir = self
|
let html_config = self.config.html_config().unwrap_or_default();
|
||||||
.config
|
let themedir = html_config
|
||||||
.html_config()
|
.theme
|
||||||
.and_then(|html| html.theme)
|
|
||||||
.unwrap_or_else(|| self.config.book.src.join("theme"));
|
.unwrap_or_else(|| self.config.book.src.join("theme"));
|
||||||
let themedir = self.root.join(themedir);
|
let themedir = self.root.join(themedir);
|
||||||
|
|
||||||
|
@ -136,8 +135,10 @@ impl BookBuilder {
|
||||||
let mut chrome_css = File::create(cssdir.join("chrome.css"))?;
|
let mut chrome_css = File::create(cssdir.join("chrome.css"))?;
|
||||||
chrome_css.write_all(theme::CHROME_CSS)?;
|
chrome_css.write_all(theme::CHROME_CSS)?;
|
||||||
|
|
||||||
let mut print_css = File::create(cssdir.join("print.css"))?;
|
if html_config.print.enable {
|
||||||
print_css.write_all(theme::PRINT_CSS)?;
|
let mut print_css = File::create(cssdir.join("print.css"))?;
|
||||||
|
print_css.write_all(theme::PRINT_CSS)?;
|
||||||
|
}
|
||||||
|
|
||||||
let mut variables_css = File::create(cssdir.join("variables.css"))?;
|
let mut variables_css = File::create(cssdir.join("variables.css"))?;
|
||||||
variables_css.write_all(theme::VARIABLES_CSS)?;
|
variables_css.write_all(theme::VARIABLES_CSS)?;
|
||||||
|
|
|
@ -495,6 +495,8 @@ pub struct HtmlConfig {
|
||||||
/// Playground settings.
|
/// Playground settings.
|
||||||
#[serde(alias = "playpen")]
|
#[serde(alias = "playpen")]
|
||||||
pub playground: Playground,
|
pub playground: Playground,
|
||||||
|
/// Print settings.
|
||||||
|
pub print: Print,
|
||||||
/// Don't render section labels.
|
/// Don't render section labels.
|
||||||
pub no_section_label: bool,
|
pub no_section_label: bool,
|
||||||
/// Search settings. If `None`, the default will be used.
|
/// Search settings. If `None`, the default will be used.
|
||||||
|
@ -542,6 +544,7 @@ impl Default for HtmlConfig {
|
||||||
additional_js: Vec::new(),
|
additional_js: Vec::new(),
|
||||||
fold: Fold::default(),
|
fold: Fold::default(),
|
||||||
playground: Playground::default(),
|
playground: Playground::default(),
|
||||||
|
print: Print::default(),
|
||||||
no_section_label: false,
|
no_section_label: false,
|
||||||
search: None,
|
search: None,
|
||||||
git_repository_url: None,
|
git_repository_url: None,
|
||||||
|
@ -566,6 +569,20 @@ impl HtmlConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Configuration for how to render the print icon, print.html, and print.css.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
|
pub struct Print {
|
||||||
|
/// Whether print support is enabled.
|
||||||
|
pub enable: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Print {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self { enable: true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Configuration for how to fold chapters of sidebar.
|
/// Configuration for how to fold chapters of sidebar.
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(default, rename_all = "kebab-case")]
|
#[serde(default, rename_all = "kebab-case")]
|
||||||
|
|
|
@ -194,7 +194,9 @@ impl HtmlHandlebars {
|
||||||
write_file(destination, "book.js", &theme.js)?;
|
write_file(destination, "book.js", &theme.js)?;
|
||||||
write_file(destination, "css/general.css", &theme.general_css)?;
|
write_file(destination, "css/general.css", &theme.general_css)?;
|
||||||
write_file(destination, "css/chrome.css", &theme.chrome_css)?;
|
write_file(destination, "css/chrome.css", &theme.chrome_css)?;
|
||||||
write_file(destination, "css/print.css", &theme.print_css)?;
|
if html_config.print.enable {
|
||||||
|
write_file(destination, "css/print.css", &theme.print_css)?;
|
||||||
|
}
|
||||||
write_file(destination, "css/variables.css", &theme.variables_css)?;
|
write_file(destination, "css/variables.css", &theme.variables_css)?;
|
||||||
if let Some(contents) = &theme.favicon_png {
|
if let Some(contents) = &theme.favicon_png {
|
||||||
write_file(destination, "favicon.png", &contents)?;
|
write_file(destination, "favicon.png", &contents)?;
|
||||||
|
@ -516,14 +518,16 @@ impl Renderer for HtmlHandlebars {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the handlebars template with the data
|
// Render the handlebars template with the data
|
||||||
debug!("Render template");
|
if html_config.print.enable {
|
||||||
let rendered = handlebars.render("index", &data)?;
|
debug!("Render template");
|
||||||
|
let rendered = handlebars.render("index", &data)?;
|
||||||
|
|
||||||
let rendered =
|
let rendered =
|
||||||
self.post_process(rendered, &html_config.playground, ctx.config.rust.edition);
|
self.post_process(rendered, &html_config.playground, ctx.config.rust.edition);
|
||||||
|
|
||||||
utils::fs::write_file(&destination, "print.html", rendered.as_bytes())?;
|
utils::fs::write_file(&destination, "print.html", rendered.as_bytes())?;
|
||||||
debug!("Creating print.html ✓");
|
debug!("Creating print.html ✓");
|
||||||
|
}
|
||||||
|
|
||||||
debug!("Copy static files");
|
debug!("Copy static files");
|
||||||
self.copy_static_files(&destination, &theme, &html_config)
|
self.copy_static_files(&destination, &theme, &html_config)
|
||||||
|
@ -644,6 +648,7 @@ fn make_data(
|
||||||
data.insert("playground_copyable".to_owned(), json!(true));
|
data.insert("playground_copyable".to_owned(), json!(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.insert("print_enable".to_owned(), json!(!html_config.print.enable));
|
||||||
data.insert("fold_enable".to_owned(), json!((html_config.fold.enable)));
|
data.insert("fold_enable".to_owned(), json!((html_config.fold.enable)));
|
||||||
data.insert("fold_level".to_owned(), json!((html_config.fold.level)));
|
data.insert("fold_level".to_owned(), json!((html_config.fold.level)));
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,9 @@
|
||||||
<link rel="stylesheet" href="{{ path_to_root }}css/variables.css">
|
<link rel="stylesheet" href="{{ path_to_root }}css/variables.css">
|
||||||
<link rel="stylesheet" href="{{ path_to_root }}css/general.css">
|
<link rel="stylesheet" href="{{ path_to_root }}css/general.css">
|
||||||
<link rel="stylesheet" href="{{ path_to_root }}css/chrome.css">
|
<link rel="stylesheet" href="{{ path_to_root }}css/chrome.css">
|
||||||
|
{{#if print_enable}}
|
||||||
<link rel="stylesheet" href="{{ path_to_root }}css/print.css" media="print">
|
<link rel="stylesheet" href="{{ path_to_root }}css/print.css" media="print">
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<!-- Fonts -->
|
<!-- Fonts -->
|
||||||
<link rel="stylesheet" href="{{ path_to_root }}FontAwesome/css/font-awesome.css">
|
<link rel="stylesheet" href="{{ path_to_root }}FontAwesome/css/font-awesome.css">
|
||||||
|
@ -136,9 +138,11 @@
|
||||||
<h1 class="menu-title">{{ book_title }}</h1>
|
<h1 class="menu-title">{{ book_title }}</h1>
|
||||||
|
|
||||||
<div class="right-buttons">
|
<div class="right-buttons">
|
||||||
|
{{#if print_enable}}
|
||||||
<a href="{{ path_to_root }}print.html" title="Print this book" aria-label="Print this book">
|
<a href="{{ path_to_root }}print.html" title="Print this book" aria-label="Print this book">
|
||||||
<i id="print-button" class="fa fa-print"></i>
|
<i id="print-button" class="fa fa-print"></i>
|
||||||
</a>
|
</a>
|
||||||
|
{{/if}}
|
||||||
{{#if git_repository_url}}
|
{{#if git_repository_url}}
|
||||||
<a href="{{git_repository_url}}" title="Git repository" aria-label="Git repository">
|
<a href="{{git_repository_url}}" title="Git repository" aria-label="Git repository">
|
||||||
<i id="git-repository-button" class="fa {{git_repository_icon}}"></i>
|
<i id="git-repository-button" class="fa {{git_repository_icon}}"></i>
|
||||||
|
|
Loading…
Reference in New Issue