-
Notifications
You must be signed in to change notification settings - Fork 0
/
hakyll.hs
203 lines (171 loc) · 6.76 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Prelude hiding (id)
import Control.Arrow ((>>>), (***), arr)
import Control.Category (id)
import Control.Monad (forM_)
import Data.Monoid (mempty, mconcat)
import Text.Pandoc (WriterOptions(..), defaultWriterOptions)
import Hakyll
main :: IO ()
main = hakyllWith config $ do
-- Compress CSS
match "stylesheets/*" $ do
route idRoute
compile compressCssCompiler
-- Copy fonts
match "fonts/*" $ do
route idRoute
compile copyFileCompiler
-- Copy images
match "images/*" $ do
route idRoute
compile copyFileCompiler
-- Copy post images
match "images/posts/*" $ do
route idRoute
compile copyFileCompiler
-- Copy javascripts
match "javascripts/*" $ do
route idRoute
compile copyFileCompiler
-- Copy files
match "files/*" $ do
route idRoute
compile copyFileCompiler
-- Copy project files
match "projects/*" $ do
route idRoute
compile copyFileCompiler
match "projects/*/*" $ do
route idRoute
compile copyFileCompiler
-- Copy robots.txt
match "robots.txt" $ do
route idRoute
compile copyFileCompiler
-- Render all pages (blog posts and projects)
match "posts/*/*" $ do
route $ setExtension ".html"
compile $ wunkiCompiler
>>> arr (renderDateField "date" "%Y-%m-%d" "Date unknown")
>>> arr (setField "bodyclass" "post")
>>> renderTagsField "prettytags" (fromCapture "tags/*")
>>> applyTemplateCompiler "templates/page.html"
>>> applyTemplateCompiler "templates/default.html"
-- Post list
match "posts.html" $ route idRoute
create "posts.html" $ constA mempty
>>> arr (setField "title" "All Posts")
>>> arr (setField "bodyclass" "postlist")
>>> setFieldPageList recentFirst
"templates/postitem.html" "posts" "posts/blog/*"
>>> applyTemplateCompiler "templates/posts.html"
>>> applyTemplateCompiler "templates/default.html"
-- project list
match "projects.html" $ route idRoute
create "projects.html" $ constA mempty
>>> arr (setField "title" "All Projects")
>>> arr (setField "bodyclass" "postlist")
>>> setFieldPageList recentFirst
"templates/postitem.html" "posts" "posts/projects/*"
>>> applyTemplateCompiler "templates/posts.html"
>>> applyTemplateCompiler "templates/default.html"
-- all pages list
match "pages.html" $ route idRoute
create "pages.html" $ constA mempty
>>> arr (setField "title" "All Posts & Projects")
>>> arr (setField "bodyclass" "postlist")
>>> setFieldPageList recentFirst
"templates/postitem.html" "posts" "posts/*/*"
>>> applyTemplateCompiler "templates/posts.html"
>>> applyTemplateCompiler "templates/default.html"
-- Index
match "index.html" $ route idRoute
create "index.html" $ constA mempty
>>> arr (setField "title" "etcet.net")
>>> arr (setField "description" description)
>>> arr (setField "keywords" keywords)
>>> arr (setField "bodyclass" "default")
>>> requireA "tags" (setFieldA "tagcloud" (renderTagCloud'))
>>> requireA "tags" (setFieldA "tags" (renderTagList'))
>>> setFieldPageList (take 3 . recentFirst)
"templates/postitem.html" "blogposts" "posts/blog/*"
>>> setFieldPageList (take 5 . recentFirst)
"templates/postitem.html" "projects" "posts/projects/*"
>>> applyTemplateCompiler "templates/index.html"
>>> applyTemplateCompiler "templates/default.html"
-- Tags
create "tags" $
requireAll "posts/*/*" (\_ ps -> readTags ps :: Tags String)
-- Add a tag list compiler for every tag
match "tags/*" $ route $ setExtension ".html"
metaCompile $ require_ "tags"
>>> arr tagsMap
>>> arr (map (\(t, p) -> (tagIdentifier t, makeTagList t p)))
-- Render RSS feed
match "rss.xml" $ route idRoute
create "rss.xml" $ requireAll_ "posts/*/*" >>> renderRss feedConfiguration
-- Read templates
match "templates/*" $ compile templateCompiler
-- Render pages without relative url's
forM_ ["404.md"] $ \p ->
match p $ do
route $ setExtension ".html"
compile $ wunkiCompiler
>>> applyTemplateCompiler "templates/default.html"
-- Render pages with relative url's
forM_ ["about.md"] $ \p ->
match p $ do
route $ setExtension ".html"
compile $ wunkiCompiler
>>> applyTemplateCompiler "templates/default.html"
>>> relativizeUrlsCompiler
where
renderTagCloud' :: Compiler (Tags String) String
renderTagCloud' = renderTagCloud tagIdentifier 100 120
renderTagList' :: Compiler (Tags String) String
renderTagList' = renderTagList tagIdentifier
tagIdentifier :: String -> Identifier (Page String)
tagIdentifier = fromCapture "tags/*"
-- Common variables
description = "etcet.net - homepage of Chris James"
keywords = "chris, james, etcet, etcet.net, portfolio, linux, programming, chris james"
makeTagList :: String
-> [Page String]
-> Compiler () (Page String)
makeTagList tag posts =
constA posts
>>> pageListCompiler recentFirst "templates/postitem.html"
>>> arr (copyBodyToField "posts" . fromBody)
>>> arr (setField "title" $ "Posts tagged " ++ tag)
>>> arr (setField "description" $ "View all posts tagged with " ++ tag)
>>> arr (setField "keywords" $ "etcet, tags, " ++ tag)
>>> arr (setField "bodyclass" "postlist")
>>> applyTemplateCompiler "templates/posts.html"
>>> applyTemplateCompiler "templates/default.html"
-- | Read a page, add default fields, substitute fields and render with Pandoc.
--
wunkiCompiler :: Compiler Resource (Page String)
wunkiCompiler = pageCompilerWith defaultHakyllParserState wunkiWriterOptions
-- | Custom HTML options for pandoc
--
wunkiWriterOptions :: WriterOptions
wunkiWriterOptions = defaultHakyllWriterOptions
{ writerHtml5 = True
, writerTableOfContents = True
, writerLiterateHaskell = False
}
config :: HakyllConfiguration
config = defaultHakyllConfiguration
{ deployCommand = "rsync --checksum -ave 'ssh -p 2222' \
\_site/* [email protected]:/home/etcetn/www/"
}
feedConfiguration :: FeedConfiguration
feedConfiguration = FeedConfiguration
{ feedTitle = "etcet.net"
, feedDescription = "Homepage of Chris James"
, feedAuthorName = "Chris James"
, feedAuthorEmail = "[email protected]"
, feedRoot = "http://www.etcet.net"
}