bookyard-core 0.1.0

Core configuration and catalog model for Bookyard.
Documentation
use std::path::Path;

pub fn slugify_book_id(input: &str) -> String {
    let candidate = Path::new(input)
        .file_name()
        .and_then(|name| name.to_str())
        .unwrap_or(input);
    let mut out = String::new();
    let mut last_dash = false;
    for ch in candidate.chars().flat_map(char::to_lowercase) {
        if ch.is_ascii_alphanumeric() {
            out.push(ch);
            last_dash = false;
        } else if !last_dash && !out.is_empty() {
            out.push('-');
            last_dash = true;
        }
    }
    while out.ends_with('-') {
        out.pop();
    }
    if out.is_empty() { "book".into() } else { out }
}