2010-01-08 11:41:58 +00:00
|
|
|
module Main where
|
|
|
|
|
2010-01-19 19:42:16 +00:00
|
|
|
import Text.Hakyll (hakyll)
|
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)
|
2010-01-29 14:16:08 +00:00
|
|
|
import Text.Hakyll.Renderables (createPagePath, createCustomPage, createListingWith, createListing)
|
2010-01-08 11:41:58 +00:00
|
|
|
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-19 19:42:16 +00:00
|
|
|
main = hakyll $ 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.
|
2010-01-29 11:19:53 +00:00
|
|
|
tagMap <- readTagMap "postTags" renderablePosts
|
2010-01-08 11:41:58 +00:00
|
|
|
|
|
|
|
-- Render all posts list.
|
2010-01-29 11:19:53 +00:00
|
|
|
renderPostList "posts.html" "All posts" renderablePosts
|
2010-01-08 11:41:58 +00:00
|
|
|
|
|
|
|
-- Render post list per tag
|
2010-01-31 10:19:57 +00:00
|
|
|
mapM_ (\(tag, posts) -> renderPostList (tagToUrl tag) ("Posts tagged " ++ tag) posts)
|
2010-01-08 11:41:58 +00:00
|
|
|
(toList tagMap)
|
|
|
|
|
|
|
|
-- Render index, including recent posts.
|
2010-01-31 10:19:57 +00:00
|
|
|
let tagCloud = renderTagCloud tagMap tagToUrl 100 200
|
2010-01-29 12:58:29 +00:00
|
|
|
index = createListingWith postManipulation "index.html"
|
2010-01-29 11:19:53 +00:00
|
|
|
"templates/postitem.html"
|
|
|
|
(take 3 renderablePosts)
|
|
|
|
[ ("title", "Home")
|
|
|
|
, ("tagcloud", tagCloud)
|
|
|
|
]
|
|
|
|
renderChain ["index.html", "templates/default.html"] index
|
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-29 14:16:08 +00:00
|
|
|
let rss = createListing "rss.xml" "templates/rssitem.xml" (take 3 renderablePosts) []
|
|
|
|
renderChain ["templates/rss.xml"] rss
|
2010-01-08 11:41:58 +00:00
|
|
|
|
|
|
|
where postManipulation :: ContextManipulation
|
|
|
|
postManipulation = renderDate "date" "%B %e, %Y" "Date unknown"
|
2010-01-31 10:19:57 +00:00
|
|
|
. renderTagLinks tagToUrl
|
2010-01-08 11:41:58 +00:00
|
|
|
|
2010-01-31 10:19:57 +00:00
|
|
|
tagToUrl tag = "$root/tags/" ++ removeSpaces tag ++ ".html"
|
2010-01-08 11:41:58 +00:00
|
|
|
|
|
|
|
renderPostList url title posts = do
|
2010-01-29 11:19:53 +00:00
|
|
|
let list = createListingWith postManipulation url "templates/postitem.html" posts [("title", title)]
|
|
|
|
renderChain ["posts.html", "templates/default.html"] list
|