hakyll/data/example/site.hs

73 lines
2.4 KiB
Haskell
Raw Normal View History

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-15 17:02:47 +00:00
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
2012-12-05 22:29:42 +00:00
>>= relativizeUrls
2012-12-07 10:36:20 +00:00
match "posts/*" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
2012-12-07 10:36:20 +00:00
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 ""
>>= 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
>>= 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
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