]> git.r.bdr.sh - rbdr/blog/blame_incremental - src/command/status/blog_status.rs
Make smaller
[rbdr/blog] / src / command / status / blog_status.rs
... / ...
CommitLineData
1use std::fs::read_dir;
2use std::path::PathBuf;
3use crate::configuration::Configuration;
4
5pub fn status(configuration: &Configuration) -> String {
6 let mut status_message = String::new();
7
8 status_message.push_str("# Blog\n");
9
10 // Main Configuration Locations
11 let blog_count = count_entries(&configuration.posts_directory);
12 status_message.push_str(&format!("Number of posts in blog: {}\n", blog_count));
13
14 let archive_count = count_entries(&configuration.archive_directory);
15 status_message.push_str(&format!("Number of posts in archive: {}\n", archive_count));
16 status_message
17}
18
19fn count_entries(path: &PathBuf) -> String {
20 match read_dir(path) {
21 Ok(entries) => entries.filter_map(Result::ok).count().to_string(),
22 Err(_) => "0".to_string()
23 }
24}