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: PathBufSource directory containing Markdown files and assets
output_dir: PathBufOutput directory where the generated site will be written
theme: ThemeTheme configuration and templates
site_config: SiteConfigSite-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
impl SiteGenerator
Sourcepub fn new<P: AsRef<Path>>(
source_dir: P,
output_dir: P,
theme_dir: Option<P>,
) -> KrikResult<Self>
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 contentoutput_dir- Directory where generated HTML will be writtentheme_dir- Optional custom theme directory (defaults tothemes/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"))?;Sourcepub fn scan_files(&mut self) -> KrikResult<()>
pub fn scan_files(&mut self) -> KrikResult<()>
Scan files in the source directory and parse markdown documents
Sourcepub fn generate_site(&self) -> KrikResult<()>
pub fn generate_site(&self) -> KrikResult<()>
Generate the complete static site
This orchestrates the entire site generation process:
- Copy non-markdown files and theme assets
- Generate HTML pages from documents
- Generate index page with post listings
- Generate Atom feed
- Generate XML sitemap
- Generate robots.txt
- Generate PDFs (if pandoc and typst are available)
Sourcepub fn generate_incremental_for_path<P: AsRef<Path>>(
&mut self,
changed_path: P,
is_removed: bool,
) -> KrikResult<()>
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§
Auto Trait Implementations§
impl !RefUnwindSafe for SiteGenerator
impl !UnwindSafe for SiteGenerator
impl Freeze for SiteGenerator
impl Send for SiteGenerator
impl Sync for SiteGenerator
impl Unpin for SiteGenerator
impl UnsafeUnpin for SiteGenerator
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<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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