-
Notifications
You must be signed in to change notification settings - Fork 9
/
site.hs
92 lines (81 loc) · 3.47 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
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid (mappend)
import Data.List
import Hakyll
import Text.Pandoc
import Text.Pandoc.Walk (walk)
-- import qualified Data.Map as M
main :: IO ()
main = hakyll $ do
match "static/*/*" $ do route idRoute
compile copyFileCompiler
match (fromList tops) $ crunchWithCtx siteCtx
match "lectures/*" $ crunchWithCtxCustom "lecture" postCtx
match "assignments/*" $ crunchWithCtx postCtx
match "discussions/*" $ crunchWithCtx postCtx
match "templates/*" $ compile templateCompiler
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
--------------------------------------------------------------------------------
postCtx :: Context String
postCtx =
dateField "date" "%B %e, %Y" `mappend`
-- constField "headerImg" "Eiffel.jpg" `mappend`
siteCtx
siteCtx :: Context String
siteCtx =
constField "cssUrl" "https://ucsd-cse230.github.io/sp20" `mappend`
constField "baseUrl" "https://ucsd-cse130.github.io/wi21" `mappend`
constField "site_name" "cse130" `mappend`
constField "site_description" "UCSD CSE 130" `mappend`
constField "site_username" "Ranjit Jhala" `mappend`
constField "twitter_username" "ranjitjhala" `mappend`
constField "github_username" "ranjitjhala" `mappend`
constField "google_username" "rjhala@eng.ucsd.edu" `mappend`
constField "google_userid" "u/0/104385825850161331469" `mappend`
constField "piazza_classid" "class/kjivoxdgfuc1w2" `mappend`
constField "canvasUrl" "https://canvas.ucsd.edu/courses/21656" `mappend`
defaultContext
tops =
[ "index.md"
, "grades.md"
, "lectures.md"
, "links.md"
, "assignments.md"
, "calendar.md"
, "contact.md"
]
fac :: Int -> Int
fac 0 = 1
fac n = n * fac (n-1)