pub struct Engine { /* private fields */ }
Expand description
The primary engine responsible for site generation.
Handles the loading of templates, processing of content files, rendering of pages, and copying of static assets.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Creates a new Engine
instance.
§Errors
Returns an error if initializing the internal state fails, which is unlikely in this implementation.
Sourcepub async fn generate(&self, config: &Config) -> Result<()>
pub async fn generate(&self, config: &Config) -> Result<()>
Orchestrates the complete site generation process.
§Errors
Returns an error if:
- The output directory cannot be created.
- Templates fail to load.
- Content files fail to process.
- Pages fail to generate.
- Assets fail to copy.
Sourcepub async fn load_templates(&self, config: &Config) -> Result<()>
pub async fn load_templates(&self, config: &Config) -> Result<()>
Loads and caches all templates from the template directory.
§Errors
Returns an error if:
- Template files cannot be read or parsed.
- Directory entries fail to load.
- File paths contain invalid characters.
Sourcepub async fn process_content_files(&self, config: &Config) -> Result<()>
pub async fn process_content_files(&self, config: &Config) -> Result<()>
Processes all content files in the content directory.
§Errors
This function will return an error if:
- The content directory cannot be read.
- Any content file fails to process.
- Writing to the cache encounters an issue.
Sourcepub async fn process_content_file(
&self,
path: &Path,
config: &Config,
) -> Result<ContentFile>
pub async fn process_content_file( &self, path: &Path, config: &Config, ) -> Result<ContentFile>
Processes a single content file and prepares it for rendering.
§Errors
This function will return an error if:
- The content file cannot be read.
- The front matter extraction fails.
- The Markdown to HTML conversion encounters an issue.
- The destination path is invalid.
Sourcepub fn extract_front_matter(
&self,
content: &str,
) -> Result<(HashMap<String, Value>, String)>
pub fn extract_front_matter( &self, content: &str, ) -> Result<(HashMap<String, Value>, String)>
Extracts frontmatter metadata and content body from a file.
§Errors
This function will return an error if:
- The front matter is not valid YAML.
- The content cannot be split correctly into metadata and body.
Sourcepub fn render_template(
&self,
template: &str,
content: &ContentFile,
) -> Result<String>
pub fn render_template( &self, template: &str, content: &ContentFile, ) -> Result<String>
Renders a template with the provided content.
§Errors
This function will return an error if:
- The template contains invalid syntax.
- The rendering process fails due to missing or invalid context variables.
Sourcepub async fn copy_assets(&self, config: &Config) -> Result<()>
pub async fn copy_assets(&self, config: &Config) -> Result<()>
Copies static assets from the content directory to the output directory.
§Errors
This function will return an error if:
- The assets directory does not exist or cannot be read.
- A file or directory cannot be copied to the output directory.
- An I/O error occurs during the copying process.