Refactor build information and add more information #44

This commit is contained in:
Magnus Hoff 2017-11-20 10:12:10 +01:00
parent 990f570a31
commit 88b3df21c2
9 changed files with 39 additions and 10 deletions

2
Cargo.lock generated
View file

@ -579,7 +579,7 @@ dependencies = [
[[package]]
name = "sausagewiki"
version = "0.1.0"
version = "0.1.0-dev"
dependencies = [
"bart 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"bart_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -1,6 +1,6 @@
[package]
name = "sausagewiki"
version = "0.1.0"
version = "0.1.0-dev"
description = "A wiki engine"
authors = ["Magnus Hoff <maghoff@gmail.com>"]
license = "GPL-3.0"

22
src/build_config.rs Normal file
View file

@ -0,0 +1,22 @@
#![allow(dead_code)]
pub const PROJECT_NAME: &str = env!("CARGO_PKG_NAME");
lazy_static! {
pub static ref VERSION: String = || -> String {
#[allow(unused_mut)]
let mut components = Vec::<&'static str>::new();
#[cfg(debug_assertions)]
components.push("debug");
if components.len() > 0 {
format!("{} ({})", env!("CARGO_PKG_VERSION"), components.join(" "))
} else {
env!("CARGO_PKG_VERSION").to_string()
}
}();
pub static ref HTTP_SERVER: String =
format!("{}/{}", PROJECT_NAME, VERSION.as_str());
}

View file

@ -28,6 +28,7 @@ extern crate titlecase;
use std::net::{IpAddr, SocketAddr};
mod assets;
mod build_config;
mod db;
mod merge;
mod mimes;

View file

@ -1,8 +1,12 @@
#[macro_use] extern crate lazy_static;
extern crate clap;
extern crate sausagewiki;
use std::net::IpAddr;
mod build_config;
use build_config::*;
const DATABASE: &str = "DATABASE";
const TRUST_IDENTITY: &str = "trust-identity";
const ADDRESS: &str = "address";
@ -11,8 +15,8 @@ const PORT: &str = "port";
fn args<'a>() -> clap::ArgMatches<'a> {
use clap::{App, Arg};
App::new(env!("CARGO_PKG_NAME"))
.version(env!("CARGO_PKG_VERSION"))
App::new(PROJECT_NAME)
.version(VERSION.as_str())
.about(env!("CARGO_PKG_DESCRIPTION"))
.arg(Arg::with_name(DATABASE)
.help("Sets the database file to use")

View file

@ -3,6 +3,7 @@ use hyper;
use hyper::header::ContentType;
use hyper::server::*;
use build_config;
use mimes::*;
use site::Layout;
use web::{Resource, ResponseFuture};
@ -59,7 +60,7 @@ struct Template<'a> {
}
impl<'a> Template<'a> {
fn pkg_version(&self) -> &str { env!("CARGO_PKG_VERSION") }
fn version(&self) -> &str { &build_config::VERSION }
}
impl Resource for AboutResource {

View file

@ -10,13 +10,14 @@ use hyper::server::*;
use hyper;
use assets::{StyleCss, SearchJs};
use build_config;
use web::Lookup;
use wiki_lookup::WikiLookup;
lazy_static! {
static ref TEXT_HTML: mime::Mime = "text/html;charset=utf-8".parse().unwrap();
static ref SERVER: Server =
Server::new(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")));
Server::new(build_config::HTTP_SERVER.as_str());
}
header! { (XIdentity, "X-Identity") => [String] }
@ -33,8 +34,8 @@ impl<'a, T: 'a + fmt::Display> Layout<'a, T> {
pub fn style_css_checksum(&self) -> &str { StyleCss::checksum() }
pub fn search_js_checksum(&self) -> &str { SearchJs::checksum() }
pub fn pkg_name(&self) -> &str { env!("CARGO_PKG_NAME") }
pub fn pkg_version(&self) -> &str { env!("CARGO_PKG_VERSION") }
pub fn project_name(&self) -> &str { build_config::PROJECT_NAME }
pub fn version(&self) -> &str { build_config::VERSION.as_str() }
}
#[derive(BartDisplay)]

View file

@ -4,7 +4,7 @@
</header>
<article>
<p>This site is running version {{pkg_version()}} of Sausagewiki, a simple,
<p>This site is running version {{version()}} of Sausagewiki, a simple,
self-contained wiki engine.</p>
<p>Copyright &copy; 2017 Magnus Hovland Hoff.</p>
<p>

View file

@ -6,7 +6,7 @@
{{#base}}<base href="{{.}}">{{/base}}
<link rel=preload href="_assets/amatic-sc-v9-latin-regular.woff" as=font crossorigin>
<link href="_assets/style-{{style_css_checksum()}}.css" rel="stylesheet">
<meta name="generator" content="{{pkg_name()}} {{pkg_version()}}" />
<meta name="generator" content="{{project_name()}} {{version()}}" />
</head>
<body>
{{>search_input.html}}