Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
83 lines (68 sloc) 2.51 KB
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid (mappend)
import Hakyll
import Data.List (sortBy,isSuffixOf)
import System.FilePath.Posix (takeBaseName,takeDirectory,(</>))
main :: IO ()
main = hakyll $ do
match "images/*" $ do
route idRoute
compile copyFileCompiler
match "css/*" $ do
route idRoute
compile compressCssCompiler
match "files/*" $ do
route idRoute
compile copyFileCompiler
match "404.html" $ do
route idRoute
compile $ do
getResourceBody
>>= loadAndApplyTemplate "templates/default.html" postCtx
match "posts/*" $ do
route $ niceRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
match "henri/*" $ do
route $ niceRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/basic.html" postCtx
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
match "index.html" $ do
route idRoute
compile $ do
let indexCtx = field "posts" $ \_ ->
postList $ recentFirst
getResourceBody
>>= applyAsTemplate indexCtx
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
>>= cleanIndexUrls
match "templates/*" $ compile templateCompiler
niceRoute :: Routes
niceRoute = customRoute createIndexRoute
where
createIndexRoute ident = takeDirectory p
</> drop 11 (takeBaseName p)
</> "index.html"
where p = toFilePath ident
cleanIndexUrls :: Item String -> Compiler (Item String)
cleanIndexUrls = return . fmap (withUrls clean)
where
idx = "index.html"
clean url
| idx `isSuffixOf` url = take (length url - length idx) url
| otherwise = url
postCtx :: Context String
postCtx =
dateField "date" "%B %e, %Y" `mappend`
defaultContext
postList :: ([Item String] -> Compiler [Item String]) -> Compiler String
postList sortFilter = do
posts <- sortFilter =<< loadAll "posts/*"
itemTpl <- loadBody "templates/post-item.html"
list <- applyTemplateList itemTpl postCtx posts
return list