Luke Plant avatar Luke Plant committed acf658a

Use templates for 404 page

Comments (0)

Files changed (4)

src/Blog/Templates.hs

                          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

src/Blog/Views.hs

                               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
 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]
                                  }
 

src/templates/notfound.st

+$pagestart(pagetitle="404 Not Found")$
+ <h1>404 Not Found</h1>
+ <p>Sorry, the page you requested could not be found</p>
+$pageend()$
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.