forked from haskell-infra/www.haskell.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite.hs
69 lines (52 loc) · 1.79 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
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid ((<>))
import Data.Time.Calendar
import Data.Time.Clock
import Hakyll
import System.FilePath.Posix
--------------------------------------------------------------------------------
main :: IO ()
main = mkContext >>= \ctx -> hakyll $ do
match "img/*" $ do
route idRoute
compile copyFileCompiler
match "css/*" $ do
route idRoute
compile compressCssCompiler
match "js/*" $ do
route idRoute
compile copyFileCompiler
match "index.html" $ do
route idRoute
compile $ defCompiler ctx
match ("**/*.markdown" .||. "*.markdown") $ do
route cleanRoute
compile $ mdCompiler ctx
match "templates/*" $
compile templateCompiler
mdCompiler :: Context String -> Compiler (Item String)
mdCompiler ctx =
pandocCompiler
>>= applyAsTemplate ctx
>>= loadAndApplyTemplate "templates/default.html" ctx
>>= relativizeUrls
defCompiler :: Context String -> Compiler (Item String)
defCompiler ctx = getResourceBody
>>= applyAsTemplate ctx
>>= loadAndApplyTemplate "templates/default.html" ctx
>>= relativizeUrls
mkContext :: IO (Context String)
mkContext = do
(year, _, _) <- toGregorian . utctDay <$> getCurrentTime
return $ constField "year" (show year)
<> dropIndexHtml
<> defaultContext
cleanRoute :: Routes
cleanRoute = customRoute $
(\(p, _) -> p </> "index" <.> "html") . splitExtension . toFilePath
dropIndexHtml :: Context a
dropIndexHtml = mapContext transform (urlField "url") where
transform url = case splitFileName url of
(p, "index.html") -> takeDirectory p
_ -> url