Add repo count to templates
This commit is contained in:
parent
615460c87b
commit
60dc242e5a
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
29
src/main.rs
29
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<T: Service>(
|
||||
data: web::Path<(String, String)>,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||
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<T: Service>(
|
||||
data: web::Path<(String, String)>,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||
let mapper = |r| match r {
|
||||
HocResult::NotFound => Ok(p404()),
|
||||
HocResult::NotFound => p404(),
|
||||
HocResult::Hoc {
|
||||
hoc,
|
||||
hoc_pretty,
|
||||
@ -238,6 +238,7 @@ fn overview<T: Service>(
|
||||
templates::overview(
|
||||
&mut buf,
|
||||
VERSION_INFO,
|
||||
REPO_COUNT.load(Ordering::Relaxed),
|
||||
&OPT.domain,
|
||||
&service_path,
|
||||
&url,
|
||||
@ -259,10 +260,15 @@ fn overview<T: Service>(
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
fn index() -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html")
|
||||
.body(INDEX.as_slice())
|
||||
fn index() -> Result<HttpResponse> {
|
||||
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<GeneratorForm>) -> Result<HttpResponse> {
|
||||
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<GeneratorForm>) -> Result<HttpResponse> {
|
||||
.streaming(rx_body.map_err(|_| ErrorBadRequest("bad request"))))
|
||||
}
|
||||
|
||||
fn p404() -> HttpResponse {
|
||||
HttpResponse::NotFound()
|
||||
.content_type("text/html")
|
||||
.body(P404.as_slice())
|
||||
fn p404() -> Result<HttpResponse> {
|
||||
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")]
|
||||
|
@ -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<u8> = {
|
||||
let mut buf = Vec::new();
|
||||
templates::index(&mut buf, VERSION_INFO, &OPT.domain).unwrap();
|
||||
buf
|
||||
};
|
||||
pub(crate) static ref P404: Vec<u8> = {
|
||||
let mut buf = Vec::new();
|
||||
templates::p404(&mut buf, VERSION_INFO).unwrap();
|
||||
buf
|
||||
};
|
||||
pub(crate) static ref P500: Vec<u8> = {
|
||||
let mut buf = Vec::new();
|
||||
templates::p500(&mut buf, VERSION_INFO).unwrap();
|
||||
buf
|
||||
};
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
@ -36,6 +36,9 @@
|
||||
<li>
|
||||
<small>HoC v@version_info.version - <a href="https://github.com/vbrandl/hoc/commit/@version_info.commit">@version_info.commit</a></small>
|
||||
</li>
|
||||
<li>
|
||||
<small>Currently serving @repo_count repositories</small>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<nav>
|
||||
|
@ -1,7 +1,7 @@
|
||||
@use super::base;
|
||||
@use crate::statics::VersionInfo;
|
||||
|
||||
@(version_info: VersionInfo, domain: &str, url: &str, service: &str, path: &str)
|
||||
@(version_info: VersionInfo, repo_count: usize, domain: &str, url: &str, service: &str, path: &str)
|
||||
|
||||
@:base("Hits-of-Code Badges", "Badge Generator", {
|
||||
|
||||
@ -20,4 +20,4 @@ It will be rendered like this
|
||||
<pre>
|
||||
<a href="https://@domain/view/@service/@path"><img src="https://@domain/@service/@path" alt="example badge" /></a>
|
||||
</pre>
|
||||
}, version_info)
|
||||
}, version_info, repo_count)
|
||||
|
@ -1,7 +1,7 @@
|
||||
@use super::base;
|
||||
@use crate::statics::VersionInfo;
|
||||
|
||||
@(version_info: VersionInfo, domain: &str)
|
||||
@(version_info: VersionInfo, repo_count: usize, domain: &str)
|
||||
|
||||
@:base("Hits-of-Code Badges", "Hits-of-Code Badges", {
|
||||
|
||||
@ -76,4 +76,4 @@ my <a href="https://mirror.oldsql.cc/key.asc">GPG key</a>
|
||||
(<a href="http://pool.sks-keyservers.net/pks/lookup?op=get&search=0x1FFE431282F4B8CC0A7579167FB009175885FC76">from a
|
||||
keyserver</a>), or by using any other UID from my key.
|
||||
</p>
|
||||
}, version_info)
|
||||
}, version_info, repo_count)
|
||||
|
@ -1,7 +1,7 @@
|
||||
@use super::base;
|
||||
@use crate::statics::VersionInfo;
|
||||
|
||||
@(version_info: VersionInfo, domain: &str, path: &str, url: &str, hoc: u64, hoc_pretty: &str, head: &str, commit_url: &str)
|
||||
@(version_info: VersionInfo, repo_count: usize, domain: &str, path: &str, url: &str, hoc: u64, hoc_pretty: &str, head: &str, commit_url: &str)
|
||||
|
||||
@:base("Hits-of-Code Badges", "Overview", {
|
||||
|
||||
@ -16,4 +16,4 @@ To include the badge in your readme, use the following markdown:
|
||||
<pre>
|
||||
[![Hits-of-Code](https://@domain/@path)](https://@domain/view/@path)
|
||||
</pre>
|
||||
}, version_info)
|
||||
}, version_info, repo_count)
|
||||
|
@ -1,7 +1,7 @@
|
||||
@use super::base;
|
||||
@use crate::statics::VersionInfo;
|
||||
|
||||
@(version_info: VersionInfo)
|
||||
@(version_info: VersionInfo, repo_count: usize)
|
||||
|
||||
@:base("Page not Found - Hits-of-Code Badges", "404 - Page not Found", {
|
||||
<p>
|
||||
@ -11,4 +11,4 @@
|
||||
<p>
|
||||
If you think, this is a mistake on my side, please <a href="mailto:mail+hoc@@vbrandl.net">drop me a mail</a>.
|
||||
</p>
|
||||
}, version_info)
|
||||
}, version_info, repo_count)
|
||||
|
@ -1,7 +1,7 @@
|
||||
@use super::base;
|
||||
@use crate::statics::VersionInfo;
|
||||
|
||||
@(version_info: VersionInfo)
|
||||
@(version_info: VersionInfo, repo_count: usize)
|
||||
|
||||
@:base("Internal Server Error - Hits-of-Code Badges", "500 - Internal Server Error", {
|
||||
<p>
|
||||
@ -11,4 +11,4 @@
|
||||
<p>
|
||||
If you think, this is a bug, please <a href="mailto:mail+hoc@@vbrandl.net">drop me a mail</a>.
|
||||
</p>
|
||||
}, version_info)
|
||||
}, version_info, repo_count)
|
||||
|
Loading…
Reference in New Issue
Block a user