add feature to set a custom path for static webdog resources

This commit is contained in:
zyl 2025-06-04 23:17:58 -07:00
parent b4088fb397
commit 3daa80f8af
Signed by: zyl
SSH key fingerprint: SHA256:uxxbSXbdroP/OnKBGnEDk5q7EKB2razvstC/KmzdXXs
2 changed files with 12 additions and 3 deletions

View file

@ -12,8 +12,8 @@ use url::Url;
use crate::{resource::ResourceBuilder, util, PageMetadata, Site, ROOT_PATH, SASS_PATH}; use crate::{resource::ResourceBuilder, util, PageMetadata, Site, ROOT_PATH, SASS_PATH};
/// Path for static webdog resources included with the site build. /// Default path for static webdog resources included with the site build.
const WEBDOG_PATH: &str = "webdog"; const WEBDOG_DEFAULT_PATH: &str = "webdog";
/// Struct containing data to be sent to templates when rendering them. /// Struct containing data to be sent to templates when rendering them.
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
@ -96,7 +96,13 @@ impl SiteBuilder {
std::fs::create_dir(&self.build_path).wrap_err("Failed to create build directory")?; std::fs::create_dir(&self.build_path).wrap_err("Failed to create build directory")?;
} }
let webdog_path = self.build_path.join(WEBDOG_PATH); let webdog_path = self.build_path.join(
self.site
.config
.webdog_path
.clone()
.unwrap_or_else(|| WEBDOG_DEFAULT_PATH.to_string()),
);
std::fs::create_dir(&webdog_path)?; std::fs::create_dir(&webdog_path)?;
std::fs::write( std::fs::write(
webdog_path.join("webdog.js"), webdog_path.join("webdog.js"),

View file

@ -49,6 +49,8 @@ pub struct SiteConfig {
pub sass_styles: Vec<PathBuf>, pub sass_styles: Vec<PathBuf>,
/// URL to the CDN used for the site's images. /// URL to the CDN used for the site's images.
pub cdn_url: Url, pub cdn_url: Url,
/// The path to output webdog static resources to. Defaults to "webdog"
pub webdog_path: Option<String>,
/// The theme to use for the site's code blocks. /// The theme to use for the site's code blocks.
/// TODO: dark/light themes /// TODO: dark/light themes
/// TODO: export themes as CSS instead of styling HTML directly /// TODO: export themes as CSS instead of styling HTML directly
@ -73,6 +75,7 @@ impl SiteConfig {
build: None, build: None,
sass_styles: vec!["index.scss".into()], sass_styles: vec!["index.scss".into()],
cdn_url, cdn_url,
webdog_path: None,
code_theme: "base16-ocean.dark".to_string(), code_theme: "base16-ocean.dark".to_string(),
resources: Default::default(), resources: Default::default(),
} }