add --version flag
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
/target
|
||||
/html
|
||||
/html
|
||||
/src/version.rs
|
||||
|
||||
7
build.sh
7
build.sh
@@ -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
|
||||
|
||||
|
||||
11
src/main.rs
11
src/main.rs
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user