1. Luke Plant
  2. haskellblog

Commits

Luke Plant  committed acf658a

Use templates for 404 page

  • Participants
  • Parent commits c67b906
  • Branches default

Comments (0)

Files changed (4)

File src/Blog/Templates.hs

View file
                          else pt ++ " « All Unkept"
 
 
--- Page specific templates
-
-custom404page =
-    page $ defaultPageVars
-             { pcontent = h1 << "404 Not Found"
-                          +++
-                          p << "Sorry, the page you requested could not be found"
-             , ptitle = "404 Not Found"
-             }
-
-
 commentNameLabel       = makeLabel "Name:" nameWidget
 commentNameWidget c    = setVal (Cm.name c) nameWidget
 commentEmailLabel      = makeLabel "Email:" emailWidget

File src/Blog/Views.hs

View file
                               addContent content
                              ] utf8HtmlResponse
 
+return404 :: View
+return404 req = do
+  resp <- custom404handler req
+  return $ Just $ resp
+
 -- | Custom 404 response
-custom404 :: Response
-custom404 = with (standardResponse custom404page) [
-             setStatus 404
-            ]
+custom404handler :: Request -> IO Response
+custom404handler req = do
+  t <- get_template "notfound"
+  return $ with (standardResponseBS $ render t) [
+                        setStatus 404
+                       ]
 
 -- Templates
 
   cn <- connect
   mcat <- getCategoryBySlug cn slug
   case mcat of
-    Nothing -> return $ Just $ custom404
+    Nothing -> return404 req
     Just cat -> do
               (posts,more) <- getPostsForCategory cn cat (getPage req)
               cats <- getCategoriesBulk cn posts
   cn <- connect
   mp <- getPostBySlug cn slug
   case mp of
-    Nothing -> return $ Just $ custom404 -- preferred to 'Nothing'
+    Nothing -> return404 req
     Just post -> do
             (commentStage, commentData, commentErrors) <- handleUserComment cn post req
             cats <- getCategoriesForPost cn post

File src/BlogCgi.hs

View file
 import Blog.Routes (views)
-import Blog.Views (custom404)
+import Blog.Views (custom404handler)
 import Database.HDBC
 import Ella.Framework
 import Ella.Processors.Security (signedCookiesProcessor)
 import qualified Blog.Settings as Settings
 
-options = defaultDispatchOptions { notFoundHandler = const $ return $ custom404
+options = defaultDispatchOptions { notFoundHandler = custom404handler
                                  , viewProcessors = [signedCookiesProcessor Settings.secret]
                                  }
 

File src/templates/notfound.st

View file
+$pagestart(pagetitle="404 Not Found")$
+ <h1>404 Not Found</h1>
+ <p>Sorry, the page you requested could not be found</p>
+$pageend()$