on e6868dd help sign in
72 lines 2.4 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 $ pandocCompiler
28 >>= loadAndApplyTemplate "templates/post.html" postCtx
29 >>= loadAndApplyTemplate "templates/default.html" postCtx
30 >>= relativizeUrls
32 match "archive.html" $ do
33 route idRoute
34 compile $ do
35 let archiveCtx =
36 field "posts" (\_ -> postList recentFirst) `mappend`
37 constField "title" "Archives" `mappend`
38 defaultContext
40 makeItem ""
41 >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
42 >>= loadAndApplyTemplate "templates/default.html" archiveCtx
43 >>= relativizeUrls
46 match "index.html" $ do
47 route idRoute
48 compile $ do
49 let indexCtx = field "posts" $ \_ -> postList (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] -> [Item String]) -> Compiler String
68postList preprocess = do
69 posts <- preprocess <$> loadAll "posts/*"
70 itemTpl <- loadBody "templates/post-item.html"
71 list <- applyTemplateList itemTpl postCtx posts
72 return list