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
3232 Hash[JSON.parse(File.read(docs_manifest_path)).map! { |doc|
3333 doc['full_name'] = doc['name'].dup
3434 doc['full_name'] << " #{doc['version']}" if doc['version']
35+ doc['slug_without_version'] = doc['slug'].split('~').first
3536 [doc['slug'], doc]
3637 }]
3738 }
@@ -123,9 +124,8 @@ class App < Sinatra::Application · 85 unmodified lines
123124
124125 def find_doc(slug)
125126 settings.docs[slug] || begin
126− slug = "#{slug}~"
127− settings.docs.each do |_slug, _doc|
128− return _doc if _slug.start_with?(slug)
127+ settings.docs.each do |_, doc|
128+ return doc if doc['slug_without_version'] == slug
129129 end
130130 nil
131131 end
@@ -147,7 +147,7 @@ class App < Sinatra::Application · 15 unmodified lines
147147 end
148148
149149 def doc_index_page?
150− @doc && request.path == "/#{@doc['slug']}/"
150+ @doc && (request.path == "/#{@doc['slug']}/" || request.path == "/#{@doc['slug_without_version']}/")
151151 end
152152
153153 def query_string_for_redirection