on 2c4e773 help sign in
75 lines 2.5 kB history raw
1--------------------------------------------------------------------------------
2{-# LANGUAGE OverloadedStrings #-}
3import Control.Applicative ((<$>))
4import Data.Monoid (mappend)
5import Hakyll
8--------------------------------------------------------------------------------
9main :: IO ()
10main = hakyll $ do
11 match "images/*" $ do
12 route idRoute
13 compile copyFileCompiler
15 match "css/*" $ do
16 route idRoute
17 compile compressCssCompiler
19 match (fromList ["about.rst", "contact.markdown"]) $ do
20 route $ setExtension "html"
21 compile $ pandocCompiler
22 >>= loadAndApplyTemplate "templates/default.html" defaultContext
23 >>= relativizeUrls
25 match "posts/*" $ do
26 route $ setExtension "html"
27 compile $ do
28 post <- pandocCompiler
29 saveSnapshot "content" post
30 return post
31 >>= loadAndApplyTemplate "templates/post.html" postCtx
32 >>= loadAndApplyTemplate "templates/default.html" postCtx
33 >>= relativizeUrls
35 match "archive.html" $ do
36 route idRoute
37 compile $ do
38 let archiveCtx =
39 field "posts" (\_ -> postList recentFirst) `mappend`
40 constField "title" "Archives" `mappend`
41 defaultContext
43 makeItem ""
44 >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
45 >>= loadAndApplyTemplate "templates/default.html" archiveCtx
46 >>= relativizeUrls
49 match "index.html" $ do
50 route idRoute
51 compile $ do
52 let indexCtx = field "posts" $ \_ -> postList (take 3 . recentFirst)
54 getResourceBody
55 >>= applyAsTemplate indexCtx
56 >>= loadAndApplyTemplate "templates/default.html" postCtx
57 >>= relativizeUrls
59 match "templates/*" $ compile templateCompiler
62--------------------------------------------------------------------------------
63postCtx :: Context String
64postCtx =
65 dateField "date" "%B %e, %Y" `mappend`
66 defaultContext
69--------------------------------------------------------------------------------
70postList :: ([Item String] -> [Item String]) -> Compiler String
71postList preprocess = do
72 posts <- preprocess <$> loadAll "posts/*"
73 itemTpl <- loadBody "templates/post-item.html"
74 list <- applyTemplateList itemTpl postCtx posts
75 return list