diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-02-26 11:44:11 +0000 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-02-26 11:44:11 +0000 |
| commit | 0e276d039b8613de0cbd302bf328bb660ab063b6 (patch) | |
| tree | 5395f77ca18ce151b9e331e3f2ada3d3ec461362 /src/command/status/blog_status.rs | |
| parent | 606f82c76540a9d80366fdb943c06abe525f662e (diff) | |
Add blog status, correctly shift
Diffstat (limited to 'src/command/status/blog_status.rs')
| -rw-r--r-- | src/command/status/blog_status.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/command/status/blog_status.rs b/src/command/status/blog_status.rs new file mode 100644 index 0000000..df5256e --- /dev/null +++ b/src/command/status/blog_status.rs @@ -0,0 +1,24 @@ +use std::fs::read_dir; +use std::path::PathBuf; +use crate::configuration::Configuration; + +pub fn status(configuration: &Configuration) -> String { + let mut status_message = String::new(); + + status_message.push_str("# Blog\n"); + + // Main Configuration Locations + let blog_count = count_entries(&configuration.posts_directory); + status_message.push_str(&format!("Number of posts in blog: {}\n", blog_count)); + + let archive_count = count_entries(&configuration.archive_directory); + status_message.push_str(&format!("Number of posts in archive: {}\n", archive_count)); + status_message +} + +fn count_entries(path: &PathBuf) -> String { + match read_dir(path) { + Ok(entries) => entries.filter_map(Result::ok).count().to_string(), + Err(_) => "0".to_string() + } +} |