Created
October 17, 2013 23:56
-
-
Save duk3luk3/7034385 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-------------------------------------------------------------------------------- | |
{-# LANGUAGE OverloadedStrings #-} | |
import Data.Monoid (mappend, mconcat) | |
import Control.Applicative | |
import Hakyll | |
import Hakyll.Web.Tags | |
-------------------------------------------------------------------------------- | |
main :: IO () | |
main = hakyll $ do | |
tags <- buildTags "posts/**" (fromCapture "tags/*.html") | |
match "images/*" $ do | |
route idRoute | |
compile copyFileCompiler | |
match "css/*" $ do | |
route idRoute | |
compile compressCssCompiler | |
match "static_html/*" $ do | |
route $ setExtension "html" `composeRoutes` gsubRoute "static_html/" (const "") | |
compile $ pandocCompiler | |
>>= loadAndApplyTemplate "templates/default.html" defaultContext | |
>>= relativizeUrls | |
match "static/*" $ do | |
route idRoute | |
compile copyFileCompiler | |
match "posts/**" $ do | |
route $ setExtension "html" | |
compile $ do | |
pandocCompiler | |
>>= loadAndApplyTemplate "templates/post.html" (postCtx tags) | |
>>= loadAndApplyTemplate "templates/default.html" (postCtx tags) | |
>>= relativizeUrls | |
create ["archive.html"] $ do | |
route idRoute | |
compile $ do | |
posts <- recentFirst =<< loadAll "posts/**" | |
let archiveCtx = mconcat [ | |
listField "posts" (postCtx tags) (return posts) `mappend` | |
constField "title" "Archives" `mappend` | |
defaultContext | |
, tagCloudCtx tags ] | |
makeItem "" | |
>>= loadAndApplyTemplate "templates/archive.html" archiveCtx | |
>>= loadAndApplyTemplate "templates/default.html" archiveCtx | |
>>= relativizeUrls | |
tagsRules tags $ \tag pattern -> do | |
let title = "Tagged: " ++ tag | |
route idRoute | |
compile $ do | |
posts <- constField "posts" <$> postList pattern (postCtx tags) recentFirst | |
makeItem "" | |
>>= loadAndApplyTemplate "templates/posts.html" posts | |
>>= loadAndApplyTemplate "templates/default.html" defaultContext | |
>>= relativizeUrls | |
match "index.html" $ do | |
route idRoute | |
compile $ do | |
posts <- recentFirst =<< loadAll "posts/**" | |
--cats <- buildCategories "posts/**" | |
let indexCtx = | |
listField "posts" (postCtx tags) (return posts) `mappend` | |
constField "title" "Home" `mappend` | |
defaultContext | |
getResourceBody | |
>>= applyAsTemplate indexCtx | |
>>= loadAndApplyTemplate "templates/default.html" indexCtx | |
>>= relativizeUrls | |
match "templates/*" $ compile templateCompiler | |
-------------------------------------------------------------------------------- | |
postCtx :: Tags -> Context String | |
postCtx tags = mconcat | |
[ dateField "date" "%B %e, %Y" | |
, tagsField "tags" tags | |
, defaultContext | |
] | |
tagCloudCtx :: Tags -> Context String | |
tagCloudCtx tags = field "tagcloud" $ \item -> rendered | |
where rendered = renderTagCloud 85.0 165.0 tags | |
-- | Creates a compiler to render a list of posts for a given pattern, context, | |
-- and sorting/filtering function | |
postList :: Pattern | |
-> Context String | |
-> ([Item String] -> Compiler [Item String]) | |
-> Compiler String | |
postList pattern postCtx sortFilter = do | |
posts <- sortFilter =<< loadAll pattern | |
itemTpl <- loadBody "templates/post-item.html" | |
applyTemplateList itemTpl postCtx posts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment