From 80436dcf9d6a0a93109cbb9edc9459d728ed2e2e Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 24 Jan 2016 16:49:58 -0500 Subject: [PATCH] Fix SEO backward compatibility for versioned docs Ref #25. --- lib/app.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/app.rb b/lib/app.rb index 37e10012..55704afa 100644 --- a/lib/app.rb +++ b/lib/app.rb @@ -32,6 +32,7 @@ class App < Sinatra::Application Hash[JSON.parse(File.read(docs_manifest_path)).map! { |doc| doc['full_name'] = doc['name'].dup doc['full_name'] << " #{doc['version']}" if doc['version'] + doc['slug_without_version'] = doc['slug'].split('~').first [doc['slug'], doc] }] } @@ -123,9 +124,8 @@ class App < Sinatra::Application def find_doc(slug) settings.docs[slug] || begin - slug = "#{slug}~" - settings.docs.each do |_slug, _doc| - return _doc if _slug.start_with?(slug) + settings.docs.each do |_, doc| + return doc if doc['slug_without_version'] == slug end nil end @@ -147,7 +147,7 @@ class App < Sinatra::Application end def doc_index_page? - @doc && request.path == "/#{@doc['slug']}/" + @doc && (request.path == "/#{@doc['slug']}/" || request.path == "/#{@doc['slug_without_version']}/") end def query_string_for_redirection