kompact-io-landing/example/site.hs

81 lines
2.6 KiB
Haskell

--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid (mappend)
import Hakyll
--------------------------------------------------------------------------------
main :: IO ()
main = hakyll $ do
match "content/favicon.png" $ do
route rmContentPrefix
compile copyFileCompiler
match "content/images/*" $ do
route rmContentPrefix
compile copyFileCompiler
match "content/scripts/*" $ do
route rmContentPrefix
compile copyFileCompiler
match "content/css/*" $ do
route rmContentPrefix
compile compressCssCompiler
match "content/fonts/*" $ do
route rmContentPrefix
compile copyFileCompiler
match (fromList ["content/about.rst", "content/contact.markdown"]) $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
match "content/posts/*" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
create ["archive.html"] $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "content/posts/*"
let archiveCtx =
listField "posts" postCtx (return posts) `mappend`
constField "title" "Archives" `mappend`
defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/archive.html" archiveCtx
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
>>= relativizeUrls
match "content/index.html" $ do
route rmContentPrefix
compile $ do
posts <- recentFirst =<< loadAll "content/posts/*"
let indexCtx =
listField "posts" postCtx (return posts) `mappend`
defaultContext
getResourceBody
>>= applyAsTemplate indexCtx
>>= loadAndApplyTemplate "templates/default.html" indexCtx
>>= relativizeUrls
match "templates/*" $ compile templateBodyCompiler
--------------------------------------------------------------------------------
postCtx :: Context String
postCtx =
dateField "date" "%B %e, %Y" `mappend`
defaultContext
rmContentPrefix = gsubRoute "content/" (const "")