forked from slonk/bingus-blog
implement configuration for the custom templates directory and change the default
This commit is contained in:
parent
99e91db6aa
commit
3e32257e56
5 changed files with 14 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,4 +5,3 @@
|
|||
!/posts/README.md
|
||||
/cache
|
||||
/config.toml
|
||||
/custom
|
||||
|
|
|
@ -24,8 +24,8 @@ link = "https://..." # public url of the blog, required if rss is enabled
|
|||
[dirs]
|
||||
posts = "posts" # where posts are stored
|
||||
media = "media" # directory served under /media/
|
||||
custom_templates = "custom/templates" # custom templates dir
|
||||
custom_static = "custom/static" # custom static dir
|
||||
custom_templates = "templates" # custom templates dir
|
||||
custom_static = "static" # custom static dir
|
||||
# see CUSTOM.md for documentation
|
||||
[http]
|
||||
host = "0.0.0.0" # ip to listen on
|
||||
|
|
|
@ -10,8 +10,8 @@ customizing the error page, other than CSS, is not supported at this time.
|
|||
|
||||
## Custom Templates
|
||||
|
||||
custom templates are loaded from `custom/templates` by default and they are
|
||||
written in [Handlebars (the rust variant)](https://crates.io/crates/handlebars)
|
||||
custom templates are written in
|
||||
[Handlebars (the rust variant)](https://crates.io/crates/handlebars).
|
||||
|
||||
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
|
||||
is present.
|
||||
|
||||
|
|
|
@ -126,8 +126,8 @@ impl Default for DirsConfig {
|
|||
Self {
|
||||
posts: "posts".into(),
|
||||
media: "media".into(),
|
||||
custom_static: "custom/static".into(),
|
||||
custom_templates: "custom/templates".into(),
|
||||
custom_static: "static".into(),
|
||||
custom_templates: "templates".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -69,8 +69,8 @@ async fn main() -> eyre::Result<()> {
|
|||
|
||||
let start = Instant::now();
|
||||
// NOTE: use tokio::task::spawn_blocking if this ever turns into a concurrent task
|
||||
let mut reg =
|
||||
new_registry("custom/templates").context("failed to create handlebars registry")?;
|
||||
let mut reg = new_registry(&config.dirs.custom_templates)
|
||||
.context("failed to create handlebars registry")?;
|
||||
reg.register_helper("date", Box::new(helpers::date));
|
||||
reg.register_helper("duration", Box::new(helpers::duration));
|
||||
debug!(duration = ?start.elapsed(), "registered all templates");
|
||||
|
@ -88,8 +88,12 @@ async fn main() -> eyre::Result<()> {
|
|||
|
||||
debug!("setting up watcher");
|
||||
tasks.spawn(
|
||||
watch_templates("custom/templates", watcher_token.clone(), reg)
|
||||
.instrument(info_span!("custom_template_watcher")),
|
||||
watch_templates(
|
||||
config.dirs.custom_templates.clone(),
|
||||
watcher_token.clone(),
|
||||
reg,
|
||||
)
|
||||
.instrument(info_span!("custom_template_watcher")),
|
||||
);
|
||||
|
||||
if config.cache.enable && config.cache.cleanup {
|
||||
|
|
Loading…
Reference in a new issue