display elapsed time

master
Araozu 2024-03-27 12:15:46 -05:00
parent e675344b23
commit 79020222e5
3 changed files with 23 additions and 10 deletions

View File

@ -9,6 +9,9 @@ mod sidebar;
mod utils;
fn main() {
// get current time in ms
let start = std::time::Instant::now();
// get args
let args: Vec<String> = std::env::args().collect();
// if first arg is --version, print version and exit
@ -33,7 +36,9 @@ fn main() {
match config::parse(&config_str) {
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) => {
eprintln!("{}", reason);

View File

@ -139,13 +139,15 @@ pub fn compile_md_to_html(
file_tree: &Node,
current_path: &Path,
file_tree_html: &String,
) {
) -> i32 {
match file_tree {
Node::File(file) if file.path != "" => {
let mut file_path = current_path.canonicalize().unwrap();
file_path.push(format!("{}.md", file.path));
md_compiler::compile(config, &file_path, file_tree_html);
1
}
Node::File(_) => {
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)
.expect("SHOULD be able to create folder");
let mut count = 0;
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) => {
let mut count = 0;
for node in folder.children.iter() {
compile_md_to_html(config, node, &current_path, file_tree_html);
count += compile_md_to_html(config, node, &current_path, file_tree_html);
}
count
}
}
}

View File

@ -10,14 +10,14 @@ enum EntryFound {
None,
}
pub fn search_config_file(config: &Config) {
pub fn search_config_file(config: &Config) -> i32 {
let current_folder = Path::new(&config.input);
search_config_file_impl(config, current_folder)
}
// 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
let result = current_folder
.read_dir()
@ -53,19 +53,21 @@ pub fn search_config_file_impl(config: &Config, current_folder: &Path) {
EntryFound::YamlFile => process_yaml(config, current_folder),
// No files found, recursively read children folders
EntryFound::None => {
let mut count = 0;
for entry in current_folder.read_dir().unwrap() {
// Should always succeed, and contain a folder
let x = entry.unwrap();
let path = x.path();
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);
//
@ -100,5 +102,5 @@ fn process_yaml(config: &Config, current_path: &Path) {
//
// 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)
}