From 2bdfa92d3e2b9ce72ab73fa6f55ad74f994082da Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 6 Feb 2025 17:04:11 +0100 Subject: [PATCH] Implement per-host templates Fixes #7. Signed-off-by: Gergely Nagy --- docs/content/configuration/templating.md | 4 +++- src/assembled_statistical_sequences.rs | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/content/configuration/templating.md b/docs/content/configuration/templating.md index 73b813f..c991e2b 100644 --- a/docs/content/configuration/templating.md +++ b/docs/content/configuration/templating.md @@ -3,7 +3,9 @@ title: Templating description: Changing the Iocaine template --- -`iocaine` uses [Handlebars](https://handlebarsjs.com/) for templating, and uses only a single template, `main`. See the Handlebars for basic syntax. A [default template][template:Default] is provided, but if you want to change it, you can configure a [template directory](@/configuration/index.md#templates), and place a customized `main.hbs` file in it, and `iocane` will use that over the default. +`iocaine` uses [Handlebars](https://handlebarsjs.com/) for templating, and will look for a template named `hosts/$host.hbs` (where `$host` is whatever is in the hosts header), but fall back on `main`, if a host-specific template is not found. + +See the Handlebars for basic syntax. A [default template][template:Default] is provided, but if you want to change it, you can configure a [template directory](@/configuration/index.md#templates), and place a customized `main.hbs` file in it, and `iocane` will use that over the default. Naturally, you can also place host-specific templates in a `hosts/` subdirectory. [template:default]: https://git.madhouse-project.org/algernon/iocaine/src/branch/main/templates/main.hbs diff --git a/src/assembled_statistical_sequences.rs b/src/assembled_statistical_sequences.rs index 2e94cdc..33da9b2 100644 --- a/src/assembled_statistical_sequences.rs +++ b/src/assembled_statistical_sequences.rs @@ -144,6 +144,11 @@ impl AssembledStatisticalSequences { links, }; - handlebars.render("main", &data).unwrap() + let host_template = &format!("hosts/{}", host); + if handlebars.has_template(host_template) { + handlebars.render(host_template, &data).unwrap() + } else { + handlebars.render("main", &data).unwrap() + } } }