Machine readable branding.

Include project name and version in Server header and generator meta tag
This commit is contained in:
Magnus Hoff 2017-11-01 13:15:42 +01:00
parent 2626223f10
commit 78bd53e640
2 changed files with 13 additions and 7 deletions

View file

@ -4,7 +4,7 @@
use std::fmt; use std::fmt;
use futures::{self, Future}; use futures::{self, Future};
use hyper::header::{Accept, ContentType}; use hyper::header::{Accept, ContentType, Server};
use hyper::mime; use hyper::mime;
use hyper::server::*; use hyper::server::*;
use hyper; use hyper;
@ -28,13 +28,11 @@ pub struct Layout<'a, T: 'a + fmt::Display> {
} }
impl<'a, T: 'a + fmt::Display> Layout<'a, T> { impl<'a, T: 'a + fmt::Display> Layout<'a, T> {
pub fn style_css_checksum(&self) -> &str { pub fn style_css_checksum(&self) -> &str { StyleCss::checksum() }
StyleCss::checksum() pub fn search_js_checksum(&self) -> &str { SearchJs::checksum() }
}
pub fn search_js_checksum(&self) -> &str { pub fn pkg_name(&self) -> &str { env!("CARGO_PKG_NAME") }
SearchJs::checksum() pub fn pkg_version(&self) -> &str { env!("CARGO_PKG_VERSION") }
}
} }
#[derive(BartDisplay)] #[derive(BartDisplay)]
@ -128,6 +126,13 @@ impl Service for Site {
None => Box::new(futures::finished(Self::not_found(base.as_ref().map(|x| &**x)))) None => Box::new(futures::finished(Self::not_found(base.as_ref().map(|x| &**x))))
}) })
.or_else(move |err| Ok(Self::internal_server_error(base2.as_ref().map(|x| &**x), err))) .or_else(move |err| Ok(Self::internal_server_error(base2.as_ref().map(|x| &**x), err)))
.map(|response| response
.with_header(Server::new(concat!(
env!("CARGO_PKG_NAME"),
"/",
env!("CARGO_PKG_VERSION")
)))
)
) )
} }
} }

View file

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