From 8d7f696deaaaeb9ed2f727c8ca454a0c9b39cdd6 Mon Sep 17 00:00:00 2001 From: Valentin Brandl Date: Tue, 23 Apr 2019 22:50:51 +0200 Subject: [PATCH] Make domain name configurable The domain name can be set using the `--domain` or `-d` flags. It defaults to `hitsofocode.com`. Also the CLI options are now parsed inside a lazy_static context to be available for the templates. --- src/main.rs | 13 ++++++++----- templates/index.rs.html | 8 ++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4187575..67310db 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,9 +39,10 @@ const VERSION: &str = env!("CARGO_PKG_VERSION"); lazy_static! { static ref CLIENT: reqwest::Client = reqwest::Client::new(); + static ref OPT: Opt = Opt::from_args(); static ref INDEX: Vec = { let mut buf = Vec::new(); - templates::index(&mut buf, COMMIT, VERSION).unwrap(); + templates::index(&mut buf, COMMIT, VERSION, &OPT.domain).unwrap(); buf }; static ref P404: Vec = { @@ -87,6 +88,9 @@ struct Opt { #[structopt(short = "h", long = "host", default_value = "0.0.0.0")] /// Interface to listen on host: String, + #[structopt(short = "d", long = "domain", default_value = "hitsofcode.com")] + /// Interface to listen on + domain: String, } fn pull(path: impl AsRef) -> Result<(), Error> { @@ -248,11 +252,10 @@ fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=warn"); pretty_env_logger::init(); openssl_probe::init_ssl_cert_env_vars(); - let opt = Opt::from_args(); - let interface = format!("{}:{}", opt.host, opt.port); + let interface = format!("{}:{}", OPT.host, OPT.port); let state = Arc::new(State { - repos: opt.outdir.display().to_string(), - cache: opt.cachedir.display().to_string(), + repos: OPT.outdir.display().to_string(), + cache: OPT.cachedir.display().to_string(), }); HttpServer::new(move || { App::new() diff --git a/templates/index.rs.html b/templates/index.rs.html index ae559e6..da129fe 100644 --- a/templates/index.rs.html +++ b/templates/index.rs.html @@ -1,6 +1,6 @@ @use super::base; -@(commit: &str, version: &str) +@(commit: &str, version: &str, domain: &str) @:base("Hits-of-Code Badges", "Hits-of-Code Badges", { @@ -23,7 +23,7 @@ used for GitHub, GitLab and Bitbucket repositories. Just put the following code

-[![Hits-of-Code](https://hitsofcode.com/<service>/<user>/<repo>)](https://hitsofcode.com/view/<service>/<user>/<repo>)
+[![Hits-of-Code](https://@domain/<service>/<user>/<repo>)](https://@domain/view/<service>/<user>/<repo>)
 

@@ -32,7 +32,7 @@ following Markdown

-[![Hits-of-Code](https://hitsofcode.com/github/vbrandl/hoc)](https://hitsofcode.com/view/github/vbrandl/hoc)
+[![Hits-of-Code](https://@domain/github/vbrandl/hoc)](https://@domain/view/github/vbrandl/hoc)
 

@@ -40,7 +40,7 @@ would render this badge:

-example badge