-
Notifications
You must be signed in to change notification settings - Fork 0
/
dtf.hs
111 lines (92 loc) · 3.27 KB
/
dtf.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid (mappend)
import Hakyll
import Data.Maybe (fromMaybe)
main :: IO ()
main = hakyll $ do
match "static/*" $ do
route idRoute
compile copyFileCompiler
match "images/*" $ do
route idRoute
compile copyFileCompiler
match "index.html" $ do
route idRoute
compile $ do
let indexCtx =
field "posts" (\_ -> postList recentFirst) `mappend`
constField "IndexCurrent" "class=\"current\"" `mappend`
constField "BlogCurrent" "" `mappend`
defaultContext
getResourceBody
>>= applyAsTemplate indexCtx
>>= loadAndApplyTemplate "templates/default.html" indexCtx
>>= relativizeUrls
match "projects.html" $ do
route idRoute
compile copyFileCompiler
match "about.html" $ do
route idRoute
compile copyFileCompiler
match "resume.html" $ do
route idRoute
compile copyFileCompiler
match "robots.txt" $ do
route idRoute
compile copyFileCompiler
match "posts/*" $ do
route $ setExtension "html"
compile $ do
pandocCompiler
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= loadAndApplyTemplate "templates/blog-base.html" postCtx
>>= relativizeUrls
match "templates/*" $ compile templateCompiler
create ["blog.html"] $ do
route idRoute
compile $ do
let blogCtx =
field "posts" (\_ -> postList recentFirst) `mappend`
postCtx
makeItem ""
>>= loadAndApplyTemplate "templates/blog.html" blogCtx
>>= loadAndApplyTemplate "templates/blog-base.html" blogCtx
>>= relativizeUrls
create ["atom.xml"] $ do
route idRoute
compile $ do
let feedCtx = postCtx `mappend`
bodyField "description"
posts <- fmap (take 10) . recentFirst =<< (return . getTeaserContents) =<< loadAllSnapshots "posts/*" "content"
renderAtom myFeedConfiguration feedCtx posts
-- Context for pages
postCtx :: Context String
postCtx =
dateField "date" "%B %e, %Y" `mappend`
teaserField "teaser" "content" `mappend`
constField "BlogCurrent" "class=\"current\"" `mappend`
constField "IndexCurrent" "" `mappend`
defaultContext
-- Makes list of posts with base template applied
postList :: ([Item String] -> Compiler [Item String]) -> Compiler String
postList sortFilter = do
posts <- sortFilter =<< loadAll "posts/*"
itemTpl <- loadBody "templates/post-item.html"
list <- applyTemplateList itemTpl postCtx posts
return list
-- Configuration for atom feed
myFeedConfiguration :: FeedConfiguration
myFeedConfiguration = FeedConfiguration
{ feedTitle = "David Flicker: latest posts"
, feedDescription = "Posts on robotics, PCBs, microcontrollers and more"
, feedAuthorName = "David Flicker"
, feedAuthorEmail = "[email protected]"
, feedRoot = "http://www.davidflicker.com"
}
-- Gets the teaser from a list of posts
getTeaserContents :: [Item String] -> [Item String]
getTeaserContents =
map $ \x -> itemSetBody (fromMaybe (itemBody x) $ needlePrefix teaserSeparator $ itemBody x) x
teaserSeparator :: String
teaserSeparator = "<!--more-->"