diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/categoryblog/hakyll.hs | 61 | ||||
-rw-r--r-- | examples/categoryblog/templates/post.html | 2 | ||||
-rw-r--r-- | examples/categoryblog/templates/rss.xml | 9 | ||||
-rw-r--r-- | examples/categoryblog/templates/rssitem.xml | 5 |
4 files changed, 37 insertions, 40 deletions
diff --git a/examples/categoryblog/hakyll.hs b/examples/categoryblog/hakyll.hs index a5f3996..cea7498 100644 --- a/examples/categoryblog/hakyll.hs +++ b/examples/categoryblog/hakyll.hs @@ -1,64 +1,75 @@ module Main where +import Control.Arrow ((>>>), arr) import Text.Hakyll (hakyll) import Text.Hakyll.Render -import Text.Hakyll.Tags (TagMap, readCategoryMap) +import Text.Hakyll.Tags (readCategoryMap, withTagMap) +import Text.Hakyll.Feed (FeedConfiguration (..), renderRss) import Text.Hakyll.File (getRecursiveContents, directory, removeSpaces, sortByBaseName) -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, changeValue) import Text.Hakyll.Util (link) 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 . sortByBaseName) $ getRecursiveContents "posts" - let renderablePosts = map createPagePath postPaths + let renderablePosts = map ((>>> postManipulation) . createPage) postPaths -- Read category map. - categoryMap <- readCategoryMap "categoryMap" renderablePosts + let categoryMap = readCategoryMap "categoryMap" postPaths -- Render all posts list. renderPostList "posts.html" "All posts" renderablePosts -- Render post list per category - mapM_ (\(category, posts) -> renderPostList (categoryToUrl category) ("Posts about " ++ category) posts) - (toList categoryMap) + let renderListForCategory category posts = + renderPostList (categoryToUrl category) ("Posts about " ++ category) + (map (>>> postManipulation) posts) + withTagMap categoryMap renderListForCategory -- Render index, including recent posts. - let index = createListingWith postManipulation "index.html" - "templates/postitem.html" - (take 3 renderablePosts) - [ ("title", "Home") - , ("categories", categoryList categoryMap) - ] + let index = createListing "index.html" + ["templates/postitem.html"] + (take 3 renderablePosts) + [ ("title", Left "Home") + , ("categories", Right $ categoryMap >>> categoryList) + ] 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" + where postManipulation = renderDate "date" "%B %e, %Y" "Date unknown" + >>> renderCategoryLink + + renderCategoryLink = changeValue "category" (\c -> link c $ categoryToUrl c) categoryToUrl category = "$root/categories/" ++ removeSpaces category ++ ".html" - categoryList :: TagMap -> String - categoryList = uncurry categoryListItem <=< toList + categoryList = arr $ uncurry categoryListItem <=< toList categoryListItem category posts = "<li>" ++ link category (categoryToUrl category) ++ " - " ++ show (length posts) ++ " items.</li>" 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/categoryblog/templates/post.html b/examples/categoryblog/templates/post.html index 8ecb87d..224a77d 100644 --- a/examples/categoryblog/templates/post.html +++ b/examples/categoryblog/templates/post.html @@ -1,5 +1,5 @@ <h1>$title</h1> by <em>$author</em> on <strong>$date</strong> -<div>Tagged as: $tags.</div> +<div>Posted in: $category.</div> $body diff --git a/examples/categoryblog/templates/rss.xml b/examples/categoryblog/templates/rss.xml deleted file mode 100644 index be918af..0000000 --- a/examples/categoryblog/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> - $items - </channel> -</rss> diff --git a/examples/categoryblog/templates/rssitem.xml b/examples/categoryblog/templates/rssitem.xml deleted file mode 100644 index 48573d2..0000000 --- a/examples/categoryblog/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> |