Add a bare bones _about page. #10

This commit is contained in:
Magnus Hoff 2017-11-01 15:38:50 +01:00
parent 78bd53e640
commit 63b9715550
5 changed files with 80 additions and 1 deletions

View file

@ -0,0 +1,52 @@
use futures::{self, Future};
use hyper;
use hyper::header::ContentType;
use hyper::server::*;
use mimes::*;
use site::Layout;
use web::{Resource, ResponseFuture};
pub struct AboutResource;
impl AboutResource {
pub fn new() -> Self {
AboutResource
}
}
#[derive(BartDisplay)]
#[template="templates/about.html"]
struct Template;
impl Template {
fn pkg_version(&self) -> &str { env!("CARGO_PKG_VERSION") }
}
impl Resource for AboutResource {
fn allow(&self) -> Vec<hyper::Method> {
use hyper::Method::*;
vec![Options, Head, Get]
}
fn head(&self) -> ResponseFuture {
Box::new(futures::finished(Response::new()
.with_status(hyper::StatusCode::Ok)
.with_header(ContentType(TEXT_HTML.clone()))
))
}
fn get(self: Box<Self>) -> ResponseFuture {
let head = self.head();
Box::new(head
.and_then(move |head| {
Ok(head
.with_body(Layout {
base: None, // Hmm, should perhaps accept `base` as argument
title: "About Sausagewiki",
body: &Template,
}.to_string()))
}))
}
}

View file

@ -1,5 +1,6 @@
pub mod pagination; pub mod pagination;
mod about_resource;
mod article_revision_resource; mod article_revision_resource;
mod article_resource; mod article_resource;
mod changes_resource; mod changes_resource;
@ -9,6 +10,7 @@ mod search_resource;
mod sitemap_resource; mod sitemap_resource;
mod temporary_redirect_resource; mod temporary_redirect_resource;
pub use self::about_resource::AboutResource;
pub use self::article_revision_resource::ArticleRevisionResource; pub use self::article_revision_resource::ArticleRevisionResource;
pub use self::article_resource::ArticleResource; pub use self::article_resource::ArticleResource;
pub use self::changes_resource::{ChangesLookup, ChangesResource}; pub use self::changes_resource::{ChangesLookup, ChangesResource};

View file

@ -139,6 +139,8 @@ impl WikiLookup {
}; };
match (head.as_ref(), tail) { match (head.as_ref(), tail) {
("_about", None) =>
Box::new(finished(Some(Box::new(AboutResource::new()) as BoxResource))),
("_assets", Some(asset)) => ("_assets", Some(asset)) =>
Box::new(asset_lookup(asset)), Box::new(asset_lookup(asset)),
("_by_id", Some(tail)) => ("_by_id", Some(tail)) =>

23
templates/about.html Normal file
View file

@ -0,0 +1,23 @@
<div class="container">
<header>
<h1>About Sausagewiki</h1>
</header>
<article>
<p>This site is running version {{pkg_version()}} of Sausagewiki.</p>
<p>Sausagewiki is a simple, self-contained wiki engine.</p>
<p>Copyright &copy; 2017 Magnus Hovland Hoff</p>
<p>
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
</p>
<p>
<a href="https://github.com/maghoff/sausagewiki">Project home page</a>
</p>
</article>
</div>
{{>footer/default.html}}

View file

@ -4,4 +4,4 @@
><li><a href="_sitemap">Sitemap</a></li ><li><a href="_sitemap">Sitemap</a></li
><li><a href="_changes">Recent changes</a></li ><li><a href="_changes">Recent changes</a></li
></ul> ></ul>
<p>Powered by <a href="https://github.com/maghoff/sausagewiki">Sausagewiki</a></p> <p>Powered by <a href="_about">Sausagewiki</a></p>