diff --git a/src/resources/temporary_redirect_resource.rs b/src/resources/temporary_redirect_resource.rs index aab660e..e9331d2 100644 --- a/src/resources/temporary_redirect_resource.rs +++ b/src/resources/temporary_redirect_resource.rs @@ -14,14 +14,18 @@ impl TemporaryRedirectResource { Self { location } } - pub fn from_slug>(slug: S) -> Self { + pub fn from_slug>(slug: S, edit: bool) -> Self { + let base = + if slug.as_ref().is_empty() { + "." + } else { + slug.as_ref() + }; + + let tail = if edit { "?edit" } else { "" }; + Self { - location: - if slug.as_ref().is_empty() { - "." - } else { - slug.as_ref() - }.to_owned() + location: format!("{}{}", base, tail) } } } diff --git a/src/wiki_lookup.rs b/src/wiki_lookup.rs index 2ac5ecc..fe84a39 100644 --- a/src/wiki_lookup.rs +++ b/src/wiki_lookup.rs @@ -220,16 +220,17 @@ impl WikiLookup { return Box::new(finished(None)); } + let edit = query == Some("edit"); + // Normalize all user-generated slugs: let slugified_slug = slugify(&slug); if slugified_slug != slug { return Box::new(finished(Some( - Box::new(TemporaryRedirectResource::from_slug(slugified_slug)) as BoxResource + Box::new(TemporaryRedirectResource::from_slug(slugified_slug, edit)) as BoxResource ))); } let state = self.state.clone(); - let edit = query == Some("edit"); let slug = slug.into_owned(); use state::SlugLookup; @@ -240,7 +241,7 @@ impl WikiLookup { SlugLookup::Hit { article_id, revision } => Box::new(ArticleResource::new(state, article_id, revision, edit)) as BoxResource, SlugLookup::Redirect(slug) => - Box::new(TemporaryRedirectResource::from_slug(slug)) as BoxResource, + Box::new(TemporaryRedirectResource::from_slug(slug, edit)) as BoxResource, }))) ) }