Skip to content

Commit

Permalink
Merge pull request #38 from sass/404
Browse files Browse the repository at this point in the history
Support a real 404 page.
  • Loading branch information
₍˄ุ.͡˳̫.˄ุ₎ committed Oct 17, 2013
2 parents ed5d0a9 + d21bfb2 commit d34e931
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 167 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -118,6 +120,7 @@ DEPENDENCIES
middleman-livereload
middleman-syntax
rack
rack-contrib
rack-rewrite
rake
redcarpet
Expand Down
22 changes: 12 additions & 10 deletions config.ru
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -10,22 +12,22 @@ 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

use Rack::Deflater

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
157 changes: 0 additions & 157 deletions source/404.html.erb

This file was deleted.

19 changes: 19 additions & 0 deletions source/404.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: "Not found :("
---

- 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

- 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")
21 changes: 21 additions & 0 deletions source/assets/css/404.css.scss
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 2 additions & 0 deletions source/layouts/head/_css.haml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
= stylesheet_link_tag "sass"
- if content_for?(:css)
= yield_content :css

1 comment on commit d34e931

@jina
Copy link
Member

@jina jina commented on d34e931 Oct 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh weird. That looked fine locally but in prod doesn't look so good. No idea how to roll back deploys. :P

Please sign in to comment.