blob: e10af10d5a064a043fe2aede6b44eec296c46c12 (
plain)
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
|
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Prelude hiding (id)
import Control.Category (id)
import Control.Arrow ((>>>), (***), arr)
import Data.Monoid (mempty, mconcat)
import Hakyll
main :: IO ()
main = hakyll $ do
-- Compress CSS
route "css/*" idRoute
compile "css/*" compressCssCompiler
-- Render posts
route "posts/*" $ setExtension ".html"
compile "posts/*" $
pageCompiler
>>> applyTemplateCompiler "templates/post.html"
>>> applyTemplateCompiler "templates/default.html"
>>> relativizeUrlsCompiler
-- Render posts list
route "posts.html" $ idRoute
create "posts.html" $
constA mempty
>>> arr (setField "title" "All posts")
>>> requireAllA "posts/*" addPostList
>>> applyTemplateCompiler "templates/posts.html"
>>> applyTemplateCompiler "templates/default.html"
>>> relativizeUrlsCompiler
-- Index
route "index.html" $ idRoute
create "index.html" $
constA mempty
>>> arr (setField "title" "Home")
>>> requireAllA "posts/*" (id *** arr (take 3 . reverse . sortByBaseName) >>> addPostList)
>>> applyTemplateCompiler "templates/index.html"
>>> applyTemplateCompiler "templates/default.html"
>>> relativizeUrlsCompiler
-- Render RSS feed
route "rss.xml" $ idRoute
create "rss.xml" $
requireAll_ "posts/*" >>> renderRss feedConfiguration
-- Read templates
compile "templates/*" templateCompiler
-- End
return ()
-- | Auxiliary compiler: generate a post list from a list of given posts, and
-- add it to the current page under @$posts@
--
addPostList :: Compiler (Page String, [Page String]) (Page String)
addPostList = setFieldA "posts" $
arr (reverse . sortByBaseName)
>>> require "templates/postitem.html" (\p t -> map (applyTemplate t) p)
>>> arr mconcat
>>> arr pageBody
feedConfiguration :: FeedConfiguration
feedConfiguration = FeedConfiguration
{ feedTitle = "SimpleBlog RSS feed."
, feedDescription = "A simple demo of an RSS feed created with Hakyll."
, feedAuthorName = "Jasper Van der Jeugt"
, feedRoot = "http://example.com"
}
|