1 --------------------------------------------------------------------------------
2 {-# LANGUAGE OverloadedStrings #-}
3 import Control.Applicative ((<$>))
4 import Data.Monoid ((<>))
7 import qualified Data.Set as S
8 import Data.Maybe (fromMaybe)
9 import Text.Pandoc.Options
11 config :: Configuration
12 config = defaultConfiguration
14 "rsync -Havz _site/ rekado@elephly.net:/home/rekado/elephly.net" }
16 myFeedConfiguration :: FeedConfiguration
17 myFeedConfiguration = FeedConfiguration
18 { feedTitle = "Rekado's website"
19 , feedDescription = "Music, words, and hacking"
20 , feedAuthorName = "Rekado"
21 , feedAuthorEmail = "rekado+feed@elephly.net"
22 , feedRoot = "http://elephly.net"
25 --------------------------------------------------------------------------------
27 main = hakyllWith config $ do
28 tags <- buildTags "posts/*.markdown" (fromCapture "tags/*.html")
31 .||. "js/hyphenator/*"
32 .||. "js/hyphenator/patterns/*"
36 .||. "downies/music/*"
39 .||. "images/posts/*/*"
44 compile copyFileCompiler
48 compile compressCssCompiler
50 -- place static markdown files in site root
51 match ( "static/*.markdown" .||. "static/*/*.markdown" ) $ do
52 route $ setExtension "html"
53 `composeRoutes` gsubRoute "static/" (const "")
54 compile $ pandocCompiler
55 >>= loadAndApplyTemplate "templates/default.html" defaultContext
58 -- place static html files in site root
59 match "static/*.html" $ do
60 route $ gsubRoute "static/" (const "")
63 >>= loadAndApplyTemplate "templates/default.html" defaultContext
66 match "posts/*.markdown" $ do
67 route $ setExtension "html"
68 compile defaultCompiler
71 match "posts/2010-03-28-elephly.markdown" $ version "direct" $ do
72 route $ constRoute "elephly.html"
73 compile defaultCompiler
75 match "posts/2010-03-23-fur-man.markdown" $ version "direct" $ do
76 route $ constRoute "fur-man.html"
77 compile defaultCompiler
80 create ["posts/index.html"] $ do
86 constField "title" title <>
87 field "posts" (\_ -> postList "posts/*.markdown" recentFirst) <>
88 field "tags" (\_ -> renderTagList tags) <>
92 >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
93 >>= loadAndApplyTemplate "templates/default.html" archiveCtx
96 create ["rss.xml"] $ postFeed renderRss
97 create ["atom.xml"] $ postFeed renderAtom
99 -- always show the most recent blog post
100 create ["posts/latest.html"] $ do
103 mostRecent <- fmap head . recentFirst =<< loadAllSnapshots "posts/*.markdown" "non-relative"
104 makeItem (itemBody mostRecent) >>= relativizeUrls
107 tagsRules tags $ \tag pattern -> do
108 let title = "Posts tagged “" ++ tag ++ "”"
112 let ctx = constField "title" title <>
113 field "posts" (\_ -> postList pattern recentFirst) <>
114 tagsField "tags" tags <>
118 >>= loadAndApplyTemplate "templates/archive.html" ctx
119 >>= loadAndApplyTemplate "templates/default.html" ctx
122 match "templates/*" $ compile templateCompiler
125 --------------------------------------------------------------------------------
126 postCtx :: Context String
127 postCtx = dateField "date" "%B %e, %Y"
133 -- If a post declares a certain key in the metadata header,
134 -- load the given template, otherwise ignore.
135 snippet :: String -> String -> Identifier -> Context String
136 snippet name key templatePath = field name $ \item -> do
137 metadata <- getMetadata (itemIdentifier item)
138 case M.lookup key metadata of
139 Just file -> itemBody <$> loadAndApplyTemplate templatePath postCtx item
142 photoSnippet = snippet "photo-snippet" "photo" "templates/photo.html"
143 flattrSnippet = snippet "flattr-snippet" "flattr" "templates/flattr.html"
144 licenseSnippet = snippet "license-snippet" "license" "templates/license.html"
146 postFeed renderer = do
149 let feedCtx = postCtx <> bodyField "description"
150 posts <- fmap (take 10) . recentFirst =<<
151 loadAllSnapshots "posts/*.markdown" "content"
152 renderer myFeedConfiguration feedCtx posts
154 --------------------------------------------------------------------------------
155 postList :: Pattern -> ([Item String] -> Compiler [Item String]) -> Compiler String
156 postList pattern sortFilter = do
157 posts <- sortFilter =<< loadAll (pattern .&&. hasNoVersion)
158 itemTpl <- loadBody "templates/post-item.html"
159 list <- applyTemplateList itemTpl postCtx posts
162 customPandocCompiler :: Compiler (Item String)
163 customPandocCompiler =
165 (addRExt [Ext_pipe_tables] defaultHakyllReaderOptions)
166 (addWExt [Ext_pipe_tables] defaultHakyllWriterOptions)
169 opts { readerExtensions = S.union (S.fromList es) (readerExtensions opts)
173 opts { writerExtensions = S.union (S.fromList es) (writerExtensions opts) }
175 defaultCompiler = customPandocCompiler
176 >>= loadAndApplyTemplate "templates/post.html" postCtx
177 >>= saveSnapshot "content"
178 >>= loadAndApplyTemplate "templates/default.html" postCtx
179 >>= saveSnapshot "non-relative"