implement configuration for the custom templates directory and change the default

This commit is contained in:
slonkazoid 2024-08-13 17:02:33 +03:00
parent 99e91db6aa
commit 3e32257e56
Signed by: slonk
SSH key fingerprint: SHA256:tbZfJX4IOvZ0LGWOWu5Ijo8jfMPi78TU7x1VoEeCIjM
5 changed files with 14 additions and 12 deletions

1
.gitignore vendored
View file

@ -5,4 +5,3 @@
!/posts/README.md !/posts/README.md
/cache /cache
/config.toml /config.toml
/custom

View file

@ -24,8 +24,8 @@ link = "https://..." # public url of the blog, required if rss is enabled
[dirs] [dirs]
posts = "posts" # where posts are stored posts = "posts" # where posts are stored
media = "media" # directory served under /media/ media = "media" # directory served under /media/
custom_templates = "custom/templates" # custom templates dir custom_templates = "templates" # custom templates dir
custom_static = "custom/static" # custom static dir custom_static = "static" # custom static dir
# see CUSTOM.md for documentation # see CUSTOM.md for documentation
[http] [http]
host = "0.0.0.0" # ip to listen on host = "0.0.0.0" # ip to listen on

View file

@ -10,8 +10,8 @@ customizing the error page, other than CSS, is not supported at this time.
## Custom Templates ## Custom Templates
custom templates are loaded from `custom/templates` by default and they are custom templates are written in
written in [Handlebars (the rust variant)](https://crates.io/crates/handlebars) [Handlebars (the rust variant)](https://crates.io/crates/handlebars).
the *custom templates directory* has a non-recursive structure: the *custom templates directory* has a non-recursive structure:
@ -47,4 +47,3 @@ under `/static`.
the endpoint `/media` is served from `dirs.media`. no other logic or mechanism the endpoint `/media` is served from `dirs.media`. no other logic or mechanism
is present. is present.

View file

@ -126,8 +126,8 @@ impl Default for DirsConfig {
Self { Self {
posts: "posts".into(), posts: "posts".into(),
media: "media".into(), media: "media".into(),
custom_static: "custom/static".into(), custom_static: "static".into(),
custom_templates: "custom/templates".into(), custom_templates: "templates".into(),
} }
} }
} }

View file

@ -69,8 +69,8 @@ async fn main() -> eyre::Result<()> {
let start = Instant::now(); let start = Instant::now();
// NOTE: use tokio::task::spawn_blocking if this ever turns into a concurrent task // NOTE: use tokio::task::spawn_blocking if this ever turns into a concurrent task
let mut reg = let mut reg = new_registry(&config.dirs.custom_templates)
new_registry("custom/templates").context("failed to create handlebars registry")?; .context("failed to create handlebars registry")?;
reg.register_helper("date", Box::new(helpers::date)); reg.register_helper("date", Box::new(helpers::date));
reg.register_helper("duration", Box::new(helpers::duration)); reg.register_helper("duration", Box::new(helpers::duration));
debug!(duration = ?start.elapsed(), "registered all templates"); debug!(duration = ?start.elapsed(), "registered all templates");
@ -88,7 +88,11 @@ async fn main() -> eyre::Result<()> {
debug!("setting up watcher"); debug!("setting up watcher");
tasks.spawn( tasks.spawn(
watch_templates("custom/templates", watcher_token.clone(), reg) watch_templates(
config.dirs.custom_templates.clone(),
watcher_token.clone(),
reg,
)
.instrument(info_span!("custom_template_watcher")), .instrument(info_span!("custom_template_watcher")),
); );