summaryrefslogtreecommitdiff
path: root/examples/simpleblog/hakyll.hs
blob: 638861a922b75e14a39428a7c7069c10a30de5e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module Main where

import Text.Hakyll (hakyll)
import Text.Hakyll.Render
import Text.Hakyll.Context
import Text.Hakyll.File (getRecursiveContents, directory)
import Text.Hakyll.Renderables (createPagePath, createCustomPage, createListing)
import Data.List (sort)
import Control.Monad (mapM_, liftM)
import Control.Monad.Reader (liftIO)
import Data.Either (Either(..))

main = hakyll $ do
    -- 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

    -- Render all posts list.
    let posts = createListing "posts.html" "templates/postitem.html" renderablePosts [("title", "All posts")]
    renderChain ["posts.html", "templates/default.html"] posts

    -- Render all posts.
    liftIO $ putStrLn "Generating posts..."
    mapM_ (renderChain ["templates/post.html", "templates/default.html"]) renderablePosts