This repository was archived by the owner on Jun 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsite.hs
129 lines (107 loc) · 4.39 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
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
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid ((<>), mappend)
import Data.List (intercalate)
import Hakyll
import System.FilePath ((</>), takeBaseName, takeDirectory)
import Text.Blaze.Html (toHtml, toValue, (!))
import Text.Blaze.Html.Renderer.String (renderHtml)
import qualified Text.Blaze.Html5 as H
import qualified Text.Blaze.Html5.Attributes as A
--------------------------------------------------------------------------------
main :: IO ()
main = hakyll $ do
match "images/*" $ do
route idRoute
compile copyFileCompiler
match "posts/*/*/images/*" $ do
route idRoute
compile copyFileCompiler
match "posts/*/*/examples/*" $ do
route idRoute
compile copyFileCompiler
match "js/*" $ do
route idRoute
compile copyFileCompiler
match "fonts/*" $ do
route idRoute
compile copyFileCompiler
match "css/*" $ do
route idRoute
compile compressCssCompiler
cats <- buildCategories "posts/*/*" (fromCapture "posts/*/index.html")
match "posts/*/*/*.md" $ do
route $ setExtension "html"
compile $ do
let indexCtx =
field "tags" (\_ -> renderCats cats) <>
postCtx
pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" indexCtx
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.html" indexCtx
>>= relativizeUrls
match "posts/*/index.md" $ do
route $ setExtension "html"
compile $ do
identifier <- getUnderlying
posts <- recentFirst =<< loadAll (fromGlob $ (takeDirectory . toFilePath $ identifier) ++ "/*/*.md")
let indexCtx =
listField "posts" postCtx (return posts) <>
field "tags" (\_ -> renderCats cats) <>
defaultContext
getResourceBody
>>= applyAsTemplate indexCtx
>>= loadAndApplyTemplate "templates/default.html" indexCtx
>>= relativizeUrls
match "index.html" $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "posts/*/*/*.md"
let indexCtx =
listField "posts" postCtx (return posts) <>
field "tags" (\_ -> renderCats cats) <>
defaultContext
getResourceBody
>>= applyAsTemplate indexCtx
>>= loadAndApplyTemplate "templates/default.html" indexCtx
>>= relativizeUrls
match "about.html" $ do
route idRoute
compile $ do
let aboutCtx =
field "tags" (\_ -> renderCats cats) <>
defaultContext
getResourceBody
>>= applyAsTemplate aboutCtx
>>= loadAndApplyTemplate "templates/default.html" aboutCtx
>>= relativizeUrls
-- keep it the same path as the original howistart.org
create ["static/posts.rss"] $ do
route idRoute
compile $ do
let feedCtx = postCtx `mappend` bodyField "description"
posts <- fmap (take 10) . recentFirst =<<
loadAllSnapshots "posts/*/*/*.md" "content"
renderAtom myFeedConfiguration feedCtx posts
match "templates/*" $ compile templateCompiler
--------------------------------------------------------------------------------
myFeedConfiguration :: FeedConfiguration
myFeedConfiguration = FeedConfiguration
{ feedTitle = "How I Start."
, feedDescription = "How I Start is a mix between a collection of development tutorials and The Setup."
, feedAuthorName = "Tristan Sloughter"
, feedAuthorEmail = "[email protected]"
, feedRoot = "http://www.howistart.org"
}
postCtx :: Context String
postCtx = mconcat
[ dateField "date" "%B %e, %Y"
, field "basename" (\item -> return . takeDirectory . toFilePath $ itemIdentifier item)
, defaultContext
]
renderCats :: Tags -> Compiler (String)
renderCats = renderTags makeLink (intercalate "")
where
makeLink tag url count _ _ = renderHtml $
H.li ! A.class_ "category" $ H.a ! A.href (toValue ("/posts" </> tag)) $ toHtml tag