From f9905e6548ac1ef373a5bceda01a708ce32eedc1 Mon Sep 17 00:00:00 2001 From: Magnus Hoff Date: Mon, 6 Nov 2017 16:07:25 +0100 Subject: [PATCH] Avoid generating invalid diff links in changes feed --- src/resources/changes_resource.rs | 21 +++++++++++++-------- templates/changes.html | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/resources/changes_resource.rs b/src/resources/changes_resource.rs index 8515bd0..cfd8f94 100644 --- a/src/resources/changes_resource.rs +++ b/src/resources/changes_resource.rs @@ -219,7 +219,7 @@ impl Resource for ChangesResource { _latest: bool, - diff_link: String, + diff_link: Option, } impl<'a> Row<'a> { @@ -337,13 +337,18 @@ impl Resource for ChangesResource { _slug: x.slug, title: x.title, _latest: x.latest, - diff_link: format!("_diff/{}?{}", - x.article_id, - diff_resource::QueryParameters::new( - x.revision as u32 - 1, - x.revision as u32, - ) - ), + diff_link: + if x.revision > 1 { + Some(format!("_diff/{}?{}", + x.article_id, + diff_resource::QueryParameters::new( + x.revision as u32 - 1, + x.revision as u32, + ) + )) + } else { + None + }, } }).collect::>(); diff --git a/templates/changes.html b/templates/changes.html index 1dc4969..e4d3f4c 100644 --- a/templates/changes.html +++ b/templates/changes.html @@ -32,7 +32,7 @@ {{.title}} {{.created}} {{#show_authors?}}{{#..author}}{{.}}{{/..author}}{{^..author}}Anonymous{{/..author}}{{/show_authors}} - change + {{#.diff_link}}change{{/.diff_link}}{{^.diff_link}}new{{/.diff_link}} {{/changes}}