This repository has been archived by the owner on Jan 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.hs
124 lines (104 loc) · 3.66 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
{-# LANGUAGE OverloadedStrings #-}
import Hakyll
main :: IO ()
main = hakyll $ do
create ["CNAME"] $ do
route idRoute
compile $ makeItem ("perplexed.dev" :: String)
match "images/*" $ do
route idRoute
compile copyFileCompiler
match "script/*" $ do
route idRoute
compile copyFileCompiler
match "css/*" $ do
route idRoute
compile compressCssCompiler
match (fromList ["about.org", "contact.org"]) $ do
route $ setExtension "html"
compile
$ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
tags <- buildTags "posts/*" (fromCapture "tags/*.html")
let postCtx = mkPostCtx tags
match "posts/*" $ do
route $ setExtension "html"
compile
$ fmap demoteHeaders
<$> pandocCompiler
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
tagsRules tags $ \tag postPattern -> do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll postPattern
let ctx =
constField "title" ("Posts tagged " <> tag)
<> listField "posts" postCtx (pure posts)
<> defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/post-list.html" ctx
>>= loadAndApplyTemplate "templates/default.html" ctx
>>= relativizeUrls
create ["archive.html"] $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
let archiveCtx =
listField "posts" postCtx (pure posts)
<> constField "title" "Archives"
<> defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/archive.html" archiveCtx
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
>>= relativizeUrls
compileFeed "rss.xml" renderRss
compileFeed "atom.xml" renderAtom
match "index.html" $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
let indexCtx =
listField "posts" postCtx (pure posts)
<> constField "title" "Home"
<> field "tagcloud" (\_ -> renderTagCloud 100.0 165.0 tags)
<> defaultContext
getResourceBody
>>= applyAsTemplate indexCtx
>>= loadAndApplyTemplate "templates/default.html" indexCtx
>>= relativizeUrls
match "templates/*" $ compile templateBodyCompiler
-- | Make the post context from the given collection of tags.
mkPostCtx :: Tags -> Context String
mkPostCtx tags =
mconcat [dateField "date" "%B %e, %Y", tagsField "tags" tags, defaultContext]
-- | Interesting thing of note is if defaultContext is m-appended after
-- bodyField "description", then the RSS/Atom feed description/summary gets
-- bloated with the content of the blog instead of using the description meta
-- data.
feedCtx :: Context String
feedCtx = defaultContext <> bodyField "description"
feedConfiguration :: FeedConfiguration
feedConfiguration = FeedConfiguration
{ feedTitle = "Perplexed Dev Blog"
, feedDescription = "Personal website of Will Bush"
, feedAuthorName = "Will Bush"
, feedAuthorEmail = "will.g.bush@gmail.com"
, feedRoot = "https://perplexed.dev"
}
type FeedRenderer
= FeedConfiguration
-> Context String
-> [Item String]
-> Compiler (Item String)
compileFeed :: Identifier -> FeedRenderer -> Rules ()
compileFeed feedName renderer =
create [feedName] $ do
route idRoute
compile
$ loadAllSnapshots "posts/*" "content"
>>= fmap (take 10) . recentFirst
>>= renderer feedConfiguration feedCtx