Permalink
Browse files

Move 301 redirect generation into rake task

  • Loading branch information...
durran committed May 27, 2012
1 parent a22ad17 commit faea3cdf1b2de41d48c6c6270552f512ec39838d
Showing with 85 additions and 116 deletions.
  1. +81 −0 Rakefile
  2. +0 −116 config.rb
  3. +4 −0 source/index.haml
View
@@ -0,0 +1,81 @@
+def write_redirect(page)
+ %{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <meta content="0; url=#{page}" http-equiv="Refresh"/>
+ </head>
+</html>}
+end
+
+MAPPINGS = {
+ "/docs.html" => "/en/mongoid/docs/installation.html",
+ "/docs/installation.html" => "/en/mongoid/docs/installation.html",
+ "/docs/installation/configuration.html" => "/en/mongoid/docs/installation.html",
+ "/docs/installation/languages.html" => "/en/mongoid/docs/installation.html",
+ "/docs/installation/replication.html" => "/en/mongoid/docs/installation.html",
+ "/docs/documents.html" => "/en/mongoid/docs/documents.html",
+ "/docs/documents/fields.html" => "/en/mongoid/docs/documents.html",
+ "/docs/documents/dynamic.html" => "/en/mongoid/docs/documents.html",
+ "/docs/documents/localized.html" => "/en/mongoid/docs/documents.html",
+ "/docs/documents/access.html" => "/en/mongoid/docs/documents.html",
+ "/docs/documents/dirty.html" => "/en/mongoid/docs/documents.html",
+ "/docs/documents/inheritance.html" => "/en/mongoid/docs/documents.html",
+ "/docs/persistence.html" => "/en/mongoid/docs/persistence.html",
+ "/docs/persistence/standard.html" => "/en/mongoid/docs/persistence.html",
+ "/docs/persistence/atomic.html" => "/en/mongoid/docs/persistence.html",
+ "/docs/persistence/safe_mode.html" => "/en/mongoid/docs/persistence.html",
+ "/docs/querying.html" => "/en/mongoid/docs/querying.html",
+ "/docs/querying/criteria.html" => "/en/mongoid/docs/querying.html",
+ "/docs/querying/modification.html" => "/en/mongoid/docs/querying.html",
+ "/docs/querying/finders.html" => "/en/mongoid/docs/querying.html",
+ "/docs/querying/scopes.html" => "/en/mongoid/docs/querying.html",
+ "/docs/relations.html" => "/en/mongoid/docs/relations.html",
+ "/docs/relations/embedded.html" => "/en/mongoid/docs/relations.html",
+ "/docs/relations/embedded/1-n.html" => "/en/mongoid/docs/relations.html",
+ "/docs/relations/embedded/1-1.html" => "/en/mongoid/docs/relations.html",
+ "/docs/relations/referenced.html" => "/en/mongoid/docs/relations.html",
+ "/docs/relations/referenced/1-n.html" => "/en/mongoid/docs/relations.html",
+ "/docs/relations/referenced/1-1.html" => "/en/mongoid/docs/relations.html",
+ "/docs/relations/referenced/n-n.html" => "/en/mongoid/docs/relations.html",
+ "/docs/relations/metadata.html" => "/en/mongoid/docs/relations.html",
+ "/docs/relations/validations.html" => "/en/mongoid/docs/relations.html",
+ "/docs/relations/nested_attributes.html" => "/en/mongoid/docs/relations.html",
+ "/docs/identity_map.html" => "/en/mongoid/docs/identity_map.html",
+ "/docs/callbacks.html" => "/en/mongoid/docs/callbacks.html",
+ "/docs/validation.html" => "/en/mongoid/docs/validation.html",
+ "/docs/indexing.html" => "/en/mongoid/docs/indexing.html",
+ "/docs/extras.html" => "/en/mongoid/docs/extras.html",
+ "/docs/rails.html" => "/en/mongoid/docs/rails.html",
+ "/docs/rails/multi_parameter_attributes.html" => "/en/mongoid/docs/rails.html",
+ "/docs/rails/rake.html" => "/en/mongoid/docs/rails.html",
+ "/docs/rails/railties.html" => "/en/mongoid/docs/rails.html",
+ "/docs/extensions.html" => "/en/mongoid/index.html",
+ "/docs/upgrading.html" => "/en/mongoid/docs/upgrading.html",
+ "/docs/contributing.html" => "/en/mongoid/docs/contributing.html",
+ "/performance.html" => "/en/mongoid/docs/performance.html",
+ "/credits.html" => "/en/mongoid/links.html",
+ "/links.html" => "/en/mongoid/links.html"
+}
+
+task :generate do
+ system "bundle exec middleman build"
+
+ puts "Generating 301 meta redirects."
+
+ Dir.mkdir("build/docs") unless Dir.exists?("build/docs")
+ Dir.mkdir("build/docs/installation") unless Dir.exists?("build/docs/installation")
+ Dir.mkdir("build/docs/documents") unless Dir.exists?("build/docs/documents")
+ Dir.mkdir("build/docs/persistence") unless Dir.exists?("build/docs/persistence")
+ Dir.mkdir("build/docs/querying") unless Dir.exists?("build/docs/querying")
+ Dir.mkdir("build/docs/relations") unless Dir.exists?("build/docs/relations")
+ Dir.mkdir("build/docs/relations/embedded") unless Dir.exists?("build/docs/relations/embedded")
+ Dir.mkdir("build/docs/relations/referenced") unless Dir.exists?("build/docs/relations/referenced")
+ Dir.mkdir("build/docs/rails") unless Dir.exists?("build/docs/rails")
+
+ MAPPINGS.each_pair do |old, new|
+ File.open("build#{old}", "w") do |file|
+ puts "Writing build#{old}"
+ file.write(write_redirect(new))
+ end
+ end
+end
View
116 config.rb
@@ -8,124 +8,8 @@
page "/en/origin/*", layout: "en/layouts/origin"
page "/en/moped/*", layout: "en/layouts/moped"
-page "/en/mongoid/*", layout: "en/layouts/mongoid"
-page "/en/origin/*", layout: "en/layouts/origin"
-page "/en/moped/*", layout: "en/layouts/moped"
-
-# We've revamped the entire set URL structure from the previous, so setup
-# the 301 redirects below.
-
-page "/" do
- redirect "/en/mongoid/index.html", 301
-end
-
-page "/index.html" do
- redirect "/en/mongoid/index.html", 301
-end
-
-page "/docs.html" do
- redirect "/en/mongoid/docs/installation.html", 301
-end
-
-page "/docs/installation.html" do
- redirect "/en/mongoid/docs/installation.html", 301
-end
-
-page "/docs/installation/*" do
- redirect "/en/mongoid/docs/installation.html", 301
-end
-
-page "/docs/documents.html" do
- redirect "/en/mongoid/docs/documents.html", 301
-end
-
-page "/docs/documents/*" do
- redirect "/en/mongoid/docs/documents.html", 301
-end
-
-page "/docs/persistence.html" do
- redirect "/en/mongoid/docs/persistence.html", 301
-end
-
-page "/docs/persistence/*" do
- redirect "/en/mongoid/docs/persistence.html", 301
-end
-
-page "/docs/querying.html" do
- redirect "/en/mongoid/docs/querying.html", 301
-end
-
-page "/docs/querying/*" do
- redirect "/en/mongoid/docs/querying.html", 301
-end
-
-page "/docs/relations.html" do
- redirect "/en/mongoid/docs/relations.html", 301
-end
-
-page "/docs/relations/*" do
- redirect "/en/mongoid/docs/relations.html", 301
-end
-
-page "/docs/identity_map.html" do
- redirect "/en/mongoid/docs/identity_map.html", 301
-end
-
-page "/docs/callbacks.html" do
- redirect "/en/mongoid/docs/callbacks.html", 301
-end
-
-page "/docs/callbacks/*" do
- redirect "/en/mongoid/docs/callbacks.html", 301
-end
-
-page "/docs/validation.html" do
- redirect "/en/mongoid/docs/validation.html", 301
-end
-
-page "/docs/indexing.html" do
- redirect "/en/mongoid/docs/indexing.html", 301
-end
-
-page "/docs/extras.html" do
- redirect "/en/mongoid/docs/extras.html", 301
-end
-
-page "/docs/rails.html" do
- redirect "/en/mongoid/docs/rails.html", 301
-end
-
-page "/docs/rails/*" do
- redirect "/en/mongoid/docs/rails.html", 301
-end
-
-page "/docs/extensions.html" do
- redirect "/en/mongoid/index.html", 301
-end
-
-page "/docs/upgrading.html" do
- redirect "/en/mongoid/docs/upgrading.html", 301
-end
-
-page "/docs/contributing.html" do
- redirect "/en/mongoid/docs/contributing.html", 301
-end
-
-page "/performance.html" do
- redirect "/en/mongoid/docs/performance.html", 301
-end
-
-page "/credits.html" do
- redirect "/en/mongoid/links.html", 301
-end
-
-page "/links.html" do
- redirect "/en/mongoid/links.html", 301
-end
-
configure :build do
activate :minify_css
- activate :smusher
end
ignore "/en/layouts/mongoid.haml"
View
@@ -0,0 +1,4 @@
+!!! Strict
+%html
+ %head
+ %meta{:"http-equiv" => "Refresh", content: "0; url=/en/mongoid/index.html"}

0 comments on commit faea3cd

Please sign in to comment.