2012-12-05 22:29:42 +00:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2012-12-13 10:08:41 +00:00
|
|
|
import Control.Applicative ((<$>))
|
|
|
|
import Data.Monoid (mappend)
|
|
|
|
import Hakyll
|
2012-12-05 22:29:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
main :: IO ()
|
|
|
|
main = hakyll $ do
|
|
|
|
match "images/*" $ do
|
|
|
|
route idRoute
|
|
|
|
compile copyFileCompiler
|
|
|
|
|
|
|
|
match "css/*" $ do
|
|
|
|
route idRoute
|
|
|
|
compile compressCssCompiler
|
|
|
|
|
2012-12-13 10:08:41 +00:00
|
|
|
match (fromList ["about.rst", "contact.markdown"]) $ do
|
2012-12-05 22:29:42 +00:00
|
|
|
route $ setExtension "html"
|
2012-12-13 21:25:28 +00:00
|
|
|
compile $ do
|
|
|
|
|
|
|
|
defaultTpl <- loadBody "templates/default.html"
|
|
|
|
pageCompiler
|
|
|
|
>>= applyTemplate defaultTpl defaultContext
|
|
|
|
>>= relativizeUrls
|
|
|
|
{-
|
2012-12-05 22:29:42 +00:00
|
|
|
compile $ pageCompiler
|
2012-12-13 21:25:28 +00:00
|
|
|
>>= loadAndApplyTemplate "templates/default.html" defaultContext
|
2012-12-05 22:29:42 +00:00
|
|
|
>>= relativizeUrls
|
2012-12-13 21:25:28 +00:00
|
|
|
-}
|
2012-12-05 22:29:42 +00:00
|
|
|
|
2012-12-07 10:36:20 +00:00
|
|
|
match "posts/*" $ do
|
|
|
|
route $ setExtension "html"
|
|
|
|
compile $ do
|
|
|
|
post <- pageCompiler
|
|
|
|
saveSnapshot "content" post
|
|
|
|
return post
|
2012-12-13 21:25:28 +00:00
|
|
|
>>= loadAndApplyTemplate "templates/post.html" postCtx
|
|
|
|
>>= loadAndApplyTemplate "templates/default.html" postCtx
|
2012-12-07 10:36:20 +00:00
|
|
|
>>= relativizeUrls
|
|
|
|
|
2012-12-13 10:08:41 +00:00
|
|
|
match "archive.html" $ do
|
|
|
|
route idRoute
|
|
|
|
compile $ do
|
|
|
|
let archiveCtx =
|
|
|
|
field "posts" (\_ -> postList recentFirst) `mappend`
|
|
|
|
constField "title" "Archives" `mappend`
|
|
|
|
defaultContext
|
|
|
|
|
|
|
|
makeItem ""
|
2012-12-13 21:25:28 +00:00
|
|
|
>>= loadAndApplyTemplate "templates/archive.html" archiveCtx
|
|
|
|
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
|
2012-12-13 10:08:41 +00:00
|
|
|
>>= relativizeUrls
|
|
|
|
|
|
|
|
|
2012-12-07 10:36:20 +00:00
|
|
|
match "index.html" $ do
|
|
|
|
route idRoute
|
|
|
|
compile $ do
|
2012-12-13 10:08:41 +00:00
|
|
|
let indexCtx = field "posts" $ \_ -> postList (take 3 . recentFirst)
|
|
|
|
|
|
|
|
getResourceBody
|
2012-12-13 21:25:28 +00:00
|
|
|
>>= applyAsTemplate indexCtx
|
|
|
|
>>= loadAndApplyTemplate "templates/default.html" postCtx
|
2012-12-07 10:36:20 +00:00
|
|
|
>>= relativizeUrls
|
|
|
|
|
2012-12-05 22:29:42 +00:00
|
|
|
match "templates/*" $ compile templateCompiler
|
2012-12-13 10:08:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
postCtx :: Context String
|
|
|
|
postCtx =
|
|
|
|
dateField "date" "%B %e, %Y" `mappend`
|
|
|
|
defaultContext
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
postList :: ([Item String] -> [Item String]) -> Compiler String
|
|
|
|
postList preprocess = do
|
2012-12-13 21:25:28 +00:00
|
|
|
posts <- preprocess <$> loadAll "posts/*"
|
|
|
|
itemTpl <- loadBody "templates/post-item.html"
|
2012-12-13 10:08:41 +00:00
|
|
|
list <- applyTemplateList itemTpl postCtx posts
|
|
|
|
return list
|