-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.hs
executable file
·86 lines (71 loc) · 2.42 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
#!/usr/bin/env cabal
{- cabal:
build-depends:
base >= 4.18 && < 4.20,
filepath ^>= 1.4.100.1,
hakyll >= 4.16 && < 4.17,
-}
{-# LANGUAGE OverloadedStrings #-}
import Data.String (String)
import Hakyll
import System.FilePath (dropExtension, takeDirectory, takeFileName, (</>))
main :: IO ()
main = hakyll $ do
match ("images/**" .||. "gallery/**" .||. "style.css") $ do
route idRoute
compile copyFileCompiler
match "blog/**" $ do
route cleanRoute
compile $
pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" blogPostContext
>>= loadAndApplyTemplate "templates/default.html" defaultContext
match "index.md" $ do
route $ setExtension "html"
compile $
pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
match "installing.md" $ do
route cleanRoute
compile $
pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
match "blog.html" $ do
route cleanRoute
compile $
getResourceBody
>>= applyAsTemplate blogListContext
>>= loadAndApplyTemplate "templates/default.html" defaultContext
create ["gallery.html"] $ do
route cleanRoute
compile $ do
images <- loadAll "gallery/*.png"
imgTpl <- loadBody "templates/gallery-image.html"
-- See https://github.com/jaspervdj/hakyll/issues/717
-- and example in https://github.com/goolord/skyespace/blob/master/src/Main.hs
let imgCtx :: Context CopyFile
imgCtx = metadataField <> urlField "url"
imgs <- applyTemplateList imgTpl imgCtx images
let galleryCtx =
constField "images" imgs
<> constField "title" "Gallery"
<> defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/gallery.html" galleryCtx
>>= loadAndApplyTemplate "templates/default.html" galleryCtx
match "templates/*" $ compile templateBodyCompiler
cleanRoute :: Routes
cleanRoute = customRoute $ (</> "index.html") . dropExtension . toFilePath
blogPostContext :: Context String
blogPostContext =
dateField "date" "%B %e, %Y"
<> mapContext stripIndex (urlField "url")
<> defaultContext
where
stripIndex url
| takeFileName url == "index.html" = takeDirectory url
| otherwise = url
blogListContext :: Context String
blogListContext =
listField "posts" blogPostContext (recentFirst =<< loadAll "blog/*")
<> defaultContext