on master help sign in
Update example & tutorials with new recentFirst
b91c8beJasper Van der Jeugt
data/example/site.hs+5−5
@@ -1,7 +1,6 @@
1--------------------------------------------------------------------------------
1--------------------------------------------------------------------------------
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3−import Control.Applicative ((<$>))
4−import Data.Monoid (mappend)
3+import Data.Monoid (mappend)
5import Hakyll
4import Hakyll
6
5
7
6
@@ -46,7 +45,8 @@ main = hakyll $ do
46 match "index.html" $ do
45 match "index.html" $ do
47 route idRoute
46 route idRoute
48 compile $ do
47 compile $ do
49− let indexCtx = field "posts" $ \_ -> postList (take 3 . recentFirst)
48+ let indexCtx = field "posts" $ \_ ->
49+ postList $ fmap (take 3) . recentFirst
50
50
51 getResourceBody
51 getResourceBody
52 >>= applyAsTemplate indexCtx
52 >>= applyAsTemplate indexCtx
@@ -64,9 +64,9 @@ postCtx =
64
64
65
65
66--------------------------------------------------------------------------------
66--------------------------------------------------------------------------------
67−postList :: ([Item String] -> [Item String]) -> Compiler String
67+postList :: ([Item String] -> Compiler [Item String]) -> Compiler String
68postList sortFilter = do
68postList sortFilter = do
69− posts <- sortFilter <$> loadAll "posts/*"
69+ posts <- sortFilter =<< loadAll "posts/*"
70 itemTpl <- loadBody "templates/post-item.html"
70 itemTpl <- loadBody "templates/post-item.html"
71 list <- applyTemplateList itemTpl postCtx posts
71 list <- applyTemplateList itemTpl postCtx posts
72 return list
72 return list
web/site.hs+3−2
@@ -4,8 +4,9 @@ import Control.Applicative ((<$>))
4import Control.Arrow (second)
4import Control.Arrow (second)
5import Control.Monad (forM_)
5import Control.Monad (forM_)
6import Data.Char (isDigit)
6import Data.Char (isDigit)
7−import Data.List (isPrefixOf, partition)
7+import Data.List (isPrefixOf, partition, sortBy)
8import Data.Monoid (mappend)
8import Data.Monoid (mappend)
9+import Data.Ord (comparing)
9import Hakyll
10import Hakyll
10import System.FilePath (dropTrailingPathSeparator, splitPath)
11import System.FilePath (dropTrailingPathSeparator, splitPath)
11import Text.Pandoc
12import Text.Pandoc
@@ -55,7 +56,7 @@ main = hakyllWith config $ do
55 tutorials <- loadAll "tutorials/*"
56 tutorials <- loadAll "tutorials/*"
56 itemTpl <- loadBody "templates/tutorial-item.html"
57 itemTpl <- loadBody "templates/tutorial-item.html"
57 let (series, articles) = partitionTutorials $
58 let (series, articles) = partitionTutorials $
58− chronological tutorials
59+ sortBy (comparing itemIdentifier) tutorials
59
60
60 series' <- applyTemplateList itemTpl defaultContext series
61 series' <- applyTemplateList itemTpl defaultContext series
61 articles' <- applyTemplateList itemTpl defaultContext articles
62 articles' <- applyTemplateList itemTpl defaultContext articles
web/tutorials/04-compilers.markdown+4−4
@@ -158,18 +158,18 @@ We can reproduce a list of items in the archive using the following code:
158
158
159```haskell
159```haskell
160compile $ do
160compile $ do
161− posts <- recentFirst <$> loadAll "posts/*"
161+ posts <- recentFirst =<< loadAll "posts/*"
162 itemTpl <- loadBody "templates/post-item.html"
162 itemTpl <- loadBody "templates/post-item.html"
163 list <- applyTemplateList itemTpl postCtx posts
163 list <- applyTemplateList itemTpl postCtx posts
164 makeItem list
164 makeItem list
165```
165```
166
166
167`recentFirst` sorts items by date. This relies on the convention that posts are
167`recentFirst` sorts items by date. This relies on the convention that posts are
168−always named `YYYY-MM-DD-title.extension` in Hakyll -- if you use some other
168+always named `YYYY-MM-DD-title.extension` in Hakyll -- or that the date must be
169−format, you'll have to write some other sorting method.
169+present in the metadata.
170
170
171```haskell
171```haskell
172−recentFirst :: [Item a] -> [Item a]
172+recentFirst :: [Item a] -> Compiler [Item a]
173```
173```
174
174
175After loading and sorting the items, we load a template for the posts.
175After loading and sorting the items, we load a template for the posts.