-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.hs
101 lines (80 loc) · 3.38 KB
/
site.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
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid (mappend)
import Hakyll
import Text.Pandoc (WriterOptions, writerHtml5)
import Control.Applicative (Alternative (..), (<$>))
--------------------------------------------------------------------------------
myFeedConfiguration :: FeedConfiguration
myFeedConfiguration = FeedConfiguration
{ feedTitle = "Pain is Optional"
, feedDescription = "Pain treatment using Active Isolated Stretching and Massage Therapy"
, feedAuthorName = "Joseph Huang"
, feedAuthorEmail = "[email protected]"
, feedRoot = "http://painisoptional.com"
}
main :: IO ()
main = hakyll $ do
match "i/*" $ do
route idRoute
compile copyFileCompiler
match "css/*" $ do
route idRoute
compile compressCssCompiler
match (fromList ["about.rst", "policy.markdown"]) $ do
route $ setExtension "htm"
compile $ pandocCompilerWith defaultHakyllReaderOptions myWriterOptions
>>= loadAndApplyTemplate "templates/post.htm" postCtx
>>= loadAndApplyTemplate "templates/default.htm" defaultContext
>>= relativizeUrls
match "p/*" $ do
route $ setExtension "htm"
compile $ pandocCompilerWith defaultHakyllReaderOptions myWriterOptions
>>= loadAndApplyTemplate "templates/post.htm" postCtx
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.htm" postCtx
>>= relativizeUrls
create ["posts.htm"] $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "p/*"
let archiveCtx =
listField "posts" postCtx (return posts) `mappend`
constField "title" "Posts" `mappend`
defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/archive.htm" archiveCtx
>>= loadAndApplyTemplate "templates/default.htm" archiveCtx
>>= relativizeUrls
match "index.htm" $ do
route idRoute
compile $ do
let indexCtx = field "post" $ const (itemBody <$> mostRecentPost)
let homeCtx = constField "title" "Home" `mappend` defaultContext
getResourceBody
>>= applyAsTemplate indexCtx
>>= loadAndApplyTemplate "templates/default.htm" homeCtx
>>= relativizeUrls
match "templates/*" $ compile templateCompiler
create ["atom.xml"] $ do
route idRoute
compile $ do
posts <- fmap (take 10) . recentFirst =<<
loadAllSnapshots "p/*" "content"
renderAtom myFeedConfiguration feedCtx posts
--------------------------------------------------------------------------------
postCtx :: Context String
postCtx =
dateField "date" "%B %e, %Y" `mappend`
dateField "datetime" "%Y-%m-%d" `mappend`
defaultContext
feedCtx :: Context String
feedCtx =
bodyField "description" `mappend`
postCtx
myWriterOptions :: WriterOptions
myWriterOptions = defaultHakyllWriterOptions
{ writerHtml5 = True
}
mostRecentPost :: Compiler (Item String)
mostRecentPost = head <$> (recentFirst =<< loadAllSnapshots "p/*" "content")