1
1
{-# LANGUAGE OverloadedStrings #-}
2
2
3
3
import Hakyll
4
- import Text.Pandoc.Highlighting
5
- import Text.Pandoc.Options ( WriterOptions ( .. ))
6
- import Prelude
4
+ import Prelude
5
+ import Text.Pandoc.Highlighting
6
+ import Text.Pandoc.Options ( WriterOptions ( .. ))
7
7
8
8
main :: IO ()
9
- main = hakyll $ do
10
- match " images/*" $ do
9
+ main = hakyll do
10
+ match " images/*" do
11
11
route idRoute
12
12
compile copyFileCompiler
13
13
14
- match " files/*" $ do
14
+ match " files/*" do
15
15
route idRoute
16
16
compile copyFileCompiler
17
17
18
- match " css/*" $ do
18
+ match " css/*" do
19
19
route idRoute
20
20
compile compressCssCompiler
21
21
22
- match " CNAME" $ do
22
+ match " CNAME" do
23
23
route idRoute
24
24
compile copyFileCompiler
25
25
26
- match (fromList [" about.rst" , " contact.markdown" ]) $ do
26
+ match (fromList [" about.rst" , " contact.markdown" ]) do
27
27
route $ setExtension " html"
28
28
compile $ pandocCompiler'
29
29
>>= loadAndApplyTemplate " templates/default.html" defaultContext
30
30
>>= relativizeUrls
31
31
32
- match " cv.html" $ do
32
+ match " cv.html" do
33
33
route idRoute
34
34
compile $ getResourceBody
35
35
>>= loadAndApplyTemplate " templates/default.html" defaultContext
36
36
>>= relativizeUrls
37
37
38
- match " posts/*" $ do
38
+ match " posts/*" do
39
39
route $ setExtension " html"
40
40
compile $ pandocCompiler'
41
41
>>= loadAndApplyTemplate " templates/post.html" postCtx
42
+ >>= saveSnapshot " content"
42
43
>>= loadAndApplyTemplate " templates/default.html" postCtx
43
44
>>= relativizeUrls
44
45
45
- create [" archive.html" ] $ do
46
+ create [" archive.html" ] do
46
47
route idRoute
47
- compile $ do
48
+ compile do
48
49
posts <- recentFirst =<< loadAll " posts/*"
49
50
let archiveCtx =
50
51
listField " posts" postCtx (return posts) `mappend`
@@ -56,15 +57,23 @@ main = hakyll $ do
56
57
>>= loadAndApplyTemplate " templates/default.html" archiveCtx
57
58
>>= relativizeUrls
58
59
59
- create [" css/syntax.css" ] $ do
60
+ create [" css/syntax.css" ] do
60
61
route idRoute
61
- compile $ do
62
+ compile do
62
63
makeItem $ styleToCss pandocCodeStyle
63
64
65
+ create [" atom.xml" ] do
66
+ route idRoute
67
+ compile $ mkFeed renderAtom
68
+
69
+ create [" rss.xml" ] do
70
+ route idRoute
71
+ compile $ mkFeed renderRss
64
72
65
- match " index.html" $ do
73
+
74
+ match " index.html" do
66
75
route idRoute
67
- compile $ do
76
+ compile do
68
77
posts <- recentFirst =<< loadAll " posts/*"
69
78
let indexCtx =
70
79
listField " posts" postCtx (return posts) `mappend`
@@ -95,3 +104,19 @@ pandocCompiler' =
95
104
defaultHakyllWriterOptions
96
105
{ writerHighlightStyle = Just pandocCodeStyle
97
106
}
107
+
108
+ type FeedRenderer = FeedConfiguration -> Context String -> [Item String ] -> Compiler (Item String )
109
+
110
+ mkFeed :: FeedRenderer -> Compiler (Item String )
111
+ mkFeed render = do
112
+ let feedCtx = postCtx `mappend` bodyField " description"
113
+ feedConfiguration = FeedConfiguration
114
+ { feedTitle = " mrcjkb"
115
+ , feedDescription = " My Hakyll site"
116
+ , feedAuthorName = " Marc Jakobi"
117
+ , feedAuthorEmail
= " [email protected] "
118
+ , feedRoot = " mrcjkb.dev"
119
+ }
120
+ posts <- fmap (take 10 ) . recentFirst =<< loadAllSnapshots " posts/*" " content"
121
+ render feedConfiguration feedCtx posts
122
+
0 commit comments