summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/build.rs13
-rw-r--r--src/config.rs30
2 files changed, 29 insertions, 14 deletions
diff --git a/src/build.rs b/src/build.rs
index 1c12476..cf34e2f 100644
--- a/src/build.rs
+++ b/src/build.rs
@@ -14,12 +14,22 @@ const HTML_TEMPLATE: &str = include_str!("../res/template.html");
14 14
15pub fn do_build(config: &crate::config::Config) -> Result<()> { 15pub fn do_build(config: &crate::config::Config) -> Result<()> {
16 let tmpdir = tempfile::tempdir().wrap_err("Could not create temporary directory")?; 16 let tmpdir = tempfile::tempdir().wrap_err("Could not create temporary directory")?;
17 debug!("Created temporary directory at: '{}'", tmpdir.path().display()); 17 debug!(
18 "Created temporary directory at: '{}'",
19 tmpdir.path().display()
20 );
21
18 let template_path = tmpdir.path().join("template.html"); 22 let template_path = tmpdir.path().join("template.html");
19 trace!("Writing HTML template to: '{}'", template_path.display()); 23 trace!("Writing HTML template to: '{}'", template_path.display());
20 std::fs::write(&template_path, HTML_TEMPLATE) 24 std::fs::write(&template_path, HTML_TEMPLATE)
21 .wrap_err("Could not save HTML template in temporary directory")?; 25 .wrap_err("Could not save HTML template in temporary directory")?;
22 26
27 let defaults_path = tmpdir.path().join("defaults.yaml");
28 debug!("Generating file: '{}'", defaults_path.display());
29 let defaults =
30 std::fs::File::create(&defaults_path).wrap_err("Could not create defaults.yaml")?;
31 serde_json::to_writer(defaults, &config.pandoc).wrap_err("Could not create defaults.yaml")?;
32
23 let source_root = Path::new(&config.book.summary) 33 let source_root = Path::new(&config.book.summary)
24 .parent() 34 .parent()
25 .expect("Summary has no parent"); 35 .expect("Summary has no parent");
@@ -99,6 +109,7 @@ pub fn do_build(config: &crate::config::Config) -> Result<()> {
99 .set_output_format(pandoc::OutputFormat::Html5, vec![]) 109 .set_output_format(pandoc::OutputFormat::Html5, vec![])
100 .add_options(&[ 110 .add_options(&[
101 pandoc::PandocOption::Css(style_path.to_string()), 111 pandoc::PandocOption::Css(style_path.to_string()),
112 pandoc::PandocOption::Defaults(defaults_path.clone()),
102 pandoc::PandocOption::SectionDivs, 113 pandoc::PandocOption::SectionDivs,
103 pandoc::PandocOption::Standalone, 114 pandoc::PandocOption::Standalone,
104 pandoc::PandocOption::Template(template_path.clone()), 115 pandoc::PandocOption::Template(template_path.clone()),
diff --git a/src/config.rs b/src/config.rs
index 53922b0..9b95f9a 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,3 +1,5 @@
1use std::collections::HashMap;
2
1use log::debug; 3use log::debug;
2use serde::{Deserialize, Serialize}; 4use serde::{Deserialize, Serialize};
3 5
@@ -7,6 +9,21 @@ pub struct Config {
7 pub book: BookConfig, 9 pub book: BookConfig,
8 #[serde(default)] 10 #[serde(default)]
9 pub build: BuildConfig, 11 pub build: BuildConfig,
12 #[serde(default)]
13 pub pandoc: HashMap<String, serde_json::Value>,
14}
15
16impl Config {
17 pub fn new(config_file: &str) -> Result<Self, config::ConfigError> {
18 let mut s = config::Config::default();
19
20 debug!("Parsing config file: {}", config_file);
21 s.merge(config::File::with_name(config_file))?;
22 debug!("Parsing config from environment");
23 s.merge(config::Environment::with_prefix("PANDOC_DOCBOOK").separator("_"))?;
24
25 s.try_into()
26 }
10} 27}
11 28
12#[derive(Debug, Clone, Deserialize, Serialize)] 29#[derive(Debug, Clone, Deserialize, Serialize)]
@@ -44,16 +61,3 @@ impl Default for BuildConfig {
44fn default_build_dir() -> String { 61fn default_build_dir() -> String {
45 "pdbook".to_string() 62 "pdbook".to_string()
46} 63}
47
48impl Config {
49 pub fn new(config_file: &str) -> Result<Self, config::ConfigError> {
50 let mut s = config::Config::default();
51
52 debug!("Parsing config file: {}", config_file);
53 s.merge(config::File::with_name(config_file))?;
54 debug!("Parsing config from environment");
55 s.merge(config::Environment::with_prefix("PANDOC_DOCBOOK").separator("_"))?;
56
57 s.try_into()
58 }
59}