forked from nadia-polikarpova/cse130-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.hs
86 lines (76 loc) · 3.23 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
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid (mappend)
import Data.List
import Hakyll
import Text.Pandoc
import Text.Pandoc.Walk (walk)
crunchWithCtx ctx = do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/page.html" ctx
>>= loadAndApplyTemplate "templates/default.html" ctx
>>= relativizeUrls
crunchWithCtxCustom mode ctx = do
route $ setExtension "html"
compile $ pandocCompilerWithTransform
defaultHakyllReaderOptions
defaultHakyllWriterOptions
(walk (toggleMode mode . haskellizeBlock) . walk haskellizeInline)
>>= loadAndApplyTemplate "templates/page.html" ctx
>>= loadAndApplyTemplate "templates/default.html" ctx
>>= relativizeUrls
-- | Treat an ordered list with uppercase roman numerals as a map:
-- in each item, the first paragraph is the key, and the second is the value;
-- pick the value with key `mode` and discard all other items
toggleMode :: String -> Block -> Block
toggleMode mode (OrderedList (_, UpperRoman, _) items) = select items
where
select ([Para [Str key], payload] : rest) =
if key == mode then payload else select rest
select _ = Null
toggleMode _ b = b
-- | Make inline code Haskell by default
haskellizeInline :: Inline -> Inline
haskellizeInline (Code (ident, [], kvs) str) = Code (ident, ["haskell"], kvs) str
haskellizeInline i = i
-- | Make code blocks Haskell by default
haskellizeBlock :: Block -> Block
haskellizeBlock (CodeBlock (ident, [], kvs) str) = CodeBlock (ident, ["haskell"], kvs) str
haskellizeBlock b = b
--------------------------------------------------------------------------------
main :: IO ()
main = hakyll $ do
match "static/*/*" $ do route idRoute
compile copyFileCompiler
match (fromList tops) $ crunchWithCtx siteCtx
match "lectures/*" $ crunchWithCtxCustom "final" postCtx
match "assignments/*" $ crunchWithCtx postCtx
match "templates/*" $ compile templateCompiler
--------------------------------------------------------------------------------
postCtx :: Context String
postCtx =
dateField "date" "%B %e, %Y" `mappend`
-- constField "headerImg" "Eiffel.jpg" `mappend`
siteCtx
siteCtx :: Context String
siteCtx =
constField "baseUrl" "https://nadia-polikarpova.github.io/cse130-web" `mappend`
constField "site_name" "cse130" `mappend`
constField "site_description" "UCSD CSE 130" `mappend`
constField "site_username" "Nadia Polikarpova" `mappend`
constField "twitter_username" "polikarn" `mappend`
constField "github_username" "nadia-polikarpova" `mappend`
constField "google_username" "[email protected]" `mappend`
constField "google_userid" "u/0/104385825850161331469" `mappend`
constField "piazza_classid" "ucsd/winter2019/cse130/home" `mappend`
defaultContext
tops =
[ "index.md"
, "grades.md"
, "lectures.md"
, "links.md"
, "assignments.md"
, "calendar.md"
, "contact.md"
]