pub struct Site {
pub root: PathBuf,
pub html_files: Vec<PathBuf>,
}Expand description
A loaded view of a built site for audit gates to consume.
Walks the site directory once at construction time so each gate avoids redundant filesystem scans (the 15 gates would otherwise stat-walk the same tree 15 times).
Fields§
§root: PathBufRoot directory of the built site (the public/ output dir).
html_files: Vec<PathBuf>All .html files under the root, in directory-walk order.
Implementations§
Source§impl Site
impl Site
Sourcepub fn load(root: &Path) -> Result<Self, SsgError>
pub fn load(root: &Path) -> Result<Self, SsgError>
Loads a site from root, walking it for HTML files.
§Errors
Returns SsgError::Io if the directory walk fails.
§Examples
use ssg::audit::Site;
let tmp = tempfile::tempdir().unwrap();
let site = Site::load(tmp.path()).unwrap();
assert_eq!(site.root, tmp.path());
assert!(site.html_files.is_empty());Sourcepub fn rel(&self, path: &Path) -> String
pub fn rel(&self, path: &Path) -> String
Returns a relative path string for path against the site root,
always using / as the separator.
The separator is normalised because these strings are compared against
URL paths taken from the HTML — hreflang targets, canonical hrefs,
sitemap entries. On Windows the native separator made
en\index.html the key while the document said /en/index.html, so
no reciprocal pair ever matched and the hreflang gate reported both a
false negative and a false positive. A path used as a URL has one
separator, whatever the filesystem underneath calls it.
§Examples
use std::path::{Path, PathBuf};
use ssg::audit::Site;
let site = Site { root: PathBuf::from("/site"), html_files: Vec::new() };
assert_eq!(site.rel(Path::new("/site/blog/a.html")), "blog/a.html");Sourcepub fn read(&self, path: &Path) -> Result<String, SsgError>
pub fn read(&self, path: &Path) -> Result<String, SsgError>
Reads the contents of path as UTF-8.
§Errors
Returns SsgError::Io if reading fails.
§Examples
use std::path::PathBuf;
use ssg::audit::Site;
let tmp = tempfile::tempdir().unwrap();
let p = tmp.path().join("a.html");
std::fs::write(&p, "<html></html>").unwrap();
let site = Site { root: tmp.path().to_path_buf(), html_files: vec![p.clone()] };
assert_eq!(site.read(&p).unwrap(), "<html></html>");Trait Implementations§
Auto Trait Implementations§
impl Freeze for Site
impl RefUnwindSafe for Site
impl Send for Site
impl Sync for Site
impl Unpin for Site
impl UnsafeUnpin for Site
impl UnwindSafe for Site
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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