use compact_str::CompactString;
use serde::Deserialize;
use wcore::utils::split_yaml_frontmatter;
#[derive(Debug, Clone)]
pub struct CronEntry {
pub name: CompactString,
pub schedule: String,
pub agent: CompactString,
pub message: String,
}
#[derive(Deserialize)]
struct CronFrontmatter {
name: String,
schedule: String,
agent: String,
}
pub fn parse_cron_md(content: &str) -> anyhow::Result<CronEntry> {
let (frontmatter, body) = split_yaml_frontmatter(content)?;
let fm: CronFrontmatter = serde_yaml::from_str(frontmatter)?;
Ok(CronEntry {
name: CompactString::from(fm.name),
schedule: fm.schedule,
agent: CompactString::from(fm.agent),
message: body.trim().to_owned(),
})
}