Skip to main content

geoff_plugin/
traits.rs

1use async_trait::async_trait;
2
3use crate::context::{
4    BuildContext, ContentContext, GraphContext, InitContext, OutputContext, RenderContext,
5    ValidationContext, WatchContext,
6};
7
8/// The core plugin trait. All lifecycle hooks have default no-op implementations.
9///
10/// Plugins can be implemented in Rust (loaded as cdylib) or in TypeScript (proxied via Deno).
11#[async_trait]
12pub trait Plugin: Send + Sync {
13    /// The plugin's unique name.
14    fn name(&self) -> &str;
15
16    /// Called once when the plugin is first loaded.
17    async fn on_init(
18        &self,
19        _ctx: &mut InitContext<'_>,
20    ) -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
21        Ok(())
22    }
23
24    /// Called at the start of each build.
25    async fn on_build_start(
26        &self,
27        _ctx: &mut BuildContext<'_>,
28    ) -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
29        Ok(())
30    }
31
32    /// Called after each content file is parsed.
33    async fn on_content_parsed(
34        &self,
35        _ctx: &mut ContentContext<'_>,
36    ) -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
37        Ok(())
38    }
39
40    /// Called after all content is ingested into the RDF graph.
41    async fn on_graph_updated(
42        &self,
43        _ctx: &mut GraphContext<'_>,
44    ) -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
45        Ok(())
46    }
47
48    /// Called after SHACL validation completes.
49    async fn on_validation_complete(
50        &self,
51        _ctx: &mut ValidationContext<'_>,
52    ) -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
53        Ok(())
54    }
55
56    /// Called before rendering each page.
57    async fn on_page_render(
58        &self,
59        _ctx: &mut RenderContext<'_>,
60    ) -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
61        Ok(())
62    }
63
64    /// Called after all output files are written.
65    async fn on_build_complete(
66        &self,
67        _ctx: &mut OutputContext<'_>,
68    ) -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
69        Ok(())
70    }
71
72    /// Called when a file change is detected during dev server.
73    async fn on_file_changed(
74        &self,
75        _ctx: &mut WatchContext<'_>,
76    ) -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
77        Ok(())
78    }
79}