on master help sign in
Update example & tutorials with new recentFirst
commitb91c8be54b14a84aa47b5033a9966653df7f84ca authorJasper Van der Jeugt <m@jaspervdj.be> dateSun 24 Feb 2013, 10:50 (14 years ago) parent9b60358
3 files changed+12−11
data/example/site.hs+5−5 web/site.hs+3−2 web/tutorials/04-compilers.markdown+4−4
data/example/site.hs+5−5
@@ -1,7 +1,6 @@
11--------------------------------------------------------------------------------
22{-# LANGUAGE OverloadedStrings #-}
3−import Control.Applicative ((<$>))
4−import Data.Monoid (mappend)
3+import Data.Monoid (mappend)
54import Hakyll
65
76
@@ -46,7 +45,8 @@ main = hakyll $ do
4645 match "index.html" $ do
4746 route idRoute
4847 compile $ do
49− let indexCtx = field "posts" $ \_ -> postList (take 3 . recentFirst)
48+ let indexCtx = field "posts" $ \_ ->
49+ postList $ fmap (take 3) . recentFirst
5050
5151 getResourceBody
5252 >>= applyAsTemplate indexCtx
@@ -64,9 +64,9 @@ postCtx =
6464
6565
6666--------------------------------------------------------------------------------
67−postList :: ([Item String] -> [Item String]) -> Compiler String
67+postList :: ([Item String] -> Compiler [Item String]) -> Compiler String
6868postList sortFilter = do
69− posts <- sortFilter <$> loadAll "posts/*"
69+ posts <- sortFilter =<< loadAll "posts/*"
7070 itemTpl <- loadBody "templates/post-item.html"
7171 list <- applyTemplateList itemTpl postCtx posts
7272 return list
web/site.hs+3−2
@@ -4,8 +4,9 @@ import Control.Applicative ((<$>))
44import Control.Arrow (second)
55import Control.Monad (forM_)
66import Data.Char (isDigit)
7−import Data.List (isPrefixOf, partition)
7+import Data.List (isPrefixOf, partition, sortBy)
88import Data.Monoid (mappend)
9+import Data.Ord (comparing)
910import Hakyll
1011import System.FilePath (dropTrailingPathSeparator, splitPath)
1112import Text.Pandoc
@@ -55,7 +56,7 @@ main = hakyllWith config $ do
5556 tutorials <- loadAll "tutorials/*"
5657 itemTpl <- loadBody "templates/tutorial-item.html"
5758 let (series, articles) = partitionTutorials $
58− chronological tutorials
59+ sortBy (comparing itemIdentifier) tutorials
5960
6061 series' <- applyTemplateList itemTpl defaultContext series
6162 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:
158158
159159```haskell
160160compile $ do
161− posts <- recentFirst <$> loadAll "posts/*"
161+ posts <- recentFirst =<< loadAll "posts/*"
162162 itemTpl <- loadBody "templates/post-item.html"
163163 list <- applyTemplateList itemTpl postCtx posts
164164 makeItem list
165165```
166166
167167`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
169−format, you'll have to write some other sorting method.
168+always named `YYYY-MM-DD-title.extension` in Hakyll -- or that the date must be
169+present in the metadata.
170170
171171```haskell
172−recentFirst :: [Item a] -> [Item a]
172+recentFirst :: [Item a] -> Compiler [Item a]
173173```
174174
175175After loading and sorting the items, we load a template for the posts.