on 792fcdf help sign in
72 lines 2.4 kB history raw
1--------------------------------------------------------------------------------
2{-# LANGUAGE OverloadedStrings #-}
3import Data.Monoid (mappend)
4import Hakyll
7--------------------------------------------------------------------------------
8main :: IO ()
9main = hakyll $ do
10 match "images/*" $ do
11 route idRoute
12 compile copyFileCompiler
14 match "css/*" $ do
15 route idRoute
16 compile compressCssCompiler
18 match (fromList ["about.rst", "contact.markdown"]) $ do
19 route $ setExtension "html"
20 compile $ pandocCompiler
21 >>= loadAndApplyTemplate "templates/default.html" defaultContext
22 >>= relativizeUrls
24 match "posts/*" $ do
25 route $ setExtension "html"
26 compile $ pandocCompiler
27 >>= loadAndApplyTemplate "templates/post.html" postCtx
28 >>= loadAndApplyTemplate "templates/default.html" postCtx
29 >>= relativizeUrls
31 create ["archive.html"] $ do
32 route idRoute
33 compile $ do
34 let archiveCtx =
35 field "posts" (\_ -> postList recentFirst) `mappend`
36 constField "title" "Archives" `mappend`
37 defaultContext
39 makeItem ""
40 >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
41 >>= loadAndApplyTemplate "templates/default.html" archiveCtx
42 >>= relativizeUrls
45 match "index.html" $ do
46 route idRoute
47 compile $ do
48 let indexCtx = field "posts" $ \_ ->
49 postList $ fmap (take 3) . recentFirst
51 getResourceBody
52 >>= applyAsTemplate indexCtx
53 >>= loadAndApplyTemplate "templates/default.html" postCtx
54 >>= relativizeUrls
56 match "templates/*" $ compile templateCompiler
59--------------------------------------------------------------------------------
60postCtx :: Context String
61postCtx =
62 dateField "date" "%B %e, %Y" `mappend`
63 defaultContext
66--------------------------------------------------------------------------------
67postList :: ([Item String] -> Compiler [Item String]) -> Compiler String
68postList sortFilter = do
69 posts <- sortFilter =<< loadAll "posts/*"
70 itemTpl <- loadBody "templates/post-item.html"
71 list <- applyTemplateList itemTpl postCtx posts
72 return list