summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2013-02-24 10:50:38 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2013-02-24 10:55:11 +0100
commitb91c8be54b14a84aa47b5033a9966653df7f84ca (patch)
tree795341847c1554b578604dca3be361dd47529318
parent9b603587de20d42d95e6affc2bce85447de6f58e (diff)
downloadhakyll-b91c8be54b14a84aa47b5033a9966653df7f84ca.tar.gz
Update example & tutorials with new recentFirst
-rw-r--r--data/example/site.hs10
-rw-r--r--web/site.hs5
-rw-r--r--web/tutorials/04-compilers.markdown8
3 files changed, 12 insertions, 11 deletions
diff --git a/data/example/site.hs b/data/example/site.hs
index 2488cc8..9e103bf 100644
--- a/data/example/site.hs
+++ b/data/example/site.hs
@@ -1,7 +1,6 @@
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
-import Control.Applicative ((<$>))
-import Data.Monoid (mappend)
+import Data.Monoid (mappend)
import Hakyll
@@ -46,7 +45,8 @@ main = hakyll $ do
match "index.html" $ do
route idRoute
compile $ do
- let indexCtx = field "posts" $ \_ -> postList (take 3 . recentFirst)
+ let indexCtx = field "posts" $ \_ ->
+ postList $ fmap (take 3) . recentFirst
getResourceBody
>>= applyAsTemplate indexCtx
@@ -64,9 +64,9 @@ postCtx =
--------------------------------------------------------------------------------
-postList :: ([Item String] -> [Item String]) -> Compiler String
+postList :: ([Item String] -> Compiler [Item String]) -> Compiler String
postList sortFilter = do
- posts <- sortFilter <$> loadAll "posts/*"
+ posts <- sortFilter =<< loadAll "posts/*"
itemTpl <- loadBody "templates/post-item.html"
list <- applyTemplateList itemTpl postCtx posts
return list
diff --git a/web/site.hs b/web/site.hs
index 45e6519..8817d8c 100644
--- a/web/site.hs
+++ b/web/site.hs
@@ -4,8 +4,9 @@ import Control.Applicative ((<$>))
import Control.Arrow (second)
import Control.Monad (forM_)
import Data.Char (isDigit)
-import Data.List (isPrefixOf, partition)
+import Data.List (isPrefixOf, partition, sortBy)
import Data.Monoid (mappend)
+import Data.Ord (comparing)
import Hakyll
import System.FilePath (dropTrailingPathSeparator, splitPath)
import Text.Pandoc
@@ -55,7 +56,7 @@ main = hakyllWith config $ do
tutorials <- loadAll "tutorials/*"
itemTpl <- loadBody "templates/tutorial-item.html"
let (series, articles) = partitionTutorials $
- chronological tutorials
+ sortBy (comparing itemIdentifier) tutorials
series' <- applyTemplateList itemTpl defaultContext series
articles' <- applyTemplateList itemTpl defaultContext articles
diff --git a/web/tutorials/04-compilers.markdown b/web/tutorials/04-compilers.markdown
index 522f817..cdc8eb0 100644
--- a/web/tutorials/04-compilers.markdown
+++ b/web/tutorials/04-compilers.markdown
@@ -158,18 +158,18 @@ We can reproduce a list of items in the archive using the following code:
```haskell
compile $ do
- posts <- recentFirst <$> loadAll "posts/*"
+ posts <- recentFirst =<< loadAll "posts/*"
itemTpl <- loadBody "templates/post-item.html"
list <- applyTemplateList itemTpl postCtx posts
makeItem list
```
`recentFirst` sorts items by date. This relies on the convention that posts are
-always named `YYYY-MM-DD-title.extension` in Hakyll -- if you use some other
-format, you'll have to write some other sorting method.
+always named `YYYY-MM-DD-title.extension` in Hakyll -- or that the date must be
+present in the metadata.
```haskell
-recentFirst :: [Item a] -> [Item a]
+recentFirst :: [Item a] -> Compiler [Item a]
```
After loading and sorting the items, we load a template for the posts.