2010-01-08 11:41:58 +00:00
|
|
|
module Main where
|
|
|
|
|
2010-01-18 20:43:31 +00:00
|
|
|
import Text.Hakyll (hakyll, defaultHakyllConfiguration)
|
2010-01-08 11:41:58 +00:00
|
|
|
import Text.Hakyll.Render
|
|
|
|
import Text.Hakyll.Tags (readTagMap, renderTagCloud, renderTagLinks)
|
|
|
|
import Text.Hakyll.File (getRecursiveContents, directory, removeSpaces)
|
|
|
|
import Text.Hakyll.Renderables (createPagePath, createCustomPage)
|
|
|
|
import Text.Hakyll.Context (ContextManipulation, renderDate)
|
|
|
|
import Data.List (sort)
|
|
|
|
import Data.Map (toList)
|
|
|
|
import Control.Monad (mapM_, liftM)
|
|
|
|
import Data.Either (Either(..))
|
|
|
|
|
2010-01-18 20:43:31 +00:00
|
|
|
main = hakyll defaultHakyllConfiguration $ do
|
2010-01-08 11:41:58 +00:00
|
|
|
-- Static directory.
|
|
|
|
directory css "css"
|
|
|
|
|
|
|
|
-- Find all post paths.
|
|
|
|
postPaths <- liftM (reverse . sort) $ getRecursiveContents "posts"
|
|
|
|
let renderablePosts = map createPagePath postPaths
|
|
|
|
|
|
|
|
-- Read tag map.
|
|
|
|
tagMap <- readTagMap postPaths
|
|
|
|
|
|
|
|
-- Render all posts list.
|
|
|
|
renderPostList "posts.html" "All posts" postPaths
|
|
|
|
|
|
|
|
-- Render post list per tag
|
|
|
|
mapM_ (\(tag, posts) -> renderPostList (tagToURL tag) ("Posts tagged " ++ tag) posts)
|
|
|
|
(toList tagMap)
|
|
|
|
|
|
|
|
-- Render index, including recent posts.
|
|
|
|
let recentPosts = renderAndConcatWith postManipulation
|
2010-01-18 20:43:31 +00:00
|
|
|
["templates/postitem.html"]
|
2010-01-08 11:41:58 +00:00
|
|
|
(take 3 renderablePosts)
|
|
|
|
renderChain ["index.html", "templates/default.html"] $
|
|
|
|
createCustomPage "index.html" ("templates/postitem.html" : take 3 postPaths)
|
2010-01-08 12:33:43 +00:00
|
|
|
[("title", Left "Home"), ("posts", Right recentPosts),
|
|
|
|
("tagcloud", Left $ renderTagCloud tagMap tagToURL 100 200)]
|
2010-01-08 11:41:58 +00:00
|
|
|
|
|
|
|
-- Render all posts.
|
|
|
|
mapM_ (renderChainWith postManipulation
|
|
|
|
["templates/post.html"
|
|
|
|
,"templates/default.html"
|
|
|
|
]) renderablePosts
|
|
|
|
|
|
|
|
-- Render rss feed
|
2010-01-18 20:43:31 +00:00
|
|
|
let recentRSSItems = renderAndConcat ["templates/rssitem.xml"] $ take 3 renderablePosts
|
2010-01-08 11:41:58 +00:00
|
|
|
let rssPage = createCustomPage "rss.xml"
|
|
|
|
("templates/postitem.html" : take 3 postPaths)
|
|
|
|
[("items", Right recentRSSItems)]
|
|
|
|
renderChain ["templates/rss.xml"] rssPage
|
|
|
|
|
|
|
|
-- Render index.
|
|
|
|
renderChain ["templates/default.html"] $ createPagePath "index.html"
|
|
|
|
|
|
|
|
where postManipulation :: ContextManipulation
|
|
|
|
postManipulation = renderDate "date" "%B %e, %Y" "Date unknown"
|
|
|
|
. renderTagLinks tagToURL
|
|
|
|
|
2010-01-11 09:02:33 +00:00
|
|
|
tagToURL tag = "$root/tags/" ++ removeSpaces tag ++ ".html"
|
2010-01-08 11:41:58 +00:00
|
|
|
|
|
|
|
renderPostList url title posts = do
|
|
|
|
let postItems = renderAndConcatWith postManipulation
|
2010-01-18 20:43:31 +00:00
|
|
|
["templates/postitem.html"]
|
2010-01-08 11:41:58 +00:00
|
|
|
(map createPagePath posts)
|
|
|
|
customPage = createCustomPage url
|
|
|
|
("templates/postitem.html" : posts)
|
|
|
|
[("title", Left title), ("posts", Right postItems)]
|
|
|
|
renderChain ["posts.html", "templates/default.html"] customPage
|