add --version flag

This commit is contained in:
2025-08-26 00:07:59 +02:00
parent ad582caa5b
commit e83a9f3f51
4 changed files with 35 additions and 4 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
/target
/html
/src/version.rs

View File

@@ -1,5 +1,12 @@
#!/bin/sh
rm webTemplate-*
version="$(cat Cargo.toml | grep '^version' | sed -e 's/^.*"\([^"]*\)".*$/\1/')"
commit="$(git show --oneline -s | sed -e 's/ .*$//')"
dirty="$(test "$(git diff --shortstat 2> /dev/null | tail -n1)" == "" || echo -n "_drity" )"
echo "pub const VERSION: &'static str = \"${version} (${commit}${dirty})\";" >src/version.rs
cross build --target aarch64-unknown-linux-gnu --release
cargo build --release

View File

@@ -4,6 +4,9 @@ use minijinja::Environment;
mod render;
use render::{Renderer, IndexItem, build_jinja_env, Template};
mod version;
use version::VERSION;
const SRC_PATH: &'static str = "./src/";
const OUT_PATH: &'static str = "./html/";
@@ -97,6 +100,10 @@ fn render_index(
}
}
fn version() {
println!("version: {}", VERSION);
}
fn usage() {
println!("webtemplate [--output=<dir>] [--src=<dir>]");
}
@@ -148,6 +155,10 @@ fn main() {
"help" => {
usage();
}
"version" => {
version();
return;
}
_ => {
println!("ERROR: invalid option {}", option);
usage();

View File

@@ -98,14 +98,26 @@ impl Renderer {
let split = indexer::split_params(content);
match parse_md(split.md, jinja_env) {
Some(md) => {
let template = jinja_env.get_template(&page.template).unwrap();
let html = template.render(context! {
let template = match jinja_env.get_template(&page.template) {
Ok(templ) => templ,
Err(_) => {
println!("ERROR: jinja: failed to get template");
return None;
},
};
let html = match template.render(context! {
index => index.to_minijinja(),
is_error_not_found => false,
url => page.get_url(),
body => md,
params => Renderer::convert_yaml(split.yaml)
}).unwrap();
}) {
Ok(out) => out,
Err(_) => {
println!("ERROR: jinja: failed to render template");
return None;
},
};
Some(html)
},