on cfac1bb help sign in
83 lines 2.8 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 $ do
23 defaultTpl <- loadBody "templates/default.html"
24 pageCompiler
25 >>= applyTemplate defaultTpl defaultContext
26 >>= relativizeUrls
27 {-
28 compile $ pageCompiler
29 >>= loadAndApplyTemplate "templates/default.html" defaultContext
30 >>= relativizeUrls
31 -}
33 match "posts/*" $ do
34 route $ setExtension "html"
35 compile $ do
36 post <- pageCompiler
37 saveSnapshot "content" post
38 return post
39 >>= loadAndApplyTemplate "templates/post.html" postCtx
40 >>= loadAndApplyTemplate "templates/default.html" postCtx
41 >>= relativizeUrls
43 match "archive.html" $ do
44 route idRoute
45 compile $ do
46 let archiveCtx =
47 field "posts" (\_ -> postList recentFirst) `mappend`
48 constField "title" "Archives" `mappend`
49 defaultContext
51 makeItem ""
52 >>= loadAndApplyTemplate "templates/archive.html" archiveCtx
53 >>= loadAndApplyTemplate "templates/default.html" archiveCtx
54 >>= relativizeUrls
57 match "index.html" $ do
58 route idRoute
59 compile $ do
60 let indexCtx = field "posts" $ \_ -> postList (take 3 . recentFirst)
62 getResourceBody
63 >>= applyAsTemplate indexCtx
64 >>= loadAndApplyTemplate "templates/default.html" postCtx
65 >>= relativizeUrls
67 match "templates/*" $ compile templateCompiler
70--------------------------------------------------------------------------------
71postCtx :: Context String
72postCtx =
73 dateField "date" "%B %e, %Y" `mappend`
74 defaultContext
77--------------------------------------------------------------------------------
78postList :: ([Item String] -> [Item String]) -> Compiler String
79postList preprocess = do
80 posts <- preprocess <$> loadAll "posts/*"
81 itemTpl <- loadBody "templates/post-item.html"
82 list <- applyTemplateList itemTpl postCtx posts
83 return list