rs_web/content/
page.rs

1use anyhow::{Context, Result};
2use std::path::Path;
3
4use super::frontmatter::{Frontmatter, parse_frontmatter};
5
6#[derive(Debug, Clone)]
7pub struct Page {
8    pub frontmatter: Frontmatter,
9    pub content: String,
10    pub html: String,
11}
12
13impl Page {
14    pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self> {
15        let raw_content = std::fs::read_to_string(path.as_ref())
16            .with_context(|| format!("Failed to read page: {:?}", path.as_ref()))?;
17
18        let (frontmatter, content) = parse_frontmatter(&raw_content)?;
19
20        Ok(Self {
21            frontmatter,
22            content: content.to_string(),
23            html: String::new(), // Will be filled by markdown pipeline
24        })
25    }
26
27    pub fn with_html(mut self, html: String) -> Self {
28        self.html = html;
29        self
30    }
31}