-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite.hs
175 lines (145 loc) · 5.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
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
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid (mappend)
import Hakyll
import Text.Pandoc.Options
--------------------------------------------------------------------------------
main :: IO ()
main = hakyll $ do
match "images/*" $ do
route idRoute
compile copyFileCompiler
match "css/*" $ do
route idRoute
compile compressCssCompiler
match "vendor/fonts/OpenSans/OpenSans-Regular.ttf" $ do
route idRoute
compile copyFileCompiler
match "vendor/img/*.svg" $ do
route idRoute
compile copyFileCompiler
match "vendor/img/*.png" $ do
route idRoute
compile copyFileCompiler
match "papers/*.pdf" $ do
route idRoute
compile copyFileCompiler
match "talks/*.pdf" $ do
route idRoute
compile copyFileCompiler
match "talks/ressi_2020.mp4" $ do
route idRoute
compile copyFileCompiler
match "files/*" $ do
route idRoute
compile copyFileCompiler
match "contact.**.markdown" $ do
route $ setExtension "html"
compile $ do
lang <- getLang . toFilePath <$> getUnderlying
let ctx = defaultContext
pandocCompiler
>>= loadAndApplyTemplate
(fromFilePath $ "templates/default."++lang++".html") ctx
>>= relativizeUrls
match "posts/*" $ do
route $ setExtension "html"
compile $ pandocCompilerWith def def{
writerHighlight = True
}
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.en.html" postCtx
>>= relativizeUrls
create (map (\l -> fromFilePath $ "archive."++l++".html") langs) $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
lang <- getLang . toFilePath <$> getUnderlying
let archiveCtx =
listField "posts" postCtx (return posts) `mappend`
langContextArchive lang `mappend`
defaultContext
makeItem ""
>>= loadAndApplyTemplate (fromFilePath $ "templates/archive."++lang++".html") archiveCtx
>>= loadAndApplyTemplate (fromFilePath $ "templates/default."++lang++".html") archiveCtx
>>= relativizeUrls
match "index.**.html" $ do
route idRoute
compile $ do
lang <- getLang . toFilePath <$> getUnderlying
let indexCtx =
langContextHome lang `mappend`
defaultContext
getResourceBody >>= loadAndApplyTemplate
(fromFilePath $ "templates/default."++lang++".html")
indexCtx
>>= relativizeUrls
match "templates/*" $ compile templateBodyCompiler
match "teaching/fdv2020/*.pdf" $ do
route idRoute
compile copyFileCompiler
match "teaching/fdv2020/index.markdown" $ do
route $ setExtension "html"
compile $ do
let ctx = defaultContext
pandocCompiler
>>= loadAndApplyTemplate
(fromFilePath $ "templates/default.fr.html") ctx
>>= relativizeUrls
match "teaching/fdv2020_s2/*.pdf" $ do
route idRoute
compile copyFileCompiler
match "teaching/fdv2020_s2/index.markdown" $ do
route $ setExtension "html"
compile $ do
let ctx = defaultContext
pandocCompiler
>>= loadAndApplyTemplate
(fromFilePath $ "templates/default.fr.html") ctx
>>= relativizeUrls
-- RSS and Atom feeds
{-
create ["rss.xml"] $ do
route idRoute
compile $ do
let feedCtx = postCtx `mappend` bodyField "description"
posts <- fmap (take 10) . recentFirst =<<
loadAllSnapshots "posts/*" "content"
renderRss feedConfig feedCtx posts
create ["atom.xml"] $ do
route idRoute
compile $ do
let feedCtx = postCtx `mappend` bodyField "description"
posts <- fmap (take 10) . recentFirst =<<
loadAllSnapshots "posts/*" "content"
renderAtom feedConfig feedCtx posts
-}
--------------------------------------------------------------------------------
langs :: [String]
langs = ["fr","en","eo"]
getLang :: FilePath -> String
getLang path =
case dropWhile (/= '.') path of
[] -> "en"
_ : tl -> takeWhile (/= '.') tl
langContextHome :: String -> Context a
langContextHome "fr" = constField "title" "Accueil"
langContextHome "eo" = constField "title" "Hejmo"
langContextHome _ = constField "title" "Home"
langContextArchive :: String -> Context a
langContextArchive "fr" = constField "title" "Billets"
langContextArchive "eo" = constField "title" "Publikaĵoj"
langContextArchive _ = constField "title" "Posts"
postCtx :: Context String
postCtx =
dateField "date" "%B %e, %Y" `mappend`
defaultContext
feedConfig :: FeedConfiguration
feedConfig = FeedConfiguration
{ feedTitle = "Otini's weblog"
, feedDescription = "Blog posts from Olivier Nicole"
, feedAuthorName = "Olivier Nicole"
, feedAuthorEmail = "[email protected]"
, feedRoot = "https://otini.chnik.fr"
}