/
hakyll.hs
79 lines (63 loc) · 2.79 KB
/
hakyll.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
module Main where
import qualified Data.Map as M
import Control.Arrow ((>>>))
import Data.List (sort, intercalate)
import Control.Monad (liftM, mapM_)
import Control.Monad.Reader (liftIO)
import Data.Either (Either(..))
import Text.Hakyll (hakyll)
import Text.Hakyll.Render
import Text.Hakyll.Feed (FeedConfiguration (..), renderRss)
import Text.Hakyll.Util (trim, link)
import Text.Hakyll.File (getRecursiveContents, directory, removeSpaces)
import Text.Hakyll.CreateContext (createPage, createCustomPage, createListing)
import Text.Hakyll.Tags (readTagMap, renderTagCloud, renderTagLinks, withTagMap)
import Text.Hakyll.ContextManipulations (renderDate, renderValue)
main = hakyll "http://jaspervdj.be" $ do
directory static "images"
directory static "js"
directory static "files"
directory css "css"
static "favicon.ico"
postPaths <- liftM (reverse . sort) $ getRecursiveContents "posts"
let renderablePosts = map ((>>> postManipulation) . createPage) postPaths
let tagMap = readTagMap "postTagMap" postPaths
let tagCloud = renderTagCloud tagToURL 100 120
index = createListing "index.html"
["templates/postitem.html"]
(take 3 renderablePosts)
[ ("title", Left "Home")
, ("tagcloud", Right $ tagMap >>> tagCloud)
]
renderChain ["index.html", "templates/default.html"] index
renderRss feedConfiguration $ take 5 renderablePosts
renderPostList "posts.html" "All posts" renderablePosts
mapM_ (renderChain ["templates/post.html", "templates/default.html"])
renderablePosts
withTagMap tagMap $ \tag posts ->
renderPostList (tagToURL tag) ("Posts tagged " ++ tag)
(map (>>> postManipulation) posts)
-- Some static pages.
mapM_ (renderChain ["templates/default.html"] . createPage)
[ "contact.markdown"
, "cv.markdown"
, "404.html"
, "links.markdown"
]
-- Some special pages
renderChain [] $ createPage "tmp/index.html"
feedConfiguration :: FeedConfiguration
feedConfiguration = FeedConfiguration
{ feedUrl = "rss.xml"
, feedTitle = "jaspervdj - a personal blog"
, feedDescription = "Personal blog of jaspervdj"
, feedAuthorName = "Jasper Van der Jeugt"
}
tagToURL :: String -> String
tagToURL tag = "$root/tags/" ++ (removeSpaces tag) ++ ".html"
postManipulation = renderTagLinks tagToURL
>>> renderDate "prettydate" "%B %e, %Y" "Date unknown"
renderPostList url title posts = do
let page = createListing url ["templates/postitem.html"]
posts [("title", Left title)]
renderChain ["posts.html", "templates/default.html"] page