Skip to main content

geoff_plugin/
context.rs

1use std::collections::HashMap;
2
3use geoff_core::config::SiteConfig;
4use geoff_graph::store::ContentStore;
5use serde::{Deserialize, Serialize};
6
7/// Plugin-facing view of a page's parsed content.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct PageData {
10    /// Content-relative path (e.g. "blog/hello.md").
11    pub path: String,
12    /// Page title from frontmatter.
13    pub title: Option<String>,
14    /// Content type from frontmatter (e.g. "Blog Post").
15    pub content_type: Option<String>,
16    /// Rendered HTML body.
17    pub html: String,
18    /// Raw Markdown body.
19    pub raw_body: String,
20    /// All frontmatter fields.
21    pub frontmatter: HashMap<String, serde_json::Value>,
22}
23
24/// Context passed to plugins during initialization.
25pub struct InitContext<'a> {
26    pub config: &'a SiteConfig,
27    pub plugin_options: &'a HashMap<String, toml::Value>,
28}
29
30/// Context passed at the start of a build.
31pub struct BuildContext<'a> {
32    pub config: &'a SiteConfig,
33    pub store: &'a ContentStore,
34}
35
36/// Context passed after a single content file is parsed.
37pub struct ContentContext<'a> {
38    pub config: &'a SiteConfig,
39    pub page: &'a mut PageData,
40}
41
42/// Context passed after all content is ingested into the graph.
43pub struct GraphContext<'a> {
44    pub config: &'a SiteConfig,
45    pub store: &'a ContentStore,
46}
47
48/// Context passed after SHACL validation completes.
49pub struct ValidationContext<'a> {
50    pub config: &'a SiteConfig,
51    pub store: &'a ContentStore,
52    pub conforms: bool,
53    pub violations: usize,
54}
55
56/// Context passed before rendering a single page.
57pub struct RenderContext<'a> {
58    pub config: &'a SiteConfig,
59    pub store: &'a ContentStore,
60    pub page: &'a mut PageData,
61    /// Extra template variables that plugins can inject.
62    pub extra_vars: &'a mut HashMap<String, serde_json::Value>,
63}
64
65/// Context passed after all output files are written.
66pub struct OutputContext<'a> {
67    pub config: &'a SiteConfig,
68    pub store: &'a ContentStore,
69    /// Map of output path -> rendered HTML.
70    pub outputs: &'a HashMap<String, String>,
71    /// The output directory path.
72    pub output_dir: &'a camino::Utf8Path,
73}
74
75/// Context passed when a file change is detected during `serve`.
76pub struct WatchContext<'a> {
77    pub config: &'a SiteConfig,
78    pub changed_path: &'a str,
79}