pub struct PluginContext {
pub content_dir: PathBuf,
pub build_dir: PathBuf,
pub site_dir: PathBuf,
pub template_dir: PathBuf,
pub config: Option<SsgConfig>,
pub cache: Option<PluginCache>,
pub memory_budget: Option<MemoryBudget>,
pub html_files: Option<Arc<Vec<PathBuf>>>,
pub dep_graph: Option<DepGraph>,
pub dry_run: bool,
}Expand description
Context passed to plugin hooks with paths and configuration.
Fields§
§content_dir: PathBufThe content source directory.
build_dir: PathBufThe build/output directory.
site_dir: PathBufThe final site directory.
template_dir: PathBufThe template directory.
config: Option<SsgConfig>Site configuration (base_url, site_name, language, etc.).
cache: Option<PluginCache>Content-addressed plugin cache for incremental builds.
memory_budget: Option<MemoryBudget>Memory budget for streaming compilation.
html_files: Option<Arc<Vec<PathBuf>>>Cached list of HTML files in site_dir, walked once and shared
across all plugins to avoid redundant filesystem traversals.
dep_graph: Option<DepGraph>Page dependency graph for incremental rebuilds.
dry_run: boolWhen true, plugins should perform validation passes only and
must not write to disk. Set by the ssg check subcommand
(issue #527). Plugins that don’t have a meaningful read-only
mode may safely ignore this flag.
Implementations§
Source§impl PluginContext
impl PluginContext
Sourcepub fn cache_html_files(&mut self)
pub fn cache_html_files(&mut self)
Populates the cached HTML file list by walking site_dir once.
Call this before running after_compile plugins to eliminate
redundant directory scans (8+ plugins read the same file list).
§Examples
use ssg::plugin::PluginContext;
use tempfile::tempdir;
let dir = tempdir().unwrap();
let mut ctx = PluginContext::new(dir.path(), dir.path(), dir.path(), dir.path());
ctx.cache_html_files();
// Empty dir ⇒ empty cached list.
assert!(ctx.get_html_files().is_empty());Sourcepub fn get_html_files(&self) -> Vec<PathBuf>
pub fn get_html_files(&self) -> Vec<PathBuf>
Returns the cached HTML file list, or walks the directory if the cache hasn’t been populated.
§Examples
use ssg::plugin::PluginContext;
use tempfile::tempdir;
let dir = tempdir().unwrap();
let ctx = PluginContext::new(dir.path(), dir.path(), dir.path(), dir.path());
assert!(ctx.get_html_files().is_empty());Sourcepub fn new(
content_dir: &Path,
build_dir: &Path,
site_dir: &Path,
template_dir: &Path,
) -> Self
pub fn new( content_dir: &Path, build_dir: &Path, site_dir: &Path, template_dir: &Path, ) -> Self
Creates a new plugin context from directory paths.
§Examples
use ssg::plugin::PluginContext;
use std::path::Path;
let ctx = PluginContext::new(
Path::new("content"), Path::new("build"),
Path::new("site"), Path::new("templates"),
);
assert_eq!(ctx.content_dir, Path::new("content"));Sourcepub fn with_config(
content_dir: &Path,
build_dir: &Path,
site_dir: &Path,
template_dir: &Path,
config: SsgConfig,
) -> Self
pub fn with_config( content_dir: &Path, build_dir: &Path, site_dir: &Path, template_dir: &Path, config: SsgConfig, ) -> Self
Creates a new plugin context with site configuration.
§Examples
use ssg::cmd::SsgConfig;
use ssg::plugin::PluginContext;
use std::path::Path;
let cfg = SsgConfig::default();
let ctx = PluginContext::with_config(
Path::new("content"), Path::new("build"),
Path::new("site"), Path::new("templates"),
cfg,
);
assert!(ctx.config.is_some());Sourcepub const fn with_dry_run(self, dry_run: bool) -> Self
pub const fn with_dry_run(self, dry_run: bool) -> Self
Sets the dry_run flag and returns the modified context.
Used by the ssg check subcommand (issue #527) to signal to
plugins that they should run their validation passes without
writing to disk.
§Examples
use ssg::plugin::PluginContext;
use std::path::Path;
let ctx = PluginContext::new(
Path::new("content"), Path::new("build"),
Path::new("site"), Path::new("templates"),
).with_dry_run(true);
assert!(ctx.dry_run);Trait Implementations§
Source§impl Clone for PluginContext
impl Clone for PluginContext
Source§fn clone(&self) -> PluginContext
fn clone(&self) -> PluginContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PluginContext
impl RefUnwindSafe for PluginContext
impl Send for PluginContext
impl Sync for PluginContext
impl Unpin for PluginContext
impl UnsafeUnpin for PluginContext
impl UnwindSafe for PluginContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more