orbit_md/models/page.rs
1//! Page lifecycle types enforcing compile-state separation.
2
3use std::path::PathBuf;
4
5use crate::models::FrontMatter;
6
7/// A Markdown source file discovered on disk with parsed front matter.
8///
9/// This is the input to the compilation pipeline. The raw Markdown body has
10/// not yet been converted to HTML.
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct SourcePage {
13 /// Absolute or project-relative path to the source `.md` file.
14 pub source_path: PathBuf,
15
16 /// Path relative to the content root, used to derive output URLs.
17 pub relative_path: PathBuf,
18
19 /// Parsed YAML front matter (defaults applied for missing keys).
20 pub front_matter: FrontMatter,
21
22 /// Markdown body after front matter extraction.
23 pub body: String,
24}
25
26/// Newtype marking a [`SourcePage`] that has not yet been parsed.
27///
28/// Illegal transitions (e.g. writing directly to disk) are prevented because
29/// only [`CompiledPage`] and [`RenderedPage`] expose HTML payloads.
30#[derive(Debug, Clone, PartialEq, Eq)]
31pub struct UncompiledPage(pub SourcePage);
32
33impl UncompiledPage {
34 /// Wraps a discovered source page for the parsing stage.
35 pub fn new(page: SourcePage) -> Self {
36 Self(page)
37 }
38
39 /// Borrows the inner source page.
40 pub fn inner(&self) -> &SourcePage {
41 &self.0
42 }
43
44 /// Consumes the wrapper and returns the inner source page.
45 pub fn into_inner(self) -> SourcePage {
46 self.0
47 }
48}
49
50/// Markdown body converted to an HTML fragment, before layout wrapping.
51#[derive(Debug, Clone, PartialEq, Eq)]
52pub struct CompiledPage {
53 /// Original source metadata and paths.
54 pub source: SourcePage,
55
56 /// HTML generated from the Markdown body (no layout chrome).
57 pub content_html: String,
58}
59
60impl CompiledPage {
61 /// Creates a compiled page from its source and rendered fragment.
62 pub fn new(source: SourcePage, content_html: String) -> Self {
63 Self {
64 source,
65 content_html,
66 }
67 }
68}
69
70/// Fully rendered HTML page ready for disk output.
71#[derive(Debug, Clone, PartialEq, Eq)]
72pub struct RenderedPage {
73 /// Destination path under the output directory.
74 pub output_path: PathBuf,
75
76 /// Complete HTML document including layout template.
77 pub html: String,
78}
79
80impl RenderedPage {
81 /// Creates a rendered page destined for `output_path`.
82 pub fn new(output_path: PathBuf, html: String) -> Self {
83 Self { output_path, html }
84 }
85}