mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
Add redirections for deleted docs
This commit is contained in:
parent
a772242694
commit
01517f8c78
2 changed files with 25 additions and 1 deletions
|
@ -270,8 +270,14 @@ class App < Sinatra::Application
|
|||
settings.news_feed
|
||||
end
|
||||
|
||||
DOC_REDIRECTS = {
|
||||
'iojs' => 'node',
|
||||
'yii1' => 'yii~1.1',
|
||||
'python2' => 'python~2.7'
|
||||
}
|
||||
|
||||
get %r{\A/([\w~\.]+)(\-[\w\-]+)?(/.*)?\z} do |doc, type, rest|
|
||||
return redirect "/node#{type}#{rest}" if doc == 'iojs'
|
||||
return redirect "/#{DOC_REDIRECTS[doc]}#{type}#{rest}" if DOC_REDIRECTS.key?(doc)
|
||||
return 404 unless @doc = find_doc(doc)
|
||||
|
||||
if rest.nil?
|
||||
|
|
|
@ -173,6 +173,12 @@ class AppTest < MiniTest::Spec
|
|||
assert last_response.redirect?
|
||||
assert_equal 'http://example.org/html/?bar=baz', last_response['Location']
|
||||
end
|
||||
|
||||
it "redirects old docs" do
|
||||
get '/iojs/'
|
||||
assert last_response.redirect?
|
||||
assert_equal 'http://example.org/node/', last_response['Location']
|
||||
end
|
||||
end
|
||||
|
||||
describe "/[doc]-[type]" do
|
||||
|
@ -212,6 +218,12 @@ class AppTest < MiniTest::Spec
|
|||
assert last_response.redirect?
|
||||
assert_equal 'http://example.org/css-foo/?bar=baz', last_response['Location']
|
||||
end
|
||||
|
||||
it "redirects old docs" do
|
||||
get '/yii1-foo/'
|
||||
assert last_response.redirect?
|
||||
assert_equal 'http://example.org/yii~1.1-foo/', last_response['Location']
|
||||
end
|
||||
end
|
||||
|
||||
describe "/[doc+type]/[path]" do
|
||||
|
@ -237,6 +249,12 @@ class AppTest < MiniTest::Spec
|
|||
assert last_response.redirect?
|
||||
assert_equal 'http://example.org/css/foo?bar=baz', last_response['Location']
|
||||
end
|
||||
|
||||
it "redirects old docs" do
|
||||
get '/python2/foo'
|
||||
assert last_response.redirect?
|
||||
assert_equal 'http://example.org/python~2.7/foo', last_response['Location']
|
||||
end
|
||||
end
|
||||
|
||||
describe "/docs.json" do
|
||||
|
|
Loading…
Reference in a new issue