aboutsummaryrefslogtreecommitdiff
path: root/src/command/status/blog_status.rs
blob: df5256e2fd78fe29bda8dd9346527eb65537d9df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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()
    }
}