diff --git a/src/article_resource.rs b/src/article_resource.rs index a2e1fc4..bec1ed3 100644 --- a/src/article_resource.rs +++ b/src/article_resource.rs @@ -16,11 +16,12 @@ pub struct ArticleResource { state: State, article_id: i32, revision: i32, + edit: bool, } impl ArticleResource { - pub fn new(state: State, article_id: i32, revision: i32) -> Self { - Self { state, article_id, revision } + pub fn new(state: State, article_id: i32, revision: i32, edit: bool) -> Self { + Self { state, article_id, revision, edit } } } @@ -47,6 +48,7 @@ impl Resource for ArticleResource { revision: i32, created: &'a chrono::DateTime, + edit: bool, cancel_url: Option<&'a str>, title: &'a str, raw: &'a str, @@ -68,6 +70,7 @@ impl Resource for ArticleResource { article_id: data.article_id, revision: data.revision, created: &Local.from_utc_datetime(&data.created), + edit: self.edit, cancel_url: Some(&data.slug), title: &data.title, raw: &data.body, diff --git a/src/new_article_resource.rs b/src/new_article_resource.rs index 7b861a3..f302b55 100644 --- a/src/new_article_resource.rs +++ b/src/new_article_resource.rs @@ -56,6 +56,7 @@ impl Resource for NewArticleResource { revision: &'a str, created: &'a str, + edit: bool, cancel_url: Option<&'a str>, title: &'a str, raw: &'a str, @@ -76,6 +77,11 @@ impl Resource for NewArticleResource { article_id: NDASH, revision: NDASH, created: NDASH, + + // Implicitly start in edit-mode when no slug is given. This + // currently directly corresponds to the /_new endpoint + edit: self.slug.is_none(), + cancel_url: self.slug.as_ref().map(|x| &**x), title: &title, raw: "", diff --git a/src/wiki_lookup.rs b/src/wiki_lookup.rs index f58ef02..bceb8f7 100644 --- a/src/wiki_lookup.rs +++ b/src/wiki_lookup.rs @@ -59,7 +59,7 @@ impl Lookup for WikiLookup { type Error = Box<::std::error::Error + Send + Sync>; type Future = Box, Error = Self::Error>>; - fn lookup(&self, path: &str, _query: Option<&str>, _fragment: Option<&str>) -> Self::Future { + fn lookup(&self, path: &str, query: Option<&str>, _fragment: Option<&str>) -> Self::Future { assert!(path.starts_with("/")); if path.starts_with("/_") { @@ -92,14 +92,15 @@ impl Lookup for WikiLookup { } let state = self.state.clone(); + let edit = query == Some("edit"); use state::SlugLookup; Box::new(self.state.lookup_slug(slug.clone()) - .and_then(|x| Ok(Some(match x { + .and_then(move |x| Ok(Some(match x { SlugLookup::Miss => Box::new(NewArticleResource::new(state, Some(slug))) as BoxResource, SlugLookup::Hit { article_id, revision } => - Box::new(ArticleResource::new(state, article_id, revision)) as BoxResource, + Box::new(ArticleResource::new(state, article_id, revision, edit)) as BoxResource, SlugLookup::Redirect(slug) => Box::new(ArticleRedirectResource::new(slug)) as BoxResource, }))) diff --git a/templates/article_revision.html b/templates/article_revision.html index 4aea72e..359e50b 100644 --- a/templates/article_revision.html +++ b/templates/article_revision.html @@ -1,6 +1,6 @@ -
+
{{>article_revision_contents.html}}
@@ -32,7 +32,7 @@