2013 年 12 月 2 日
关注 @ortaTL;DR:我们破坏了一些 URI,但这是我们确保人们仍然能获取他们正在寻找的信息的方式。
为了尝试简化您找到 CocoaPods 文档的位置,我们弃用了 docs.cocoapods.org,转而使用 guides.cocoapods.org,并且还会有更多关注不同内容的子站点。为了确保平稳过渡,我构建了一个小型 sinatra 应用程序,它可能对其他人有用。
虽然没有完全实现 W3C 梦想(内容改变但 URI 不变),但我认为智能 HTTP 302 永久重定向系统对我们的系统来说会非常优雅。以前我们有一个静态站点,它保存在 github 页面上,这意味着我们无法进行真正的重定向,只能使用 HTML 的属性 <meta http-equiv="refresh">
。这是一种对重定向使用大锤子的方法,而我们希望使用一个更小的工具。
因此,我拿出了 ruby(CocoaPods 构建的语言),并使用 sinatra 创建了一个小应用程序,可用于制作一个重定向目标 URL 的映射。幸运的是,文档中没有那么多页面,并且我们在指南中也有同等页面。然后将其变成一个 heroku 应用程序,并将其作为新的 docs.cocoapods.org,它会将人们悄无声息地重定向到新网站,其中包含他们正在寻找的相同信息。
require 'sinatra'
NEW_URL = "https://guides.cocoapods.org.cn"
ROUTES = {
"/" => "/",
# References
"/podfile.html" => "/syntax/podfile.html",
"/specification.html"=> "/syntax/podspec.html",
"/commands.html"=> "/terminal/commands.html",
# Guides
"/guides/philosophy.html"=> "/using/faq.html",
"/guides/installing_cocoapods.html" => "/using/getting-started.html",
"/guides/dependency_versioning.html" => "/using/the-podfile.html",
"/guides/closed_source_pods.html" => "/making/private-cocoapods.html",
"/guides/working_with_teams.html" => "/making/private-cocoapods.html",
"/guides/contributing_to_the_master_repo.html" => "/making/specs-and-specs-repo.html",
"/guides/creating_and_maintaining_a_pod.html" => "/making/specs-and-specs-repo.html#how-do-i-update-an-existing-pod?",
"/guides/creating_your_own_repository.html" => "/making/private-cocoapods.html",
# Gem specifics should be handled by rubydoc
"/cocoapods/*" => "http://rubydoc.info/gems/cocoapods",
"/cocoapods_core/*" => "http://rubydoc.info/gems/cocoapods-core",
"/xcodeproj/*" => "http://rubydoc.info/gems/xcodeproj",
"/claide/*" => "http://rubydoc.info/gems/claide",
"/cocoapods_downloader/*" => "http://rubydoc.info/gems/cocoapods-downloader"
}
ROUTES.each_key do |key|
# Create a sinatra route for each key, check if it's value starts with http
# and either redirect to the new site with the same query.
get key do
if (ROUTES[key][0..3] == "http")
redirect ROUTES[key], 302
else
url = NEW_URL + ROUTES[key] + request.query_string
redirect url, 302
end
end
end
# If we've missed anything just go to the root of the new URL
error Sinatra::NotFound do
redirect NEW_URL + request.query_string
end