use anyhow::Result;
use std::path::Path;
pub fn write_export(dir: &Path, slug: &str, contents: &str) -> Result<std::path::PathBuf> {
std::fs::create_dir_all(dir)?;
let path = dir.join(format!("{slug}.md"));
std::fs::write(&path, contents)?;
Ok(path)
}
pub fn slug_from_title(title: &str) -> String {
title
.chars()
.filter_map(|c| {
if c.is_alphanumeric() {
Some(c.to_ascii_lowercase())
} else if c.is_whitespace() || c == '-' || c == '_' {
Some('-')
} else {
None
}
})
.collect::<String>()
.split('-')
.filter(|s| !s.is_empty())
.collect::<Vec<_>>()
.join("-")
}