diff --git a/src/resources/about_resource.rs b/src/resources/about_resource.rs new file mode 100644 index 0000000..83d11fb --- /dev/null +++ b/src/resources/about_resource.rs @@ -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 { + 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) -> 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())) + })) + } +} diff --git a/src/resources/mod.rs b/src/resources/mod.rs index 748b4c1..a678634 100644 --- a/src/resources/mod.rs +++ b/src/resources/mod.rs @@ -1,5 +1,6 @@ pub mod pagination; +mod about_resource; mod article_revision_resource; mod article_resource; mod changes_resource; @@ -9,6 +10,7 @@ mod search_resource; mod sitemap_resource; mod temporary_redirect_resource; +pub use self::about_resource::AboutResource; pub use self::article_revision_resource::ArticleRevisionResource; pub use self::article_resource::ArticleResource; pub use self::changes_resource::{ChangesLookup, ChangesResource}; diff --git a/src/wiki_lookup.rs b/src/wiki_lookup.rs index 63a61fd..5be8382 100644 --- a/src/wiki_lookup.rs +++ b/src/wiki_lookup.rs @@ -139,6 +139,8 @@ impl WikiLookup { }; match (head.as_ref(), tail) { + ("_about", None) => + Box::new(finished(Some(Box::new(AboutResource::new()) as BoxResource))), ("_assets", Some(asset)) => Box::new(asset_lookup(asset)), ("_by_id", Some(tail)) => diff --git a/templates/about.html b/templates/about.html new file mode 100644 index 0000000..b8ee5f9 --- /dev/null +++ b/templates/about.html @@ -0,0 +1,23 @@ +
+
+

About Sausagewiki

+
+ +
+

This site is running version {{pkg_version()}} of Sausagewiki.

+

Sausagewiki is a simple, self-contained wiki engine.

+

Copyright © 2017 Magnus Hovland Hoff

+

+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. +

+ +

+Project home page +

+
+
+ +{{>footer/default.html}} diff --git a/templates/footer/items.html b/templates/footer/items.html index 2f779aa..41b1a54 100644 --- a/templates/footer/items.html +++ b/templates/footer/items.html @@ -4,4 +4,4 @@ >
  • Sitemap
  • Recent changes
  • -

    Powered by Sausagewiki

    +

    Powered by Sausagewiki