Skip to main content

SiteGenerator

Struct SiteGenerator 

Source
pub struct SiteGenerator {
    pub source_dir: PathBuf,
    pub output_dir: PathBuf,
    pub theme: Theme,
    pub site_config: SiteConfig,
    pub documents: Vec<Document>,
    pub document_cache: HashMap<String, Document>,
}
Expand description

The main site generator that processes Markdown files and creates a static website.

SiteGenerator handles the entire process of creating a static site:

  • Scanning and parsing Markdown files with front matter
  • Processing internationalization and translations
  • Applying themes and templates
  • Generating HTML output with navigation features
  • Creating Atom feeds

§Example

use krik::generator::SiteGenerator;
use std::path::PathBuf;

let mut generator = SiteGenerator::new(
    "content",           // Source directory
    "_site",            // Output directory  
    Some("themes/custom") // Optional theme directory
)?;

generator.scan_files()?;
generator.generate_site()?;

Fields§

§source_dir: PathBuf

Source directory containing Markdown files and assets

§output_dir: PathBuf

Output directory where the generated site will be written

§theme: Theme

Theme configuration and templates

§site_config: SiteConfig

Site-wide configuration loaded from site.toml

§documents: Vec<Document>

Parsed documents ready for processing

§document_cache: HashMap<String, Document>

Incremental cache: map from relative file path to Document

Implementations§

Source§

impl SiteGenerator

Source

pub fn new<P: AsRef<Path>>( source_dir: P, output_dir: P, theme_dir: Option<P>, ) -> KrikResult<Self>

Creates a new SiteGenerator instance.

§Arguments
  • source_dir - Directory containing Markdown files and content
  • output_dir - Directory where generated HTML will be written
  • theme_dir - Optional custom theme directory (defaults to themes/default)
§Returns

Returns a Result containing the SiteGenerator or an error if initialization fails.

§Example
use krik::generator::SiteGenerator;

// Using default theme
let generator = SiteGenerator::new("content", "_site", None::<&str>)?;

// Using custom theme
let generator = SiteGenerator::new("content", "_site", Some("my-theme"))?;
Source

pub fn scan_files(&mut self) -> KrikResult<()>

Scan files in the source directory and parse markdown documents

Source

pub fn generate_site(&self) -> KrikResult<()>

Generate the complete static site

This orchestrates the entire site generation process:

  1. Copy non-markdown files and theme assets
  2. Generate HTML pages from documents
  3. Generate index page with post listings
  4. Generate Atom feed
  5. Generate XML sitemap
  6. Generate robots.txt
  7. Generate PDFs (if pandoc and typst are available)
Source

pub fn generate_incremental_for_path<P: AsRef<Path>>( &mut self, changed_path: P, is_removed: bool, ) -> KrikResult<()>

Incrementally (re)generate outputs affected by a single changed content or asset file.

Behavior:

  • If a markdown file changed: re-scan just that file, update/emit its HTML, and re-render index/feed/sitemap.
  • If a non-markdown content asset changed: copy that single asset into the output.
  • If a content file was removed: remove the mirrored output file and refresh index/feed/sitemap.
  • If a theme file changed (templates/assets), fall back to full regeneration as templates affect many pages.

Trait Implementations§

Source§

impl Debug for SiteGenerator

Source§

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

Formats the value using the given formatter. 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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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