History

Fix SEO backward compatibility for versioned docs

Ref #25.

Thibaut Courouble committed 10 years ago

Commit 80436dc1 parent f7b213c1 file · +4 −4Browse files

Unified · Split

lib/app.rb+4−4
@@ -32,6 +32,7 @@ class App < Sinatra::Application · 31 unmodified lines
32 Hash[JSON.parse(File.read(docs_manifest_path)).map! { |doc|32 Hash[JSON.parse(File.read(docs_manifest_path)).map! { |doc|
33 doc['full_name'] = doc['name'].dup33 doc['full_name'] = doc['name'].dup
34 doc['full_name'] << " #{doc['version']}" if doc['version']34 doc['full_name'] << " #{doc['version']}" if doc['version']
35 doc['slug_without_version'] = doc['slug'].split('~').first
35 [doc['slug'], doc]36 [doc['slug'], doc]
36 }]37 }]
37 }38 }
@@ -123,9 +124,8 @@ class App < Sinatra::Application · 85 unmodified lines
123 124
124 def find_doc(slug)125 def find_doc(slug)
125 settings.docs[slug] || begin126 settings.docs[slug] || begin
126 slug = "#{slug}~"127 settings.docs.each do |_, doc|
127 settings.docs.each do |_slug, _doc|128 return doc if doc['slug_without_version'] == slug
128 return _doc if _slug.start_with?(slug)
129 end129 end
130 nil130 nil
131 end131 end
@@ -147,7 +147,7 @@ class App < Sinatra::Application · 15 unmodified lines
147 end147 end
148 148
149 def doc_index_page?149 def doc_index_page?
150 @doc && request.path == "/#{@doc['slug']}/"150 @doc && (request.path == "/#{@doc['slug']}/" || request.path == "/#{@doc['slug_without_version']}/")
151 end151 end
152 152
153 def query_string_for_redirection153 def query_string_for_redirection