diff options
Diffstat (limited to 'src/generator/mod.rs')
-rw-r--r-- | src/generator/mod.rs | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/src/generator/mod.rs b/src/generator/mod.rs index b4e1c94..3f62779 100644 --- a/src/generator/mod.rs +++ b/src/generator/mod.rs | |||
@@ -2,11 +2,8 @@ pub(crate) mod config; | |||
2 | mod pandoc; | 2 | mod pandoc; |
3 | 3 | ||
4 | use self::config::Config; | 4 | use self::config::Config; |
5 | //use crate::entities::{ | ||
6 | // Description, DynEntity, EntitiesManager, EntitiesManagerComponents, Usr, | ||
7 | //}; | ||
8 | use self::pandoc::into_pandoc; | 5 | use self::pandoc::into_pandoc; |
9 | use crate::types::Entity; | 6 | use crate::types::*; |
10 | 7 | ||
11 | use anyhow::{ensure, Context, Result}; | 8 | use anyhow::{ensure, Context, Result}; |
12 | use rayon::Scope; | 9 | use rayon::Scope; |
@@ -18,7 +15,11 @@ use std::path::Path; | |||
18 | 15 | ||
19 | const DEFAULT_CSS: &[u8] = include_bytes!("../../res/style.css"); | 16 | const DEFAULT_CSS: &[u8] = include_bytes!("../../res/style.css"); |
20 | 17 | ||
21 | pub(crate) fn generate(base_dir: &Path, entities: BTreeMap<String, Entity>, config: &Config) -> Result<()> { | 18 | pub(crate) fn generate( |
19 | base_dir: &Path, | ||
20 | entities: BTreeMap<EntityId, Entity>, | ||
21 | config: &Config, | ||
22 | ) -> Result<()> { | ||
22 | let md_output_dir = base_dir.join("markdown"); | 23 | let md_output_dir = base_dir.join("markdown"); |
23 | let html_output_dir = base_dir.join("html"); | 24 | let html_output_dir = base_dir.join("html"); |
24 | 25 | ||
@@ -54,7 +55,7 @@ pub(crate) fn generate(base_dir: &Path, entities: BTreeMap<String, Entity>, conf | |||
54 | } | 55 | } |
55 | 56 | ||
56 | fn generate_recursively<'a>( | 57 | fn generate_recursively<'a>( |
57 | id: String, | 58 | id: EntityId, |
58 | entity: Entity, | 59 | entity: Entity, |
59 | pool: &Scope<'a>, | 60 | pool: &Scope<'a>, |
60 | md_output_dir: &'a Path, | 61 | md_output_dir: &'a Path, |
@@ -63,7 +64,7 @@ fn generate_recursively<'a>( | |||
63 | config: &'a Config, | 64 | config: &'a Config, |
64 | ) { | 65 | ) { |
65 | pool.spawn(move |pool| { | 66 | pool.spawn(move |pool| { |
66 | trace!("Trying to generate {}", id); | 67 | trace!("Trying to generate {}", id.0); |
67 | 68 | ||
68 | let leftovers = generate_single( | 69 | let leftovers = generate_single( |
69 | &id, | 70 | &id, |
@@ -90,18 +91,18 @@ fn generate_recursively<'a>( | |||
90 | } | 91 | } |
91 | 92 | ||
92 | fn generate_single( | 93 | fn generate_single( |
93 | id: &str, | 94 | id: &EntityId, |
94 | entity: Entity, | 95 | entity: Entity, |
95 | md_output_dir: impl AsRef<Path>, | 96 | md_output_dir: impl AsRef<Path>, |
96 | html_output_dir: impl AsRef<Path>, | 97 | html_output_dir: impl AsRef<Path>, |
97 | css_path: impl AsRef<Path>, | 98 | css_path: impl AsRef<Path>, |
98 | config: &Config | 99 | config: &Config, |
99 | ) -> Result<BTreeMap<String, Entity>> { | 100 | ) -> Result<BTreeMap<EntityId, Entity>> { |
100 | use std::io::prelude::*; | 101 | use std::io::prelude::*; |
101 | use std::process::{Command, Stdio}; | 102 | use std::process::{Command, Stdio}; |
102 | 103 | ||
103 | let md_output_file = md_output_dir.as_ref().join(id); | 104 | let md_output_file = md_output_dir.as_ref().join(&id.0); |
104 | let html_output_file = html_output_dir.as_ref().join(id); | 105 | let html_output_file = html_output_dir.as_ref().join(&id.0); |
105 | 106 | ||
106 | let mut command = Command::new("pandoc"); | 107 | let mut command = Command::new("pandoc"); |
107 | 108 | ||
@@ -111,7 +112,10 @@ fn generate_single( | |||
111 | .stderr(Stdio::piped()) | 112 | .stderr(Stdio::piped()) |
112 | .args(&[ | 113 | .args(&[ |
113 | "--from=json", | 114 | "--from=json", |
114 | "--to=markdown", | 115 | // standalone keeps the sent metadat |
116 | "--standalone", | ||
117 | "--to", | ||
118 | &config.from, | ||
115 | "--output", | 119 | "--output", |
116 | md_output_file | 120 | md_output_file |
117 | .to_str() | 121 | .to_str() |
@@ -165,8 +169,10 @@ fn generate_single( | |||
165 | .stdout(Stdio::piped()) | 169 | .stdout(Stdio::piped()) |
166 | .stderr(Stdio::piped()) | 170 | .stderr(Stdio::piped()) |
167 | .args(&[ | 171 | .args(&[ |
168 | "--from=markdown-raw_tex", | 172 | "--from", |
169 | "--to=html", | 173 | &config.from, |
174 | "--to", | ||
175 | &config.to, | ||
170 | "--css", | 176 | "--css", |
171 | css_path | 177 | css_path |
172 | .as_ref() | 178 | .as_ref() |
@@ -183,6 +189,10 @@ fn generate_single( | |||
183 | .context("Entity name is not valid UTF-8")?, | 189 | .context("Entity name is not valid UTF-8")?, |
184 | ]); | 190 | ]); |
185 | 191 | ||
192 | for filter in &config.pandoc_filters { | ||
193 | command.args(&["--filter", filter]); | ||
194 | } | ||
195 | |||
186 | let command_str = format!("{:?}", command); | 196 | let command_str = format!("{:?}", command); |
187 | debug!("Launching command: {}", command_str); | 197 | debug!("Launching command: {}", command_str); |
188 | 198 | ||
@@ -190,6 +200,8 @@ fn generate_single( | |||
190 | .output() | 200 | .output() |
191 | .context("Failed to execute Pandoc command")?; | 201 | .context("Failed to execute Pandoc command")?; |
192 | 202 | ||
203 | std::io::stderr().lock().write_all(&output.stderr)?; | ||
204 | |||
193 | ensure!( | 205 | ensure!( |
194 | output.status.success(), | 206 | output.status.success(), |
195 | CommandError { | 207 | CommandError { |