diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/tagblog/hakyll.hs | 57 | ||||
-rw-r--r-- | examples/tagblog/templates/rss.xml | 9 | ||||
-rw-r--r-- | examples/tagblog/templates/rssitem.xml | 5 |
3 files changed, 32 insertions, 39 deletions
diff --git a/examples/tagblog/hakyll.hs b/examples/tagblog/hakyll.hs index c2f16cf..515d0d2 100644 --- a/examples/tagblog/hakyll.hs +++ b/examples/tagblog/hakyll.hs @@ -1,60 +1,67 @@ module Main where +import Control.Arrow ((>>>)) import Text.Hakyll (hakyll) import Text.Hakyll.Render -import Text.Hakyll.Tags (readTagMap, renderTagCloud, renderTagLinks) +import Text.Hakyll.Tags (readTagMap, renderTagCloud, renderTagLinks, withTagMap) +import Text.Hakyll.Feed (FeedConfiguration (..), renderRss) import Text.Hakyll.File (getRecursiveContents, directory, removeSpaces) -import Text.Hakyll.Renderables (createPagePath, createCustomPage, createListingWith, createListing) -import Text.Hakyll.Context (ContextManipulation, renderDate) +import Text.Hakyll.CreateContext (createPage, createCustomPage, createListing) +import Text.Hakyll.ContextManipulations (renderDate, copyValue) import Data.List (sort) import Data.Map (toList) import Control.Monad (mapM_, liftM) import Data.Either (Either(..)) -main = hakyll $ do +main = hakyll "http://example.com" $ do -- Static directory. directory css "css" -- Find all post paths. postPaths <- liftM (reverse . sort) $ getRecursiveContents "posts" - let renderablePosts = map createPagePath postPaths + let renderablePosts = map ((>>> postManipulation) . createPage) postPaths -- Read tag map. - tagMap <- readTagMap "postTags" renderablePosts + let tagMap = readTagMap "postTags" postPaths -- Render all posts list. renderPostList "posts.html" "All posts" renderablePosts -- Render post list per tag - mapM_ (\(tag, posts) -> renderPostList (tagToUrl tag) ("Posts tagged " ++ tag) posts) - (toList tagMap) + withTagMap tagMap $ \tag posts -> + renderPostList (tagToUrl tag) ("Posts tagged " ++ tag) (map (>>> postManipulation) posts) -- Render index, including recent posts. - let tagCloud = renderTagCloud tagMap tagToUrl 100 200 - index = createListingWith postManipulation "index.html" - "templates/postitem.html" - (take 3 renderablePosts) - [ ("title", "Home") - , ("tagcloud", tagCloud) - ] + let tagCloud = tagMap >>> renderTagCloud tagToUrl 100 200 + index = createListing "index.html" + ["templates/postitem.html"] + (take 3 renderablePosts) + [ ("title", Left "Home") + , ("tagcloud", Right tagCloud) + ] renderChain ["index.html", "templates/default.html"] index -- Render all posts. - mapM_ (renderChainWith postManipulation - ["templates/post.html" - ,"templates/default.html" - ]) renderablePosts + 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 + renderRss myFeedConfiguration $ + map (>>> copyValue "body" "description") (take 3 renderablePosts) - where postManipulation :: ContextManipulation - postManipulation = renderDate "date" "%B %e, %Y" "Date unknown" - . renderTagLinks tagToUrl + where postManipulation = renderDate "date" "%B %e, %Y" "Date unknown" + >>> renderTagLinks tagToUrl tagToUrl tag = "$root/tags/" ++ removeSpaces tag ++ ".html" renderPostList url title posts = do - let list = createListingWith postManipulation url "templates/postitem.html" posts [("title", title)] + let list = createListing url ["templates/postitem.html"] posts [("title", Left title)] renderChain ["posts.html", "templates/default.html"] list + +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" + } diff --git a/examples/tagblog/templates/rss.xml b/examples/tagblog/templates/rss.xml deleted file mode 100644 index 1217b4e..0000000 --- a/examples/tagblog/templates/rss.xml +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" ?> -<rss version="2.0"> - <channel> - <title>The SimpleBlog</title> - <link>http://example.com</link> - <description>Simple blog in hakyll</description> - $body - </channel> -</rss> diff --git a/examples/tagblog/templates/rssitem.xml b/examples/tagblog/templates/rssitem.xml deleted file mode 100644 index 48573d2..0000000 --- a/examples/tagblog/templates/rssitem.xml +++ /dev/null @@ -1,5 +0,0 @@ -<item> - <title>$title</title> - <link>http://example.com/$url</link> - <description>$title by $author</description> -</item> |