diff --git a/README.md b/README.md index 874c4ff..7773b03 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,16 @@ All configuration is done via the `md-docs.config.yaml` file. Values: ```yaml -{ - String input # Path to the input folder - String output # Path to the output folder +String input # Path to the input folder +String output # Path to the output folder +String template # Path to the template file +String? extension = "html" # File extension of the output files - headings: { - String? h1 # Classes to add to h1 elements - String? h2 # Classes to add to h2 elements - String? h3 # Classes to add to h3 elements - String? h4 # Classes to add to h4 elements - String? h5 # Classes to add to h5 elements - } +headings: { + String? h1 # Classes to add to h1 elements + String? h2 # Classes to add to h2 elements + String? h3 # Classes to add to h3 elements + String? h4 # Classes to add to h4 elements + String? h5 # Classes to add to h5 elements } ``` diff --git a/src/config/mod.rs b/src/config/mod.rs index 13b3ede..6d1ad88 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -11,6 +11,7 @@ pub struct Config { pub input: String, pub output: String, pub template: String, + pub extension: String, pub headings: Headings, } @@ -48,6 +49,11 @@ pub fn parse(yaml_str: &String) -> Result { } }; + let file_extension = match config_yaml.get(ystr!("extension")) { + Some(Yaml::String(input)) => input.clone(), + _ => String::from("html"), + }; + let input_folder = match config_yaml.get(ystr!("input")) { Some(Yaml::String(input)) => input, Some(_) => { @@ -132,6 +138,7 @@ pub fn parse(yaml_str: &String) -> Result { input: input_folder.clone(), output: output_folder.clone(), template: template_file.clone(), + extension: file_extension, headings: headings_yaml, }) } diff --git a/src/main.rs b/src/main.rs index 94b1c56..32fc540 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ mod utils; fn main() { let config_file = Path::new(CONFIG_NAME); - if !config_file.is_dir() { + if !config_file.is_file() { eprintln!("A {} file was not found. Aborting.", CONFIG_NAME); return; } diff --git a/src/pages/md_compiler.rs b/src/pages/md_compiler.rs index 943e3b8..b549f2c 100644 --- a/src/pages/md_compiler.rs +++ b/src/pages/md_compiler.rs @@ -31,7 +31,7 @@ pub fn compile(config: &Config, file: &PathBuf, file_tree_html: &String) { let mut output_file = output_folder.clone(); output_file.push(relative_input_file); - output_file.set_extension("html"); + output_file.set_extension(config.extension.clone()); // // Read MD from disk @@ -47,8 +47,8 @@ pub fn compile(config: &Config, file: &PathBuf, file_tree_html: &String) { let sidebar_html = md_ast.generate_sidebar(); // Read template.html - let mut template_path = output_folder.clone(); - template_path.push("template.html"); + let template_path = Path::new(&config.template.clone()).canonicalize().unwrap(); + // template_path.push("template.html"); let template_contents = fs::read(template_path).unwrap(); let template_contents = String::from_utf8(template_contents).unwrap(); diff --git a/src/pages/mod.rs b/src/pages/mod.rs index fb343ed..38ddf2f 100644 --- a/src/pages/mod.rs +++ b/src/pages/mod.rs @@ -82,7 +82,7 @@ pub fn parse_yaml(values: &Yaml) -> Node { } } -pub fn generate_pages_html(file_tree: &Node, current_path: &Path) -> String { +pub fn generate_pages_html(file_tree: &Node, current_path: &Path, config: &Config) -> String { match file_tree { Node::File(file) => { if file.path == "index" { @@ -97,11 +97,12 @@ pub fn generate_pages_html(file_tree: &Node, current_path: &Path) -> String { } else { format!( "
  • - {} + {}
  • ", current_path.to_str().unwrap(), file.path, - file.name + config.extension, + file.name, ) } } @@ -112,7 +113,7 @@ pub fn generate_pages_html(file_tree: &Node, current_path: &Path) -> String { let sub_nodes_html: Vec = folder .children .iter() - .map(|n| generate_pages_html(n, &new_path)) + .map(|n| generate_pages_html(n, &new_path, config)) .collect(); // This is true for the root of the YAML file diff --git a/src/processor.rs b/src/processor.rs index 6d69082..937f8a9 100644 --- a/src/processor.rs +++ b/src/processor.rs @@ -94,7 +94,7 @@ fn process_yaml(config: &Config, current_path: &Path) { let yaml_folder_temp = current_path.canonicalize().unwrap(); let web_absolute_path = yaml_folder_temp.strip_prefix(input_folder).unwrap(); - generate_pages_html(&file_tree, web_absolute_path) + generate_pages_html(&file_tree, web_absolute_path, config) }; //