Skip to main content

TemplatePlugin

Struct TemplatePlugin 

Source
pub struct TemplatePlugin { /* private fields */ }
Expand description

Plugin that post-processes compiled HTML through templates.

Runs in the after_compile phase, with the MiniJinja templates under <template_dir>/tera of the build context. For each HTML file in site_dir:

  1. Reads the companion .meta.json sidecar (from frontmatter extraction)
  2. Determines the layout from frontmatter (layout field, default: page)
  3. Takes the page’s rendered content out of the compiled document (the inside of <main>) and renders it through the template chain
  4. Writes the rendered result back to the same file

Falls back gracefully if no templates directory exists. The template_dir of a TemplateConfig passed to Self::new does not override the context’s: it only carries the globals and escaping settings.

Implementations§

Source§

impl TemplatePlugin

Source

pub const fn new(config: TemplateConfig) -> Self

Creates a new TemplatePlugin with the given configuration.

§Examples
use ssg::plugin::Plugin;
use ssg::template_engine::TemplateConfig;
use ssg::template_plugin::TemplatePlugin;

let p = TemplatePlugin::new(TemplateConfig::default());
assert_eq!(p.name(), "templates");
Source

pub fn from_template_dir(template_dir: &Path) -> Self

Creates a TemplatePlugin that looks for templates in the standard templates/tera/ subdirectory of the template dir.

§Examples
use ssg::plugin::Plugin;
use ssg::template_plugin::TemplatePlugin;
use std::path::Path;

let p = TemplatePlugin::from_template_dir(Path::new("templates"));
assert_eq!(p.name(), "templates");

Trait Implementations§

Source§

impl Debug for TemplatePlugin

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Plugin for TemplatePlugin

Available on crate feature templates only.
Source§

fn name(&self) -> &'static str

Returns the unique name of this plugin.
Source§

fn before_compile(&self, ctx: &PluginContext) -> Result<(), SsgError>

Called before site compilation begins. Read more
Source§

fn after_compile(&self, ctx: &PluginContext) -> Result<(), SsgError>

Called after site compilation completes. Read more
Source§

fn transform_html( &self, html: &str, _path: &Path, _ctx: &PluginContext, ) -> Result<String, SsgError>

Per-file HTML transform hook — called once per HTML file during the fused transform pass. Read more
Source§

fn has_transform(&self) -> bool

Returns true if this plugin implements transform_html. Override to true to opt in to the fused transform pass.
Source§

fn needs_all_files(&self) -> bool

Returns true if this plugin must always observe the full cache.html_files() list — even during --incremental rebuilds that only invalidated a handful of pages. Read more
Source§

fn on_serve(&self, _ctx: &PluginContext) -> Result<(), SsgError>

Called before the development server starts serving files. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more