pub struct StaticSiteGenerator { /* private fields */ }ssg only.Expand description
Writes rendered pages and assets into an output directory.
§Examples
use winged_rust::prelude::*;
use winged_rust::{Document, ssg::StaticSiteGenerator};
let site = StaticSiteGenerator::new("dist");
site.clean(true)?;
site.generate(&Document::new(Some("pt-BR")), "index.html", &RenderOptions::pretty())?;Implementations§
Source§impl StaticSiteGenerator
impl StaticSiteGenerator
Sourcepub fn new(output_directory: impl Into<PathBuf>) -> Self
pub fn new(output_directory: impl Into<PathBuf>) -> Self
Creates a generator writing into output_directory.
Sourcepub fn output_directory(&self) -> &Path
pub fn output_directory(&self) -> &Path
The directory pages are written into.
Sourcepub fn generate(
&self,
document: &Document,
path: &str,
options: &RenderOptions,
) -> Result<()>
pub fn generate( &self, document: &Document, path: &str, options: &RenderOptions, ) -> Result<()>
Renders a document to path, relative to the output directory.
§Errors
Returns an error if the path escapes the output directory, or if the write fails.
Sourcepub fn generate_multiple(
&self,
documents: &[(Document, String)],
options: &RenderOptions,
) -> Result<()>
pub fn generate_multiple( &self, documents: &[(Document, String)], options: &RenderOptions, ) -> Result<()>
Renders several documents.
With the parallel feature the pages are rendered concurrently — sound because the
node tree is Send + Sync, which Winged-Swift’s reference-typed tree is not.
Every failure is reported, not just the first: a bulk build that names one of twelve broken pages is worse than useless.
§Errors
Returns an error naming every page that failed.
Sourcepub fn generate_page(
&self,
page: &Node,
path: &str,
options: &RenderOptions,
doctype: bool,
) -> Result<()>
pub fn generate_page( &self, page: &Node, path: &str, options: &RenderOptions, doctype: bool, ) -> Result<()>
Renders a bare node to path, optionally prefixed by the doctype.
§Errors
Returns an error if the path is unsafe or the write fails.
Sourcepub fn copy_asset(&self, from: impl AsRef<Path>, to: &str) -> Result<()>
pub fn copy_asset(&self, from: impl AsRef<Path>, to: &str) -> Result<()>
Copies a file into the output directory, replacing any existing destination.
§Errors
Returns an error if the destination is unsafe or the copy fails.
Sourcepub fn clean(&self, create_directory: bool) -> Result<()>
pub fn clean(&self, create_directory: bool) -> Result<()>
Removes the output directory, optionally recreating it empty.
§Errors
Returns an error if the output directory is unsafe to delete — empty, the
filesystem root, or containing a .. component. Winged-Swift’s version has no such
guard and will happily recurse through whatever it is pointed at.
Sourcepub fn write_file(&self, content: &str, path: &str) -> Result<()>
pub fn write_file(&self, content: &str, path: &str) -> Result<()>
Writes UTF-8 content to path, creating parent directories.
The write is atomic: content goes to a temporary file in the same directory and is then renamed, so a reader never sees a half-written page.
§Errors
Returns an error if the path escapes the output directory or the write fails.
Trait Implementations§
Source§impl Clone for StaticSiteGenerator
impl Clone for StaticSiteGenerator
Auto Trait Implementations§
impl Freeze for StaticSiteGenerator
impl RefUnwindSafe for StaticSiteGenerator
impl Send for StaticSiteGenerator
impl Sync for StaticSiteGenerator
impl Unpin for StaticSiteGenerator
impl UnsafeUnpin for StaticSiteGenerator
impl UnwindSafe for StaticSiteGenerator
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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