about summary refs log tree commit diff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorVincent Ambo <viam@humac.com>2012-03-03T15·39+0100
committerVincent Ambo <viam@humac.com>2012-03-03T15·39+0100
commit96093c9009554cd63431022635fccf54e47438e2 (patch)
treeab73bc04716645ac52068336d4f45c470e600707 /src/Main.hs
parent485e27147574106d5925ea9ab880739d8e1c4f6e (diff)
* Pagination (finally!)
* slight CSS change
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/Main.hs b/src/Main.hs
index debf02e3cc18..89f6179237f5 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -2,10 +2,11 @@
 
 module Main where
 
-import           Control.Monad (msum, mzero)
+import           Control.Applicative (optional)
+import           Control.Monad (msum)
 import           Data.Monoid (mempty)
 import           Data.ByteString.Char8 (ByteString)
-import           Data.Text hiding (map, length, zip, head)
+import           Data.Text hiding (map, length, zip, head, drop)
 import           Data.Time
 import           Database.CouchDB
 import           Happstack.Server
@@ -64,14 +65,20 @@ tryEntry (Just entry) = toResponse $ blogTemplate eLang eTitle $ renderEntry ent
 
 showIndex :: BlogLang -> ServerPart Response
 showIndex lang = do
-    entries <- getLatest lang [("limit", toJSON (7 :: Int)), ("descending", toJSON True)]
-    ok $ toResponse $ blogTemplate lang "" $ renderEntries entries (topText lang)
-
+    entries <- getLatest lang [("descending", showJSON True)]
+    (page :: Maybe Int) <- optional $ lookRead "page"
+    ok $ toResponse $ blogTemplate lang "" $ 
+        renderEntries False (eDrop page entries) (topText lang) (Just $ showLinks page lang)
+  where
+    eDrop :: Maybe Int -> [a] -> [a]
+    eDrop (Just i) = drop ((i-1) * 6)
+    eDrop Nothing = drop 0 
+    
 showMonth :: Int -> Int -> BlogLang -> ServerPart Response
 showMonth y m lang = do
-    entries <- getLatest lang $ makeQuery startkey endkey
+    entries <- getLatest lang $ ("descending", showJSON True) : makeQuery startkey endkey
     ok $ toResponse $ blogTemplate lang month 
-        $ renderEntries entries month
+        $ renderEntries True entries month Nothing
   where
     month = getMonth lang y  m
     startkey = JSArray [toJSON y, toJSON m]