use std::path::PathBuf;
use crate::body;
use crate::frontmatter::{self, Frontmatter};
#[derive(Debug, Clone)]
pub struct Doc {
pub path: PathBuf,
pub frontmatter: Frontmatter,
pub body: String,
pub title: String,
}
impl Doc {
pub fn parse(path: PathBuf, text: &str) -> Result<Doc, String> {
let display = path.display().to_string();
let (frontmatter, body) = frontmatter::parse(text, &display).map_err(|e| e.0)?;
let title = body::title(&body);
Ok(Doc {
path,
frontmatter,
body,
title,
})
}
pub fn id(&self) -> Option<&str> {
self.frontmatter.id()
}
pub fn status(&self) -> Option<&str> {
self.frontmatter.status()
}
pub fn to_text(&self) -> String {
frontmatter::serialize(&self.frontmatter, &self.body)
}
}