Restructure footer.

Less irrelevant information. Refactor rendering of "last updated"
This commit is contained in:
Magnus Hoff 2017-10-19 13:26:54 +02:00
parent f923b5b6c0
commit 904bfd2a0b
5 changed files with 44 additions and 41 deletions

View file

@ -67,9 +67,7 @@ function openEditor() {
// Update url-bar, page title and footer
window.history.replaceState(null, result.title, result.slug == "" ? "." : result.slug);
document.querySelector("title").textContent = result.title;
if (result.article_id != null) articleId.textContent = result.article_id;
revision.textContent = result.revision;
lastUpdated.textContent = result.created;
lastUpdated.textContent = result.last_updated;
// Update body:
rendered.innerHTML = result.rendered;

View file

@ -1,3 +1,4 @@
use chrono::{TimeZone, DateTime, Local};
use futures::{self, Future};
use hyper;
use hyper::header::ContentType;
@ -25,6 +26,20 @@ impl ArticleResource {
}
}
pub fn last_updated(created: &DateTime<Local>, author: Option<&str>) -> String {
#[derive(BartDisplay)]
#[template_string = "Last updated {{created}}{{#author}} by {{.}}{{/author}}"]
struct Template<'a> {
created: &'a str,
author: Option<&'a str>,
}
Template {
created: &created.to_rfc2822(),
author
}.to_string()
}
impl Resource for ArticleResource {
fn allow(&self) -> Vec<hyper::Method> {
use hyper::Method::*;
@ -39,15 +54,11 @@ impl Resource for ArticleResource {
}
fn get(self: Box<Self>) -> ResponseFuture {
use chrono::{TimeZone, Local};
#[derive(BartDisplay)]
#[template="templates/article_revision.html"]
struct Template<'a> {
article_id: i32,
revision: i32,
created: &'a str,
author: Option<&'a str>,
last_updated: &'a str,
edit: bool,
cancel_url: Option<&'a str>,
@ -69,10 +80,11 @@ impl Resource for ArticleResource {
base: None, // Hmm, should perhaps accept `base` as argument
title: &data.title,
body: &Template {
article_id: data.article_id,
revision: data.revision,
created: &Local.from_utc_datetime(&data.created).to_rfc2822(),
author: data.author.as_ref().map(|x| &**x),
last_updated: &last_updated(
&Local.from_utc_datetime(&data.created),
data.author.as_ref().map(|x| &**x)
),
edit: self.edit,
cancel_url: Some(&data.slug),
title: &data.title,
@ -88,7 +100,6 @@ impl Resource for ArticleResource {
fn put(self: Box<Self>, body: hyper::Body, identity: Option<String>) -> ResponseFuture {
// TODO Check incoming Content-Type
use chrono::{TimeZone, Local};
use futures::Stream;
#[derive(Deserialize)]
@ -111,7 +122,7 @@ impl Resource for ArticleResource {
revision: i32,
title: &'a str,
rendered: &'a str,
created: &'a str,
last_updated: &'a str,
}
Box::new(body
@ -136,7 +147,10 @@ impl Resource for ArticleResource {
title: &updated.title,
rendered: render_markdown(&updated.body),
}.to_string(),
created: &Local.from_utc_datetime(&updated.created).to_rfc2822(),
last_updated: &last_updated(
&Local.from_utc_datetime(&updated.created),
updated.author.as_ref().map(|x| &**x)
),
}).expect("Should never fail"))
)
})

View file

@ -52,10 +52,8 @@ impl Resource for NewArticleResource {
#[derive(BartDisplay)]
#[template="templates/article_revision.html"]
struct Template<'a> {
article_id: &'a str,
revision: &'a str,
created: &'a str,
author: Option<&'a str>,
last_updated: &'a str,
edit: bool,
cancel_url: Option<&'a str>,
@ -76,10 +74,8 @@ impl Resource for NewArticleResource {
base: None, // Hmm, should perhaps accept `base` as argument
title: &title,
body: &Template {
article_id: NDASH,
revision: NDASH,
created: NDASH,
author: None,
last_updated: NDASH,
// Implicitly start in edit-mode when no slug is given. This
// currently directly corresponds to the /_new endpoint
@ -98,6 +94,7 @@ impl Resource for NewArticleResource {
fn put(self: Box<Self>, body: hyper::Body, identity: Option<String>) -> ResponseFuture {
// TODO Check incoming Content-Type
// TODO Refactor. Reduce duplication with ArticleResource::put
use chrono::{TimeZone, Local};
use futures::Stream;
@ -123,7 +120,7 @@ impl Resource for NewArticleResource {
revision: i32,
title: &'a str,
rendered: &'a str,
created: &'a str,
last_updated: &'a str,
}
Box::new(body
@ -152,7 +149,10 @@ impl Resource for NewArticleResource {
title: &updated.title,
rendered: render_markdown(&updated.body),
}.to_string(),
created: &Local.from_utc_datetime(&updated.created).to_string(),
last_updated: &super::article_resource::last_updated(
&Local.from_utc_datetime(&updated.created),
updated.author.as_ref().map(|x| &**x)
),
}).expect("Should never fail"))
)
})

View file

@ -32,18 +32,9 @@
</div>
<footer>
<ul class="dense">
<li><a id="openEditor" href="?edit">Edit</a></li>
</ul>
<dl>
<dt>Article ID</dt>
<dd class="article-id">{{article_id}}</dd>
<dt>Revision</dt>
<dd class="revision">{{revision}}</dd>
<dt>Last updated</dt>
<dd class="last-updated">{{created}}{{#author}} by {{.}}{{/author}}</dd>
</dl>
<ul class="dense"
><li class="last-updated">{{last_updated}}</li
><li><a id="openEditor" href="?edit">Edit</a></li
></ul>
{{>footer/items.html}}
</footer>

View file

@ -1,7 +1,7 @@
<ul class="dense">
<li><a href=".">Home</a></li>
<li><a href="_new">Create article</a></li>
<li><a href="_sitemap">Sitemap</a></li>
<li><a href="_changes">Recent changes</a></li>
</ul>
<ul class="dense"
><li><a href=".">Home</a></li
><li><a href="_new">Create article</a></li
><li><a href="_sitemap">Sitemap</a></li
><li><a href="_changes">Recent changes</a></li
></ul>
<p>Powered by <a href="https://github.com/maghoff/sausagewiki">Sausagewiki</a></p>