Fix SEO backward compatibility for versioned docs

Ref #25.
pull/308/merge
Thibaut Courouble 9 years ago
parent f7b213c4d3
commit 80436dcf9d

@ -32,6 +32,7 @@ class App < Sinatra::Application
Hash[JSON.parse(File.read(docs_manifest_path)).map! { |doc| Hash[JSON.parse(File.read(docs_manifest_path)).map! { |doc|
doc['full_name'] = doc['name'].dup doc['full_name'] = doc['name'].dup
doc['full_name'] << " #{doc['version']}" if doc['version'] doc['full_name'] << " #{doc['version']}" if doc['version']
doc['slug_without_version'] = doc['slug'].split('~').first
[doc['slug'], doc] [doc['slug'], doc]
}] }]
} }
@ -123,9 +124,8 @@ class App < Sinatra::Application
def find_doc(slug) def find_doc(slug)
settings.docs[slug] || begin settings.docs[slug] || begin
slug = "#{slug}~" settings.docs.each do |_, doc|
settings.docs.each do |_slug, _doc| return doc if doc['slug_without_version'] == slug
return _doc if _slug.start_with?(slug)
end end
nil nil
end end
@ -147,7 +147,7 @@ class App < Sinatra::Application
end end
def doc_index_page? def doc_index_page?
@doc && request.path == "/#{@doc['slug']}/" @doc && (request.path == "/#{@doc['slug']}/" || request.path == "/#{@doc['slug_without_version']}/")
end end
def query_string_for_redirection def query_string_for_redirection

Loading…
Cancel
Save