From c997abb9efe5f66091abcaa9d4cc0f5b382b16f4 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Wed, 16 Oct 2013 23:46:28 -0400 Subject: [PATCH 1/2] Support a real 404 page. --- Gemfile | 1 + Gemfile.lock | 3 + config.ru | 22 +++--- source/404.html.erb | 157 ------------------------------------------- source/404.html.haml | 13 ++++ 5 files changed, 29 insertions(+), 167 deletions(-) delete mode 100644 source/404.html.erb create mode 100644 source/404.html.haml diff --git a/Gemfile b/Gemfile index 62125afb3..681963456 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ source "https://rubygems.org" gem "rake" gem "rack" gem "rack-rewrite" +gem "rack-contrib" group :development do gem "middleman", "~>3.1.5" diff --git a/Gemfile.lock b/Gemfile.lock index 881170a36..730ae13d6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -71,6 +71,8 @@ GEM rouge (~> 0.3.0) multi_json (1.8.1) rack (1.5.2) + rack-contrib (1.1.0) + rack (>= 0.9.1) rack-livereload (0.3.15) rack rack-rewrite (1.4.01) @@ -118,6 +120,7 @@ DEPENDENCIES middleman-livereload middleman-syntax rack + rack-contrib rack-rewrite rake redcarpet diff --git a/config.ru b/config.ru index 45c7d4ca1..4f26e34b7 100644 --- a/config.ru +++ b/config.ru @@ -1,6 +1,8 @@ require "rubygems" require "rack/rewrite" +require "rack/contrib/not_found" +require "rack/contrib/try_static" use Rack::Rewrite do r301 %r{/docs/yardoc/(.*)}, '/documentation/$1' @@ -10,20 +12,20 @@ use Rack::Rewrite do r301 '/documentation/_index.html', '/documentation/' r301 '/try', 'http://sassmeister.com' r301 '/try.html', 'http://sassmeister.com' - - rewrite(%r{^(.*)/([^/.]+)$}, lambda do |match, rack_env| - path = "#{File.dirname(__FILE__)}/build#{match[0]}" - next "#{match[1]}/#{match[2]}/index.html" if Dir.exists?(path) - next match[0] if File.exists?(path) - "#{match[0]}.html" - end) end if ENV["HEROKU"].nil? || ENV["HEROKU"] == 'false' require "middleman" - run Middleman.server + + server = Middleman.server + run Rack::Cascade.new([ + server, + lambda {|env| server.call(env.merge!('PATH_INFO' => '/404'))} + ]) else - use Rack::Static, :urls => [""], :root => 'build', :index => 'index.html' + use Rack::TryStatic, + :urls => ["/"], :root => 'build', :index => 'index.html', + :try => ['.html', '/index.html'] - run lambda {} + run Rack::NotFound.new("build/404/index.html") end diff --git a/source/404.html.erb b/source/404.html.erb deleted file mode 100644 index 5049bb6f1..000000000 --- a/source/404.html.erb +++ /dev/null @@ -1,157 +0,0 @@ - - - - - Page Not Found :( - - - -
-

Not found :(

-

Sorry, but the page you were trying to view does not exist.

-

It looks like this was the result of either:

- - - -
- - diff --git a/source/404.html.haml b/source/404.html.haml new file mode 100644 index 000000000..b452be784 --- /dev/null +++ b/source/404.html.haml @@ -0,0 +1,13 @@ +--- +title: "Not found :(" +--- + +%p Sorry, but the page you were trying to view does not exist. +%p It looks like this was the result of either: +%ul + %li a mistyped address + %li an out-of-date link + +:javascript + var GOOG_FIXURL_LANG = (navigator.language || '').slice(0,2),GOOG_FIXURL_SITE = location.host; +%script(src="//linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js") From d21bfb277e71f84aa26247503c4aac09e84a4ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=82=8D=CB=84=E0=B8=B8=2E=CD=A1=CB=B3=CC=AB=2E=CB=84?= =?UTF-8?q?=E0=B8=B8=E2=82=8E?= Date: Wed, 16 Oct 2013 23:49:48 -0700 Subject: [PATCH 2/2] adjusting 404 layout --- source/404.html.haml | 14 ++++++++++---- source/assets/css/404.css.scss | 21 +++++++++++++++++++++ source/layouts/head/_css.haml | 2 ++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 source/assets/css/404.css.scss diff --git a/source/404.html.haml b/source/404.html.haml index b452be784..3952fdf2e 100644 --- a/source/404.html.haml +++ b/source/404.html.haml @@ -2,12 +2,18 @@ title: "Not found :(" --- -%p Sorry, but the page you were trying to view does not exist. +- content_for :css do + = stylesheet_link_tag "404" + +- content_for :introduction do + Sorry, but the page you were trying to view does not exist. + %p It looks like this was the result of either: %ul %li a mistyped address %li an out-of-date link -:javascript - var GOOG_FIXURL_LANG = (navigator.language || '').slice(0,2),GOOG_FIXURL_SITE = location.host; -%script(src="//linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js") +- content_for :complementary do + :javascript + var GOOG_FIXURL_LANG = (navigator.language || '').slice(0,2),GOOG_FIXURL_SITE = location.host; + %script(src="//linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js") diff --git a/source/assets/css/404.css.scss b/source/assets/css/404.css.scss new file mode 100644 index 000000000..74e5300a5 --- /dev/null +++ b/source/assets/css/404.css.scss @@ -0,0 +1,21 @@ +@import "compass"; +@import "breakpoint"; + +@import "dependencies/layout"; +@import "dependencies/color"; + +@import "foundation/forms"; + +@import "components/forms"; +@import "components/buttons"; + +#goog-fixurl .content { + margin: 0; + padding: 0; +} + +#goog-wm-sb { + @extend .button; + @extend .primary; + @include leader; +} diff --git a/source/layouts/head/_css.haml b/source/layouts/head/_css.haml index fc923b7f1..e867a3876 100644 --- a/source/layouts/head/_css.haml +++ b/source/layouts/head/_css.haml @@ -1 +1,3 @@ = stylesheet_link_tag "sass" +- if content_for?(:css) + = yield_content :css