Skip to main content

euv_docs/generator/
struct.rs

1use super::*;
2
3/// Result summary emitted after generating a static documentation bundle.
4#[derive(Clone, Debug, Deserialize, Eq, Getter, New, PartialEq, Serialize)]
5pub struct GeneratedSiteReport {
6    /// Total HTML pages written.
7    #[get(type(copy))]
8    pub(crate) page_count: usize,
9    /// UTC RFC-3339 build timestamp.
10    pub(crate) generated_at: String,
11    /// Path to the generated JSON search index.
12    pub(crate) index_path: String,
13}
14
15/// Configuration controlling static documentation site generation and optional dev live-reload.
16#[derive(Clone, Data, Debug, Deserialize, Eq, PartialEq, Serialize)]
17pub struct DocsBuildOptions {
18    /// Optional explicit site brand title overriding frontmatter and directory heuristics.
19    pub(crate) title: Option<String>,
20    /// Optional URL base prefix (for example `""` or `"/docs"`).
21    pub(crate) base_url: String,
22    /// Optional SSE live-reload endpoint injected in dev mode (for example `Some("/__euv_hmr")`).
23    pub(crate) hmr_endpoint: Option<String>,
24    /// Optional source root directory whose static assets are copied into the build output.
25    pub(crate) assets_root: Option<PathBuf>,
26    /// When `true`, writes both `<route>/index.html` and `<route>.html` for universal static hosting.
27    #[get(type(copy))]
28    pub(crate) clean_urls: bool,
29}
30
31/// Pre-escaped sidebar navigation link metadata shared across all rendered pages.
32#[derive(Clone, Debug, Getter)]
33pub(crate) struct SidebarNavEntry<'a> {
34    /// Canonical page route used to mark the active link.
35    #[get(pub(crate), type(copy))]
36    pub(crate) route: &'a str,
37    /// Optional pre-rendered section header HTML emitted before this entry when a section starts.
38    #[get(pub(crate))]
39    pub(crate) section_header_html: Option<String>,
40    /// Pre-escaped link suffix (`"<href>\"><title></a>"`) appended after the open anchor prefix.
41    #[get(pub(crate))]
42    pub(crate) link_tail_html: String,
43}
44
45/// Shared immutable context passed into page HTML generation to keep helper signatures compact.
46#[derive(Clone, Copy, Debug, Getter)]
47pub(crate) struct PageRenderContext<'a> {
48    /// Parent documentation site containing navigation metadata.
49    #[get(pub(crate), type(copy))]
50    pub(crate) site: &'a DocSite,
51    /// Pre-sorted and pre-escaped sidebar navigation entries shared across all pages.
52    #[get(pub(crate), type(copy))]
53    pub(crate) sidebar_entries: &'a [SidebarNavEntry<'a>],
54    /// Pre-escaped site title string.
55    #[get(pub(crate), type(copy))]
56    pub(crate) site_title_escaped: &'a str,
57    /// Pre-escaped root home href attribute string.
58    #[get(pub(crate), type(copy))]
59    pub(crate) home_href_escaped: &'a str,
60    /// Pre-escaped RFC-3339 build timestamp string.
61    #[get(pub(crate), type(copy))]
62    pub(crate) generated_at_escaped: &'a str,
63    /// JSON-serialized base URL prefix injected into the search script.
64    #[get(pub(crate), type(copy))]
65    pub(crate) base_json: &'a str,
66    /// Previous page in canonical sidebar reading order.
67    #[get(pub(crate), type(copy))]
68    pub(crate) prev_page: Option<&'a DocPage>,
69    /// Next page in canonical sidebar reading order.
70    #[get(pub(crate), type(copy))]
71    pub(crate) next_page: Option<&'a DocPage>,
72    /// Script-safe compact JSON search index payload.
73    #[get(pub(crate), type(copy))]
74    pub(crate) search_json_compact: &'a str,
75    /// Active documentation build options.
76    #[get(pub(crate), type(copy))]
77    pub(crate) options: &'a DocsBuildOptions,
78}
79
80/// Mutable state threaded through Markdown chunk rendering for a single page.
81pub(crate) struct MarkdownRenderState<'a> {
82    /// Current documentation page being rendered.
83    pub(crate) page: &'a DocPage,
84    /// Normalized base URL prefix without trailing slash.
85    pub(crate) base: &'a str,
86    /// Per-page heading anchor slug counter for deduplication.
87    pub(crate) seen_slugs: BTreeMap<String, usize>,
88    /// Whether the leading H1 matching `page.title` has already been skipped.
89    pub(crate) skipped_title_h1: bool,
90    /// Destination HTML buffer.
91    pub(crate) out: &'a mut String,
92}