display elapsed time
This commit is contained in:
parent
e675344b23
commit
79020222e5
@ -9,6 +9,9 @@ mod sidebar;
|
|||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
// get current time in ms
|
||||||
|
let start = std::time::Instant::now();
|
||||||
|
|
||||||
// get args
|
// get args
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args: Vec<String> = std::env::args().collect();
|
||||||
// if first arg is --version, print version and exit
|
// if first arg is --version, print version and exit
|
||||||
@ -33,7 +36,9 @@ fn main() {
|
|||||||
|
|
||||||
match config::parse(&config_str) {
|
match config::parse(&config_str) {
|
||||||
Ok(config) => {
|
Ok(config) => {
|
||||||
processor::search_config_file(&config);
|
let files_count = processor::search_config_file(&config);
|
||||||
|
let elapsed = start.elapsed();
|
||||||
|
println!("Processed {} files in {:.2?}", files_count, elapsed);
|
||||||
}
|
}
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
eprintln!("{}", reason);
|
eprintln!("{}", reason);
|
||||||
|
@ -139,13 +139,15 @@ pub fn compile_md_to_html(
|
|||||||
file_tree: &Node,
|
file_tree: &Node,
|
||||||
current_path: &Path,
|
current_path: &Path,
|
||||||
file_tree_html: &String,
|
file_tree_html: &String,
|
||||||
) {
|
) -> i32 {
|
||||||
match file_tree {
|
match file_tree {
|
||||||
Node::File(file) if file.path != "" => {
|
Node::File(file) if file.path != "" => {
|
||||||
let mut file_path = current_path.canonicalize().unwrap();
|
let mut file_path = current_path.canonicalize().unwrap();
|
||||||
file_path.push(format!("{}.md", file.path));
|
file_path.push(format!("{}.md", file.path));
|
||||||
|
|
||||||
md_compiler::compile(config, &file_path, file_tree_html);
|
md_compiler::compile(config, &file_path, file_tree_html);
|
||||||
|
|
||||||
|
1
|
||||||
}
|
}
|
||||||
Node::File(_) => {
|
Node::File(_) => {
|
||||||
panic!("YAML: A file cannot have an empty `path` key")
|
panic!("YAML: A file cannot have an empty `path` key")
|
||||||
@ -156,14 +158,18 @@ pub fn compile_md_to_html(
|
|||||||
utils::ensure_folder_exists(config, &new_path)
|
utils::ensure_folder_exists(config, &new_path)
|
||||||
.expect("SHOULD be able to create folder");
|
.expect("SHOULD be able to create folder");
|
||||||
|
|
||||||
|
let mut count = 0;
|
||||||
for node in folder.children.iter() {
|
for node in folder.children.iter() {
|
||||||
compile_md_to_html(config, node, &new_path, file_tree_html);
|
count += compile_md_to_html(config, node, &new_path, file_tree_html);
|
||||||
}
|
}
|
||||||
|
count
|
||||||
}
|
}
|
||||||
Node::Folder(folder) => {
|
Node::Folder(folder) => {
|
||||||
|
let mut count = 0;
|
||||||
for node in folder.children.iter() {
|
for node in folder.children.iter() {
|
||||||
compile_md_to_html(config, node, ¤t_path, file_tree_html);
|
count += compile_md_to_html(config, node, ¤t_path, file_tree_html);
|
||||||
}
|
}
|
||||||
|
count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,14 +10,14 @@ enum EntryFound {
|
|||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn search_config_file(config: &Config) {
|
pub fn search_config_file(config: &Config) -> i32 {
|
||||||
let current_folder = Path::new(&config.input);
|
let current_folder = Path::new(&config.input);
|
||||||
|
|
||||||
search_config_file_impl(config, current_folder)
|
search_config_file_impl(config, current_folder)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursively traverses the current folder searching a YAML file
|
// Recursively traverses the current folder searching a YAML file
|
||||||
pub fn search_config_file_impl(config: &Config, current_folder: &Path) {
|
pub fn search_config_file_impl(config: &Config, current_folder: &Path) -> i32 {
|
||||||
// Iterate over all the files searching for a YAML file
|
// Iterate over all the files searching for a YAML file
|
||||||
let result = current_folder
|
let result = current_folder
|
||||||
.read_dir()
|
.read_dir()
|
||||||
@ -53,19 +53,21 @@ pub fn search_config_file_impl(config: &Config, current_folder: &Path) {
|
|||||||
EntryFound::YamlFile => process_yaml(config, current_folder),
|
EntryFound::YamlFile => process_yaml(config, current_folder),
|
||||||
// No files found, recursively read children folders
|
// No files found, recursively read children folders
|
||||||
EntryFound::None => {
|
EntryFound::None => {
|
||||||
|
let mut count = 0;
|
||||||
for entry in current_folder.read_dir().unwrap() {
|
for entry in current_folder.read_dir().unwrap() {
|
||||||
// Should always succeed, and contain a folder
|
// Should always succeed, and contain a folder
|
||||||
let x = entry.unwrap();
|
let x = entry.unwrap();
|
||||||
let path = x.path();
|
let path = x.path();
|
||||||
|
|
||||||
utils::ensure_folder_exists(config, &path).unwrap();
|
utils::ensure_folder_exists(config, &path).unwrap();
|
||||||
search_config_file_impl(config, &path);
|
count += search_config_file_impl(config, &path);
|
||||||
}
|
}
|
||||||
|
count
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_yaml(config: &Config, current_path: &Path) {
|
fn process_yaml(config: &Config, current_path: &Path) -> i32 {
|
||||||
let input_folder = Path::new(&config.input);
|
let input_folder = Path::new(&config.input);
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -100,5 +102,5 @@ fn process_yaml(config: &Config, current_path: &Path) {
|
|||||||
//
|
//
|
||||||
// Compile MD to HTML
|
// Compile MD to HTML
|
||||||
//
|
//
|
||||||
compile_md_to_html(config, &file_tree, current_path, &tree_html);
|
compile_md_to_html(config, &file_tree, current_path, &tree_html)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user