From 60dc242e5a62443ca1b0a350237744aad71c3594 Mon Sep 17 00:00:00 2001 From: Valentin Brandl Date: Wed, 12 Jun 2019 21:50:45 +0200 Subject: [PATCH] Add repo count to templates --- Cargo.lock | 6 +++--- Cargo.toml | 6 +++--- src/main.rs | 29 ++++++++++++++++++----------- src/statics.rs | 16 ---------------- templates/base.rs.html | 5 ++++- templates/generate.rs.html | 4 ++-- templates/index.rs.html | 4 ++-- templates/overview.rs.html | 4 ++-- templates/p404.rs.html | 4 ++-- templates/p500.rs.html | 4 ++-- 10 files changed, 38 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d0abb48..f248a37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -773,7 +773,7 @@ dependencies = [ "log4rs 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "number_prefix 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "reqwest 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)", + "reqwest 0.9.17 (registry+https://github.com/rust-lang/crates.io-index)", "ructe 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1558,7 +1558,7 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.9.18" +version = "0.9.17" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2562,7 +2562,7 @@ dependencies = [ "checksum regex 1.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0b2f0808e7d7e4fb1cb07feb6ff2f4bc827938f24f8c2e6a3beb7370af544bdd" "checksum regex-syntax 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d76410686f9e3a17f06128962e0ecc5755870bb890c34820c7af7f1db2e1d48" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" -"checksum reqwest 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)" = "00eb63f212df0e358b427f0f40aa13aaea010b470be642ad422bcbca2feff2e4" +"checksum reqwest 0.9.17 (registry+https://github.com/rust-lang/crates.io-index)" = "e57803405f8ea0eb041c1567dac36127e0c8caa1251c843cb03d43fd767b3d50" "checksum resolv-conf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b263b4aa1b5de9ffc0054a2386f96992058bb6870aab516f8cdeb8a667d56dcb" "checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" "checksum ructe 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "976a8c6d7b90407935443485911ba072dddbe188f14e173c687b16e0b5d22b43" diff --git a/Cargo.toml b/Cargo.toml index 62b174d..5d80d6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,9 +16,9 @@ log = "0.4.6" log4rs = "0.8.3" number_prefix = "0.3.0" openssl-probe = "0.1.2" -reqwest = "0.9.18" -serde = "1.0.92" -serde_derive = "1.0.92" +reqwest = "0.9.17" +serde = "1.0.91" +serde_derive = "1.0.91" serde_json = "1.0.39" structopt = "0.2.16" diff --git a/src/main.rs b/src/main.rs index 77568fc..6e35e27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ use crate::{ cache::CacheState, error::{Error, Result}, service::{Bitbucket, FormService, GitHub, Gitlab, Service}, - statics::{CLIENT, CSS, FAVICON, INDEX, OPT, P404, P500, VERSION_INFO}, + statics::{CLIENT, CSS, FAVICON, OPT, REPO_COUNT, VERSION_INFO}, }; use actix_web::{ error::ErrorBadRequest, @@ -192,7 +192,7 @@ fn calculate_hoc( data: web::Path<(String, String)>, ) -> impl Future { let mapper = |r| match r { - HocResult::NotFound => Ok(p404()), + HocResult::NotFound => p404(), HocResult::Hoc { hoc_pretty, .. } => { let badge_opt = BadgeOptions { subject: "Hits-of-Code".to_string(), @@ -225,7 +225,7 @@ fn overview( data: web::Path<(String, String)>, ) -> impl Future { let mapper = |r| match r { - HocResult::NotFound => Ok(p404()), + HocResult::NotFound => p404(), HocResult::Hoc { hoc, hoc_pretty, @@ -238,6 +238,7 @@ fn overview( templates::overview( &mut buf, VERSION_INFO, + REPO_COUNT.load(Ordering::Relaxed), &OPT.domain, &service_path, &url, @@ -259,10 +260,15 @@ fn overview( } #[get("/")] -fn index() -> HttpResponse { - HttpResponse::Ok() - .content_type("text/html") - .body(INDEX.as_slice()) +fn index() -> Result { + let mut buf = Vec::new(); + templates::index( + &mut buf, + VERSION_INFO, + REPO_COUNT.load(Ordering::Relaxed), + &OPT.domain, + )?; + Ok(HttpResponse::Ok().content_type("text/html").body(buf)) } #[post("/generate")] @@ -272,6 +278,7 @@ fn generate(params: web::Form) -> Result { templates::generate( &mut buf, VERSION_INFO, + REPO_COUNT.load(Ordering::Relaxed), &OPT.domain, params.service.url(), params.service.service(), @@ -285,10 +292,10 @@ fn generate(params: web::Form) -> Result { .streaming(rx_body.map_err(|_| ErrorBadRequest("bad request")))) } -fn p404() -> HttpResponse { - HttpResponse::NotFound() - .content_type("text/html") - .body(P404.as_slice()) +fn p404() -> Result { + let mut buf = Vec::new(); + templates::p404(&mut buf, VERSION_INFO, REPO_COUNT.load(Ordering::Relaxed))?; + Ok(HttpResponse::NotFound().content_type("text/html").body(buf)) } #[get("/tacit-css.min.css")] diff --git a/src/statics.rs b/src/statics.rs index fdf248a..2e4757e 100644 --- a/src/statics.rs +++ b/src/statics.rs @@ -1,4 +1,3 @@ -use crate::{config::Opt, templates}; use structopt::StructOpt; pub struct VersionInfo<'a> { @@ -16,19 +15,4 @@ pub(crate) const FAVICON: &[u8] = include_bytes!("../static/favicon32.png"); lazy_static! { pub(crate) static ref CLIENT: reqwest::Client = reqwest::Client::new(); pub(crate) static ref OPT: Opt = Opt::from_args(); - pub(crate) static ref INDEX: Vec = { - let mut buf = Vec::new(); - templates::index(&mut buf, VERSION_INFO, &OPT.domain).unwrap(); - buf - }; - pub(crate) static ref P404: Vec = { - let mut buf = Vec::new(); - templates::p404(&mut buf, VERSION_INFO).unwrap(); - buf - }; - pub(crate) static ref P500: Vec = { - let mut buf = Vec::new(); - templates::p500(&mut buf, VERSION_INFO).unwrap(); - buf - }; } diff --git a/templates/base.rs.html b/templates/base.rs.html index 0b3eb56..810cda9 100644 --- a/templates/base.rs.html +++ b/templates/base.rs.html @@ -1,6 +1,6 @@ @use crate::statics::VersionInfo; -@(title: &str, header: &str, content: Content, version_info: VersionInfo) +@(title: &str, header: &str, content: Content, version_info: VersionInfo, repo_count: usize) @@ -36,6 +36,9 @@
  • HoC v@version_info.version - @version_info.commit
  • +
  • + Currently serving @repo_count repositories +