]>
Commit | Line | Data |
---|---|---|
1 | use std::fs::read_dir; | |
2 | use std::path::PathBuf; | |
3 | use crate::configuration::Configuration; | |
4 | ||
5 | pub 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 | ||
19 | fn 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 | } |