-
Notifications
You must be signed in to change notification settings - Fork 4
/
site.hs
98 lines (78 loc) · 2.95 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
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Monoid ( (<>) )
import Hakyll
import Text.Pandoc
import System.FilePath ( splitFileName, (</>), (<.>) )
blogName = "Jacob Errington"
myDefaultContext
= constField "blogName" blogName
<> defaultContext
main :: IO ()
main = hakyll $ do
-- PAGES --------------------------------------------------------------------
match "pages/index.md" $ do
route $ constRoute "index.html"
compile $ do
pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" myDefaultContext
>>= relativizeUrls
match "pages/blog.md" $ do
route $ constRoute "blog.html"
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
let ctx = listField "posts" postCtx (return posts) <> myDefaultContext
getResourceBody
>>= applyAsTemplate ctx
>>= loadAndApplyTemplate "templates/default.html" ctx
>>= relativizeUrls
match "pages/*" $ do
route $ setExtension "html" `composeRoutes` dropRoute 6
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" myDefaultContext
>>= relativizeUrls
-- RSS FEED -----------------------------------------------------------------
create ["atom.xml"] $ do
route idRoute
compile $ do
let feedCtx = postCtx <> bodyField "description"
posts <- fmap (take 10) . recentFirst
=<< loadAllSnapshots "posts/*" "content"
renderAtom feedConfig feedCtx posts
-- POSTS --------------------------------------------------------------------
match (foldr (.||.) (complement mempty) ["posts/*", "drafts/*"]) $ do
route $ setExtension "html"
compile $ pandocMathCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
-- STATIC RESOURCES ---------------------------------------------------------
match "static/**" $ do
route (dropRoute 7)
compile copyFileCompiler
-- TEMPLATES ----------------------------------------------------------------
match "templates/*" $ compile templateCompiler
postCtx :: Context String
postCtx =
dateField "date" "%B %e, %Y" <>
myDefaultContext
pandocMathCompiler :: Compiler (Item String)
pandocMathCompiler
= pandocCompilerWith readerOptions writerOptions where
readerOptions = defaultHakyllReaderOptions
writerOptions = defaultHakyllWriterOptions
{ writerHTMLMathMethod = MathJax ""
}
feedConfig :: FeedConfiguration
feedConfig = FeedConfiguration
{ feedTitle = "Jacob Thomas Errington's blog"
, feedDescription = "Just another functional programming blog."
, feedAuthorName = "Jacob Thomas Errington"
, feedAuthorEmail = "blog@mail.jerrington.me"
, feedRoot = "https://jerrington.me"
}
-- | A route that drops a given number of characters from a path to
-- produce a route.
dropRoute :: Int -> Routes
dropRoute n = customRoute (drop n . toFilePath)