Commits

Luke Plant committed 1f1a44d

Re-implemented 'category' page using HStringTemplate

And removed some unused code

Comments (0)

Files changed (3)

src/Blog/Templates.hs

              , ptitle = "404 Not Found"
              }
 
-mainIndexPage :: [(P.Post, [C.Category])] -- ^ list of posts (wtth their categories) to display
-              -> Int                      -- ^ current page number being displayed
-              -> Bool                     -- ^ True if there are more pages to display
-              -> Html
-mainIndexPage postInfo curpage moreposts =
-    page $ defaultPageVars
-             { pcontent = formatIndex "Recent posts" indexUrl postInfo curpage moreposts
-             , ptitle = ""
-             }
-
-formatIndex :: String -> String -> [(P.Post, [C.Category])] -> Int -> Bool -> Html
-formatIndex title url postInfo curpage shownext =
-    (h1 << title)
-    +++
-    (do (post, cats) <- postInfo
-        return (
-                (thediv ! [ theclass "summarylink" ]
-                 << postLink post)
-                +++
-                (metaInfoLine post cats "metainfoindex")
-                +++
-                (thediv ! [ theclass "summary" ]
-                 << (primHtml $ P.summary_formatted post))
-               )
-    ) +++ (
-           pagingLinks url curpage shownext
-          )
-
-formatCategoryLink cat =
-    (thediv ! [theclass "category"]
-     << categoryLink cat)
-
-categoryPage :: C.Category -> [(P.Post, [C.Category])] -> Int -> Bool -> Html
-categoryPage cat posts curpage moreposts =
-    page $ defaultPageVars
-         { pcontent = formatIndex ("Category: " ++ C.name cat) (categoryUrl cat) posts curpage moreposts
-         , ptitle = C.name cat
-         }
-
 postPage :: P.Post        -- ^ The Post to display
          -> CommentStage  -- ^ What stage comment submission is at
          -> Cm.Comment    -- ^ Data for the comment form

src/Blog/Views.hs

 postsRedirectView req = return $ Just $ redirectResponse indexUrl
 
 -- | View that shows an overview of categories
-
 categoriesView :: View
 categoriesView req = do
   cn <- connect
     Just cat -> do
               (posts,more) <- getPostsForCategory cn cat (getPage req)
               cats <- getCategoriesBulk cn posts
-              return $ Just $ standardResponse $ categoryPage cat (zip posts cats) curpage more
+              t <- get_template "category"
+              return $ Just $ standardResponseBS $
+                         (renderf t
+                          ("category", cat)
+                          ("posts", map postTemplateInfo posts)
+                          ("categories", map (map categoryTemplateInfo) cats)
+                          ("paginglinks", pagingLinks (categoryUrl cat) curpage more)
+                         )
 
 -- | View that shows individual post
 postView :: String -> View

src/templates/category.st

+$pagestart(pagetitle=category.name)$
+<h1>Category: $category.name$</h1>
+
+$posts,categories:{ p,cs |
+<div class="summarylink"><a href="$p.url$">$p.title$</a></div>
+$metainfoline(divclass="metainfoindex";post=p;categories=cs)$
+<div class="summary">$p.summary$</div>
+}$
+$paginglinks$
+$pageend()$