hakyll/examples/rssblog/hakyll.hs

35 lines
1.3 KiB
Haskell
Raw Normal View History

2010-01-02 18:57:12 +00:00
module Main where
import Control.Monad.Reader (liftIO)
import Text.Hakyll (hakyll)
2010-01-02 18:57:12 +00:00
import Text.Hakyll.Render (renderAndConcat, renderChain, css)
import Text.Hakyll.File (getRecursiveContents, directory)
import Text.Hakyll.Renderables (createPagePath, createCustomPage, createListing)
2010-01-02 18:57:12 +00:00
import Data.List (sort)
import Control.Monad (mapM_, liftM)
import Data.Either (Either(..))
main = hakyll $ do
2010-01-02 18:57:12 +00:00
-- Static directory.
directory css "css"
-- Find all post paths.
postPaths <- liftM (reverse . sort) $ getRecursiveContents "posts"
let renderablePosts = map createPagePath postPaths
-- Render index, including recent posts.
let index = createListing "index.html" "templates/postitem.html" (take 3 renderablePosts) [("title", "Home")]
renderChain ["index.html", "templates/default.html"] index
2010-01-02 18:57:12 +00:00
-- Render all posts list.
let posts = createListing "posts.html" "templates/postitem.html" renderablePosts [("title", "All posts")]
renderChain ["posts.html", "templates/default.html"] posts
2010-01-02 18:57:12 +00:00
-- Render all posts.
liftIO $ putStrLn "Generating posts..."
2010-01-02 18:57:12 +00:00
mapM_ (renderChain ["templates/post.html", "templates/default.html"]) renderablePosts
-- Render rss feed
let rss = createListing "rss.xml" "templates/rssitem.xml" (take 3 renderablePosts) []
renderChain ["templates/rss.xml"] rss