@@ -0,0 +1,46 @@
1+module Main where
2+
3+import Control.Arrow ((>>>))
4+import Text.Hakyll (hakyll)
5+import Text.Hakyll.Render
6+import Text.Hakyll.Context
7+import Text.Hakyll.File (getRecursiveContents, directory)
8+import Text.Hakyll.CreateContext (createPage, createCustomPage, createListing)
9+import Text.Hakyll.ContextManipulations (copyValue)
10+import Text.Hakyll.Feed (FeedConfiguration (..), renderRss)
11+import Data.List (sort)
12+import Control.Monad (mapM_, liftM)
13+import Control.Monad.Reader (liftIO)
14+import Data.Either (Either(..))
15+
16+main = hakyll "http://example.com" $ do
17+ -- Static directory.
18+ directory css "css"
19+
20+ -- Find all post paths.
21+ postPaths <- liftM (reverse . sort) $ getRecursiveContents "posts"
22+ let postPages = map createPage postPaths
23+
24+ -- Render index, including recent posts.
25+ let index = createListing "index.html" ["templates/postitem.html"] (take 3 postPages) [("title", Left "Home")]
26+ renderChain ["index.html", "templates/default.html"] index
27+
28+ -- Render all posts list.
29+ let posts = createListing "posts.html" ["templates/postitem.html"] postPages [("title", Left "All posts")]
30+ renderChain ["posts.html", "templates/default.html"] posts
31+
32+ -- Render all posts.
33+ liftIO $ putStrLn "Generating posts..."
34+ mapM_ (renderChain ["templates/post.html", "templates/default.html"]) postPages
35+
36+ -- Render RSS feed.
37+ let
38+ renderRss myFeedConfiguration $
39+ map (>>> copyValue "body" "description") (take 3 postPages)
40+
41+myFeedConfiguration = FeedConfiguration
42+ { feedUrl = "rss.xml"
43+ , feedTitle = "SimpleBlog RSS feed."
44+ , feedDescription = "A simple demo of an RSS feed created with Hakyll."
45+ , feedAuthorName = "Jasper Van der Jeugt"
46+ }