Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gmcninch-tufts
GitHub Repository: gmcninch-tufts/2024-Sp-Math190
Path: blob/main/site.hs
474 views
1
--------------------------------------------------------------------------------
2
{-# LANGUAGE OverloadedStrings #-}
3
import Data.Monoid (mappend)
4
import Hakyll
5
import Text.Pandoc
6
--------------------------------------------------------------------------------
7
8
--------------------------------------------------------------------------------
9
10
mathjaxExtensions :: Extensions
11
mathjaxExtensions = extensionsFromList
12
[Ext_tex_math_dollars -- $...$ or $$...$$
13
,Ext_tex_math_double_backslash -- \(...\) or \[...\]
14
,Ext_latex_macros
15
,Ext_inline_code_attributes
16
]
17
18
readMathjaxOptions :: ReaderOptions
19
readMathjaxOptions = defaultHakyllReaderOptions
20
{
21
readerExtensions = readerExtensions defaultHakyllReaderOptions <> mathjaxExtensions
22
}
23
24
writeMathjaxOptions :: WriterOptions
25
writeMathjaxOptions = defaultHakyllWriterOptions
26
{
27
writerHTMLMathMethod = MathJax ""
28
}
29
30
myCompiler :: Compiler (Item String)
31
myCompiler = do
32
csl <- load "bib/chicago-author-date.csl"
33
bib <- load "bib/teaching.bib"
34
getResourceBody >>=
35
readPandocBiblio readMathjaxOptions csl bib >>=
36
pure . (writePandocWith writeMathjaxOptions)
37
38
39
-- myCompiler :: Compiler (Item String)
40
-- myCompiler = pandocCompilerWith readMathjaxOptions writeMathjaxOptions
41
42
43
44
main :: IO ()
45
main = hakyllWith config $ do
46
match "course-assets/**" $ do
47
route idRoute
48
compile copyFileCompiler
49
50
match "bib/chicago-author-date.csl" $ compile cslCompiler
51
match "bib/teaching.bib" $ compile biblioCompiler
52
53
match (fromList ["about.md"]) $ do
54
route $ setExtension "html"
55
compile $ pandocCompiler
56
>>= loadAndApplyTemplate "templates/default.html" defaultContext
57
>>= relativizeUrls
58
59
match "course-contents/*md" $ do
60
route $ setExtension "html"
61
compile $ myCompiler
62
>>= loadAndApplyTemplate "templates/content.html" postCtx
63
>>= loadAndApplyTemplate "templates/default.html" postCtx
64
>>= relativizeUrls
65
66
match ("course-contents/*ipynb"
67
.||. "course-assignments/*pdf"
68
) $ version "copy" $ do
69
route idRoute
70
compile copyFileCompiler
71
72
match "css/*" $ do
73
route idRoute
74
compile compressCssCompiler
75
76
match "course-pages/*md" $ do
77
route $ setExtension "html"
78
compile $ myCompiler
79
>>= loadAndApplyTemplate "templates/page.html" postCtx
80
>>= loadAndApplyTemplate "templates/default.html" postCtx
81
>>= relativizeUrls
82
83
84
match ("course-posts/*md" .||. "course-assignments/*md") $ do
85
route $ setExtension "html"
86
compile $ myCompiler
87
>>= loadAndApplyTemplate "templates/post.html" postCtx
88
>>= loadAndApplyTemplate "templates/default.html" postCtx
89
>>= relativizeUrls
90
91
create ["archive.html"] $ do
92
route idRoute
93
compile $ do
94
posts <- recentFirst =<< loadAll "course-posts/*"
95
let archiveCtx =
96
listField "posts" postCtx (return posts) `mappend`
97
constField "title" "Post archives" `mappend`
98
defaultContext
99
100
makeItem ""
101
>>= loadAndApplyTemplate "templates/archive.html" archiveCtx
102
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
103
>>= relativizeUrls
104
105
106
107
match "index.html" $ do
108
route idRoute
109
compile $ do
110
posts <- fmap (take 10) $ recentFirst =<< loadAll "course-posts/*"
111
112
113
let indexCtx =
114
listField "posts" postCtx (return posts) `mappend`
115
defaultContext
116
117
getResourceBody
118
>>= applyAsTemplate indexCtx
119
>>= loadAndApplyTemplate "templates/default.html" indexCtx
120
>>= relativizeUrls
121
122
match "templates/*" $ compile templateBodyCompiler
123
124
--------------------------------------------------------------------------------
125
postCtx :: Context String
126
postCtx =
127
-- dateField "date" "%B %e, %Y" `mappend`
128
dateField "date" "%Y-%m-%d" `mappend`
129
defaultContext
130
131
132
-- postCtxWithTags :: Tags -> Context String
133
-- postCtxWithTags tags = tagsField "tags" tags `mappend` postCtx
134
135
136
config :: Configuration
137
config = defaultConfiguration
138
{ destinationDirectory = "/home/george/Classes/2024-Sp-Math190/docs"
139
, providerDirectory = "/home/george/Classes/2024-Sp-Math190"
140
, storeDirectory = "/home/george/Classes/2024-Sp-Math190/_cache"
141
, tmpDirectory = "/home/george/Classes/2024-Sp-Math190/_cache/tmp"
142
, previewPort = 9090
143
, deployCommand = "bash /home/george/Classes/2024-Sp-Math190/deploy.sh"
144
}
145
146