This repository has been archived by the owner on May 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite.hs
181 lines (153 loc) · 6.3 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
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
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid (mappend)
import Hakyll
import Data.List (intersperse)
import qualified Data.Set as S
import qualified Data.Map as M
import Text.Blaze.Html (toHtml,toValue, (!))
import qualified Text.Blaze.Html5 as H
import qualified Text.Blaze.Html5.Attributes as A
import Text.Pandoc.Options
--------------------------------------------------------------------------------
main :: IO ()
main = hakyll $ do
match "assets/fonts/*" $ do
route idRoute
compile copyFileCompiler
match "assets/js/*" $ do
route idRoute
compile copyFileCompiler
match "assets/images/*" $ do
route idRoute
compile copyFileCompiler
match "assets/css/*" $ do
route idRoute
compile compressCssCompiler
match "assets/css/images/overlay.png" $ do
route idRoute
compile copyFileCompiler
match "downloads/*" $ do
route idRoute
compile copyFileCompiler
match "CNAME" $ do
route idRoute
compile copyFileCompiler
match "resume.html" $ do
route idRoute
compile copyFileCompiler
--photos <- buildPhotos "posts/*" (fromCapture "photos/*.html")
tags <- buildTags "posts/*" (fromCapture "tags/*.html")
tagsRules tags $ \tag pattern -> do
let title = tag
route idRoute
compile $ do
posts <- recentFirst =<< loadAllSnapshots pattern "content"
let ctx = constField "title" title
`mappend` listField "posts" teaserCtx (return posts)
`mappend` defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/tag.html" ctx
>>= loadAndApplyTemplate "templates/default.html" ctx
>>= relativizeUrls
{--
tagsRules photos $ \tag pattern -> do
let title = tag
route idRoute
compile $ do
let ctx = constField "title" title
`mappend` defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/photo.html" ctx
>>= loadAndApplyTemplate "templates/default.html" ctx
>>= relativizeUrls
--}
match "posts/*" $ do
route $ setExtension "html"
compile $ pandocMathCompiler
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/post.html" (postCtxWithTags tags)
>>= loadAndApplyTemplate "templates/default.html" (postCtxWithTags tags)
>>= relativizeUrls
match "404.md" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" (postCtxWithTags tags)
>>= relativizeUrls
match "posts.html" $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
let postsCtx =
listField "posts" teaserCtx (return posts) `mappend`
constField "title" "Posts" `mappend`
defaultContext
getResourceBody
>>= applyAsTemplate postsCtx
>>= relativizeUrls
match "index.html" $ do
route idRoute
compile $ do
posts <- fmap (take 5) . recentFirst =<< loadAllSnapshots "posts/*" "content"
let indexCtx =
listField "posts" teaserCtx (return posts) `mappend`
constField "title" "Home" `mappend`
defaultContext
getResourceBody
>>= applyAsTemplate indexCtx
>>= relativizeUrls
match "templates/*" $ compile templateCompiler
create ["feed.xml"] $ do
route idRoute
compile $ do
let feedCtx = postCtx `mappend` bodyField "description"
posts <- fmap (take 10) . recentFirst =<<
loadAllSnapshots "posts/*" "content"
renderAtom feedConfiguration feedCtx posts
--------------------------------------------------------------------------------
postCtx :: Context String
postCtx =
dateField "date" "%B %e, %Y" `mappend`
defaultContext
--Add Tags and Photos to Post Metadata and make accessible with keys
postCtxWithTags :: Tags -> Context String
postCtxWithTags tags = tagsField "tags" tags `mappend` postCtx
{--
postCtxWithPhotosAndTags :: Tags -> Tags -> Context String
postCtxWithPhotosAndTags photos tags = photosField "photos" photos
`mappend` postCtxWithTags tags
--}
feedConfiguration :: FeedConfiguration
feedConfiguration = FeedConfiguration
{ feedTitle = "AJPantuso"
, feedDescription = "Applied Mathematics and Computer Science"
, feedAuthorName = "Andrew Pantuso"
, feedAuthorEmail = "[email protected]"
, feedRoot = "http://ajpantuso.com"
}
pandocMathCompiler =
let mathExtensions = [Ext_tex_math_dollars, Ext_tex_math_double_backslash,
Ext_latex_macros]
defaultExtensions = writerExtensions defaultHakyllWriterOptions
newExtensions = foldr S.insert defaultExtensions mathExtensions
writerOptions = defaultHakyllWriterOptions {
writerExtensions = newExtensions,
writerHTMLMathMethod = MathJax ""
}
in pandocCompilerWith defaultHakyllReaderOptions writerOptions
teaserCtx = teaserField "teaser" "content" `mappend` postCtx
--Modified "Tag" functions to look for and build photo metadata and keys
{--
getPhotos :: MonadMetadata m => Identifier -> m [String]
getPhotos identifier = do
metadata <- getMetadata identifier
return $ maybe [] (map trim . splitAll ",") $ M.lookup "photos" metadata
buildPhotos :: MonadMetadata m => Pattern -> (String -> Identifier) -> m Tags
buildPhotos = buildTagsWith getPhotos
photosField :: String -> Tags -> Context a
photosField = tagsFieldWith getPhotos simpleRenderLink (mconcat . intersperse ", ")
simpleRenderLink :: String -> (Maybe FilePath) -> Maybe H.Html
simpleRenderLink _ Nothing = Nothing
simpleRenderLink tag (Just filePath) =
Just $ H.a ! A.href (toValue $ toUrl filePath) $ toHtml tag
--}