2010-01-08 11:41:58 +00:00
|
|
|
module Main where
|
|
|
|
|
2010-03-21 14:57:12 +00:00
|
|
|
import Control.Arrow ((>>>))
|
2010-01-19 19:42:16 +00:00
|
|
|
import Text.Hakyll (hakyll)
|
2010-01-08 11:41:58 +00:00
|
|
|
import Text.Hakyll.Render
|
2010-03-21 14:57:12 +00:00
|
|
|
import Text.Hakyll.Tags (readTagMap, renderTagCloud, renderTagLinks, withTagMap)
|
|
|
|
import Text.Hakyll.Feed (FeedConfiguration (..), renderRss)
|
2010-01-08 11:41:58 +00:00
|
|
|
import Text.Hakyll.File (getRecursiveContents, directory, removeSpaces)
|
2010-03-21 14:57:12 +00:00
|
|
|
import Text.Hakyll.CreateContext (createPage, createCustomPage, createListing)
|
|
|
|
import Text.Hakyll.ContextManipulations (renderDate, copyValue)
|
2010-01-08 11:41:58 +00:00
|
|
|
import Data.List (sort)
|
|
|
|
import Data.Map (toList)
|
|
|
|
import Control.Monad (mapM_, liftM)
|
|
|
|
import Data.Either (Either(..))
|
|
|
|
|
2010-03-21 14:57:12 +00:00
|
|
|
main = hakyll "http://example.com" $ do
|
2010-01-08 11:41:58 +00:00
|
|
|
-- Static directory.
|
|
|
|
directory css "css"
|
|
|
|
|
|
|
|
-- Find all post paths.
|
|
|
|
postPaths <- liftM (reverse . sort) $ getRecursiveContents "posts"
|
2010-03-21 14:57:12 +00:00
|
|
|
let renderablePosts = map ((>>> postManipulation) . createPage) postPaths
|
2010-01-08 11:41:58 +00:00
|
|
|
|
|
|
|
-- Read tag map.
|
2010-03-21 14:57:12 +00:00
|
|
|
let tagMap = readTagMap "postTags" postPaths
|
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-03-24 14:30:51 +00:00
|
|
|
let renderListForTag tag posts = renderPostList (tagToUrl tag) ("Posts tagged " ++ tag)
|
|
|
|
(map (>>> postManipulation) posts)
|
|
|
|
withTagMap tagMap renderPostList
|
2010-01-08 11:41:58 +00:00
|
|
|
|
|
|
|
-- Render index, including recent posts.
|
2010-03-21 14:57:12 +00:00
|
|
|
let tagCloud = tagMap >>> renderTagCloud tagToUrl 100 200
|
|
|
|
index = createListing "index.html"
|
|
|
|
["templates/postitem.html"]
|
|
|
|
(take 3 renderablePosts)
|
|
|
|
[ ("title", Left "Home")
|
|
|
|
, ("tagcloud", Right tagCloud)
|
|
|
|
]
|
2010-01-29 11:19:53 +00:00
|
|
|
renderChain ["index.html", "templates/default.html"] index
|
2010-01-08 11:41:58 +00:00
|
|
|
|
|
|
|
-- Render all posts.
|
2010-03-21 14:57:12 +00:00
|
|
|
mapM_ (renderChain ["templates/post.html"
|
|
|
|
,"templates/default.html"
|
|
|
|
]) renderablePosts
|
2010-01-08 11:41:58 +00:00
|
|
|
|
|
|
|
-- Render rss feed
|
2010-03-21 14:57:12 +00:00
|
|
|
renderRss myFeedConfiguration $
|
|
|
|
map (>>> copyValue "body" "description") (take 3 renderablePosts)
|
2010-01-08 11:41:58 +00:00
|
|
|
|
2010-03-21 14:57:12 +00:00
|
|
|
where postManipulation = renderDate "date" "%B %e, %Y" "Date unknown"
|
|
|
|
>>> 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-03-21 14:57:12 +00:00
|
|
|
let list = createListing url ["templates/postitem.html"] posts [("title", Left title)]
|
2010-01-29 11:19:53 +00:00
|
|
|
renderChain ["posts.html", "templates/default.html"] list
|
2010-03-21 14:57:12 +00:00
|
|
|
|
|
|
|
myFeedConfiguration = FeedConfiguration
|
|
|
|
{ feedUrl = "rss.xml"
|
|
|
|
, feedTitle = "SimpleBlog RSS feed."
|
|
|
|
, feedDescription = "A simple demo of an RSS feed created with Hakyll."
|
|
|
|
, feedAuthorName = "Jasper Van der Jeugt"
|
|
|
|
}
|