From a796f299a427cfe7175d9c8e5b4b8e66ba6a7b1a Mon Sep 17 00:00:00 2001 From: Magnus Hoff Date: Mon, 6 Nov 2017 16:26:37 +0100 Subject: [PATCH] Add link to diff view from article revision --- src/resources/article_revision_resource.rs | 14 ++++++++++++++ templates/article_revision.html | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/src/resources/article_revision_resource.rs b/src/resources/article_revision_resource.rs index 05297b3..862cbac 100644 --- a/src/resources/article_revision_resource.rs +++ b/src/resources/article_revision_resource.rs @@ -11,6 +11,7 @@ use site::Layout; use web::{Resource, ResponseFuture}; use super::changes_resource::QueryParameters; +use super::diff_resource; use super::pagination::Pagination; pub struct ArticleRevisionResource { @@ -79,6 +80,7 @@ impl Resource for ArticleRevisionResource { struct Template<'a> { link_current: &'a str, timestamp_and_author: &'a str, + diff_link: Option, title: &'a str, rendered: String, @@ -101,6 +103,18 @@ impl Resource for ArticleRevisionResource { &Local.from_utc_datetime(&data.created), data.author.as_ref().map(|x| &**x) ), + diff_link: + if data.revision > 1 { + Some(format!("_diff/{}?{}", + data.article_id, + diff_resource::QueryParameters::new( + data.revision as u32 - 1, + data.revision as u32, + ) + )) + } else { + None + }, title: &data.title, rendered: render_markdown(&data.body), }, diff --git a/templates/article_revision.html b/templates/article_revision.html index 3b5340e..498a0d9 100644 --- a/templates/article_revision.html +++ b/templates/article_revision.html @@ -5,6 +5,10 @@ You are viewing an historical version of this article, authored at {{{timestamp_and_author}}}.

+

+ {{#diff_link}}See the changes made for this revision.{{/diff_link}} + {{^diff_link}}This is the first revision of the article.{{/diff_link}} +