diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/tagblog/hakyll.hs | 139 | ||||
-rw-r--r-- | examples/tagblog/posts.html | 4 | ||||
-rw-r--r-- | examples/tagblog/posts/2009-11-05-a-first-post.markdown | 31 | ||||
-rw-r--r-- | examples/tagblog/posts/2009-11-10-another-post.markdown | 19 | ||||
-rw-r--r-- | examples/tagblog/posts/2009-11-28-a-third-post.markdown | 27 | ||||
-rw-r--r-- | examples/tagblog/posts/2009-12-04-this-blog-aint-dead.markdown | 13 | ||||
-rw-r--r-- | examples/tagblog/posts/2009-12-23-almost-christmas.markdown | 15 | ||||
-rw-r--r-- | examples/tagblog/templates/default.html | 14 | ||||
-rw-r--r-- | examples/tagblog/templates/index.html (renamed from examples/tagblog/index.html) | 8 | ||||
-rw-r--r-- | examples/tagblog/templates/post.html | 8 | ||||
-rw-r--r-- | examples/tagblog/templates/postitem.html | 4 | ||||
-rw-r--r-- | examples/tagblog/templates/posts.html | 4 |
12 files changed, 163 insertions, 123 deletions
diff --git a/examples/tagblog/hakyll.hs b/examples/tagblog/hakyll.hs index a81c280..447f232 100644 --- a/examples/tagblog/hakyll.hs +++ b/examples/tagblog/hakyll.hs @@ -1,71 +1,104 @@ +{-# LANGUAGE OverloadedStrings #-} module Main where -import Control.Arrow ((>>>)) -import Text.Hakyll (hakyll) -import Text.Hakyll.Render -import Text.Hakyll.Tags (readTagMap, renderTagCloud, renderTagLinks, withTagMap) -import Text.Hakyll.Feed (FeedConfiguration (..), renderRss) -import Text.Hakyll.File (getRecursiveContents, directory, removeSpaces) -import Text.Hakyll.CreateContext (createPage, createCustomPage, createListing) -import Text.Hakyll.ContextManipulations (renderDate, copyValue) -import Data.List (sort) -import Data.Map (toList) -import Control.Monad (forM_, liftM) -import Data.Either (Either(..)) +import Prelude hiding (id) +import Control.Arrow ((>>>), (***), arr) +import Control.Category (id) +import Control.Monad (forM_) +import qualified Data.Map as M +import Data.Monoid (mempty, mconcat) -main = hakyll "http://example.com" $ do - -- Static directory. - directory css "css" +import Hakyll - -- Find all post paths. - postPaths <- liftM (reverse . sort) $ getRecursiveContents "posts" - let renderablePosts = map ((>>> postManipulation) . createPage) postPaths +main :: IO () +main = hakyll $ do + -- Compress CSS + route "css/*" idRoute + compile "css/*" compressCssCompiler - -- Read tag map. - let tagMap = readTagMap "postTags" postPaths + -- Render posts + route "posts/*" $ setExtension ".html" + compile "posts/*" $ + pageCompiler + >>> arr (renderDateField "date" "%B %e, %Y" "Date unknown") + >>> renderTagsField "prettytags" (fromCaptureString "tags/*") + >>> applyTemplateCompiler "templates/post.html" + >>> applyTemplateCompiler "templates/default.html" + >>> relativizeUrlsCompiler - -- Render all posts list. - renderPostList "posts.html" "All posts" renderablePosts + -- Render posts list + route "posts.html" $ idRoute + create "posts.html" $ + constA mempty + >>> arr (setField "title" "All posts") + >>> requireAllA "posts/*" addPostList + >>> applyTemplateCompiler "templates/posts.html" + >>> applyTemplateCompiler "templates/default.html" + >>> relativizeUrlsCompiler - -- Render post list per tag - let renderListForTag tag posts = - renderPostList (tagToUrl tag) ("Posts tagged " ++ tag) - (map (>>> postManipulation) posts) - withTagMap tagMap renderListForTag + -- Index + route "index.html" $ idRoute + create "index.html" $ + constA mempty + >>> arr (setField "title" "Home") + >>> requireA "tags" (setFieldA "tagcloud" (renderTagCloud')) + >>> requireAllA "posts/*" (id *** arr (take 3 . reverse . sortByBaseName) >>> addPostList) + >>> applyTemplateCompiler "templates/index.html" + >>> applyTemplateCompiler "templates/default.html" + >>> relativizeUrlsCompiler - -- Render index, including recent posts. - 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 + -- Tags + create "tags" $ + requireAll "posts/*" (\_ ps -> readTags ps :: Tags String) - -- Render all posts. - forM_ renderablePosts $ renderChain [ "templates/post.html" - , "templates/default.html" - ] + -- Add a tag list compiler for every tag + route "tags/*" $ setExtension ".html" + metaCompile $ require_ "tags" + >>> arr (M.toList . tagsMap) + >>> arr (map (\(t, p) -> (tagIdentifier t, makeTagList t p))) - -- Render rss feed - renderRss myFeedConfiguration $ - map (>>> copyValue "body" "description") (take 3 renderablePosts) + -- Render RSS feed + route "rss.xml" $ idRoute + create "rss.xml" $ + requireAll_ "posts/*" + >>> renderRss feedConfiguration + -- Read templates + compile "templates/*" templateCompiler + + -- End + return () where - postManipulation = renderDate "date" "%B %e, %Y" "Date unknown" - >>> renderTagLinks tagToUrl + renderTagCloud' :: Compiler (Tags String) String + renderTagCloud' = renderTagCloud tagIdentifier 100 120 + + tagIdentifier :: String -> Identifier + tagIdentifier = fromCaptureString "tags/*" - tagToUrl tag = "$root/tags/" ++ removeSpaces tag ++ ".html" +-- | Auxiliary compiler: generate a post list from a list of given posts, and +-- add it to the current page under @$posts@ +-- +addPostList :: Compiler (Page String, [Page String]) (Page String) +addPostList = setFieldA "posts" $ + arr (reverse . sortByBaseName) + >>> require "templates/postitem.html" (\p t -> map (applyTemplate t) p) + >>> arr mconcat + >>> arr pageBody - renderPostList url title posts = do - let list = createListing url ["templates/postitem.html"] - posts [("title", Left title)] - renderChain ["posts.html", "templates/default.html"] list +makeTagList :: String + -> [Page String] + -> Compiler () (Page String) +makeTagList tag posts = + constA (mempty, posts) + >>> addPostList + >>> arr (setField "title" ("Posts tagged ‘" ++ tag ++ "’")) + >>> applyTemplateCompiler "templates/posts.html" + >>> applyTemplateCompiler "templates/default.html" -myFeedConfiguration = FeedConfiguration - { feedUrl = "rss.xml" - , feedTitle = "SimpleBlog RSS feed." +feedConfiguration :: FeedConfiguration +feedConfiguration = FeedConfiguration + { feedTitle = "SimpleBlog RSS feed." , feedDescription = "A simple demo of an RSS feed created with Hakyll." , feedAuthorName = "Jasper Van der Jeugt" + , feedRoot = "http://example.com" } diff --git a/examples/tagblog/posts.html b/examples/tagblog/posts.html deleted file mode 100644 index ee2ed78..0000000 --- a/examples/tagblog/posts.html +++ /dev/null @@ -1,4 +0,0 @@ -<h1>$title</h1> -<ul> - $body -</ul> diff --git a/examples/tagblog/posts/2009-11-05-a-first-post.markdown b/examples/tagblog/posts/2009-11-05-a-first-post.markdown index c010832..13d39f6 100644 --- a/examples/tagblog/posts/2009-11-05-a-first-post.markdown +++ b/examples/tagblog/posts/2009-11-05-a-first-post.markdown @@ -2,20 +2,21 @@ title: A first post author: Julius Caesar tags: caesar, random crap +description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. --- -Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus pretium leo -adipiscing lectus iaculis lobortis. Vivamus scelerisque velit dignissim metus -gravida sit amet dapibus ligula tempor. Quisque sit amet viverra nunc. -Suspendisse cursus elementum ante, ut venenatis nisi dictum eu. Nulla diam -ligula, eleifend in varius quis, malesuada a nibh. Vivamus consequat -pellentesque erat non blandit. Nunc sit amet eros vel massa semper ullamcorper -quis iaculis magna. Vestibulum ullamcorper urna sit amet est elementum -pulvinar. Vestibulum consequat lacus ac quam hendrerit tincidunt. Praesent -bibendum vehicula diam, nec sagittis risus tempus a. Nulla quis odio sit amet -odio vehicula cursus ut id odio. Curabitur semper magna euismod magna mollis -venenatis. Nunc eget eleifend velit. Mauris sed posuere sem. Fusce id nunc -nisi, a aliquam orci. Suspendisse laoreet justo non enim laoreet eget consequat -velit porttitor. Aenean faucibus sodales metus at tincidunt. Donec vestibulum -leo pulvinar erat auctor ac ultrices massa euismod. Phasellus blandit cursus -magna, eget lacinia mi lobortis sed. Suspendisse ultricies enim ligula, vel +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus pretium leo +adipiscing lectus iaculis lobortis. Vivamus scelerisque velit dignissim metus +gravida sit amet dapibus ligula tempor. Quisque sit amet viverra nunc. +Suspendisse cursus elementum ante, ut venenatis nisi dictum eu. Nulla diam +ligula, eleifend in varius quis, malesuada a nibh. Vivamus consequat +pellentesque erat non blandit. Nunc sit amet eros vel massa semper ullamcorper +quis iaculis magna. Vestibulum ullamcorper urna sit amet est elementum +pulvinar. Vestibulum consequat lacus ac quam hendrerit tincidunt. Praesent +bibendum vehicula diam, nec sagittis risus tempus a. Nulla quis odio sit amet +odio vehicula cursus ut id odio. Curabitur semper magna euismod magna mollis +venenatis. Nunc eget eleifend velit. Mauris sed posuere sem. Fusce id nunc +nisi, a aliquam orci. Suspendisse laoreet justo non enim laoreet eget consequat +velit porttitor. Aenean faucibus sodales metus at tincidunt. Donec vestibulum +leo pulvinar erat auctor ac ultrices massa euismod. Phasellus blandit cursus +magna, eget lacinia mi lobortis sed. Suspendisse ultricies enim ligula, vel scelerisque mauris. diff --git a/examples/tagblog/posts/2009-11-10-another-post.markdown b/examples/tagblog/posts/2009-11-10-another-post.markdown index a79ca88..4f0b62b 100644 --- a/examples/tagblog/posts/2009-11-10-another-post.markdown +++ b/examples/tagblog/posts/2009-11-10-another-post.markdown @@ -2,14 +2,15 @@ title: Another post author: Marcus Tullius Cicero tags: cicero, random crap +description: Vestibulum in ultrices urna. --- -Vestibulum in ultrices urna. Etiam tempor enim dui, nec malesuada elit. Donec -tempor ligula et quam volutpat quis fermentum eros congue. Sed ut pulvinar sem. -Sed aliquam ipsum id purus sollicitudin vulputate. Cras et mauris dui, vel -hendrerit leo. Ut metus ipsum, fermentum ac malesuada id, tempus pharetra quam. -Donec diam felis, consequat ac scelerisque cursus, gravida non lectus. Sed -faucibus elit dapibus diam elementum id varius nisi tristique. Proin consequat -faucibus neque in aliquam. Vestibulum ligula odio, pulvinar vel hendrerit -vitae, egestas ut nibh. Praesent ut velit elit, in consequat dolor. Praesent -sem enim, commodo in gravida sed, adipiscing vel eros. Lorem ipsum dolor sit +Vestibulum in ultrices urna. Etiam tempor enim dui, nec malesuada elit. Donec +tempor ligula et quam volutpat quis fermentum eros congue. Sed ut pulvinar sem. +Sed aliquam ipsum id purus sollicitudin vulputate. Cras et mauris dui, vel +hendrerit leo. Ut metus ipsum, fermentum ac malesuada id, tempus pharetra quam. +Donec diam felis, consequat ac scelerisque cursus, gravida non lectus. Sed +faucibus elit dapibus diam elementum id varius nisi tristique. Proin consequat +faucibus neque in aliquam. Vestibulum ligula odio, pulvinar vel hendrerit +vitae, egestas ut nibh. Praesent ut velit elit, in consequat dolor. Praesent +sem enim, commodo in gravida sed, adipiscing vel eros. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin non aliquam nunc. diff --git a/examples/tagblog/posts/2009-11-28-a-third-post.markdown b/examples/tagblog/posts/2009-11-28-a-third-post.markdown index a3e99aa..f696620 100644 --- a/examples/tagblog/posts/2009-11-28-a-third-post.markdown +++ b/examples/tagblog/posts/2009-11-28-a-third-post.markdown @@ -2,18 +2,19 @@ title: A third post author: Publius Ovidius Naso tags: epic fail, ovidius +description: Pellentesque tempor blandit elit, vel ultricies arcu congue egestas. --- -Pellentesque tempor blandit elit, vel ultricies arcu congue egestas. Fusce -vitae rutrum nisl. Fusce id mauris libero, a venenatis tellus. Fusce iaculis, -lorem et ornare molestie, mauris risus mollis nisi, non fermentum lacus lacus -sit amet ipsum. Praesent lobortis ullamcorper dolor, eget convallis ligula -dignissim a. Suspendisse nulla nisi, congue et pharetra vel, convallis non -libero. Ut a nulla ipsum. Phasellus cursus velit id neque viverra ut -pellentesque justo posuere. Curabitur laoreet enim et velit tempor consectetur. -Donec eu pretium urna. Suspendisse vitae nisi at metus vestibulum aliquam in -sit amet nisl. Donec convallis lacinia odio, vestibulum molestie nunc feugiat -a. Suspendisse vehicula, sapien id aliquet consectetur, sem sapien ullamcorper -arcu, scelerisque porttitor elit ipsum posuere ligula. Nulla at velit eu metus -tincidunt auctor ut sit amet enim. Donec placerat dapibus nisi id facilisis. -Maecenas pellentesque pulvinar auctor. Curabitur gravida quam sit amet purus +Pellentesque tempor blandit elit, vel ultricies arcu congue egestas. Fusce +vitae rutrum nisl. Fusce id mauris libero, a venenatis tellus. Fusce iaculis, +lorem et ornare molestie, mauris risus mollis nisi, non fermentum lacus lacus +sit amet ipsum. Praesent lobortis ullamcorper dolor, eget convallis ligula +dignissim a. Suspendisse nulla nisi, congue et pharetra vel, convallis non +libero. Ut a nulla ipsum. Phasellus cursus velit id neque viverra ut +pellentesque justo posuere. Curabitur laoreet enim et velit tempor consectetur. +Donec eu pretium urna. Suspendisse vitae nisi at metus vestibulum aliquam in +sit amet nisl. Donec convallis lacinia odio, vestibulum molestie nunc feugiat +a. Suspendisse vehicula, sapien id aliquet consectetur, sem sapien ullamcorper +arcu, scelerisque porttitor elit ipsum posuere ligula. Nulla at velit eu metus +tincidunt auctor ut sit amet enim. Donec placerat dapibus nisi id facilisis. +Maecenas pellentesque pulvinar auctor. Curabitur gravida quam sit amet purus consectetur blandit. diff --git a/examples/tagblog/posts/2009-12-04-this-blog-aint-dead.markdown b/examples/tagblog/posts/2009-12-04-this-blog-aint-dead.markdown index bdaa87f..11ec505 100644 --- a/examples/tagblog/posts/2009-12-04-this-blog-aint-dead.markdown +++ b/examples/tagblog/posts/2009-12-04-this-blog-aint-dead.markdown @@ -2,11 +2,12 @@ title: This blog ain't dead author: Marcus Antonius tags: epic fail, antonius +description: Etiam non felis aliquet tellus dictum vestibulum. --- -Etiam non felis aliquet tellus dictum vestibulum. Aliquam accumsan mauris non -lacus ultricies nec lacinia enim rhoncus. Curabitur vel tortor massa, elementum -tincidunt elit. Maecenas venenatis luctus arcu ut ullamcorper. Donec interdum -dolor eu enim tristique vel vehicula risus mollis. Nunc nec tortor quam. Nulla -a mauris arcu. Phasellus venenatis tortor vel odio tincidunt consequat. Integer -venenatis nibh vitae lectus laoreet eu feugiat nunc pretium. Integer nec turpis +Etiam non felis aliquet tellus dictum vestibulum. Aliquam accumsan mauris non +lacus ultricies nec lacinia enim rhoncus. Curabitur vel tortor massa, elementum +tincidunt elit. Maecenas venenatis luctus arcu ut ullamcorper. Donec interdum +dolor eu enim tristique vel vehicula risus mollis. Nunc nec tortor quam. Nulla +a mauris arcu. Phasellus venenatis tortor vel odio tincidunt consequat. Integer +venenatis nibh vitae lectus laoreet eu feugiat nunc pretium. Integer nec turpis metus, in fermentum lorem. diff --git a/examples/tagblog/posts/2009-12-23-almost-christmas.markdown b/examples/tagblog/posts/2009-12-23-almost-christmas.markdown index 2e16426..aa7e473 100644 --- a/examples/tagblog/posts/2009-12-23-almost-christmas.markdown +++ b/examples/tagblog/posts/2009-12-23-almost-christmas.markdown @@ -2,12 +2,13 @@ title: Almost Christmas! author: Publius Vergilius Maro tags: christmas, random crap +description: Morbi tincidunt eleifend ante, eu gravida ante rutrum vel. --- -Morbi tincidunt eleifend ante, eu gravida ante rutrum vel. Nunc bibendum nulla -tellus, eget egestas sapien. Nam rhoncus interdum libero, eget congue orci -imperdiet eu. Quisque pellentesque fringilla urna, ac venenatis ante ultricies -et. Pellentesque habitant morbi tristique senectus et netus et malesuada fames -ac turpis egestas. Mauris eleifend sagittis ultrices. Quisque ultrices accumsan -nisl, sed pellentesque metus porta vitae. Nulla facilisi. In et nibh tincidunt -mi volutpat pellentesque vitae nec sapien. Integer massa ipsum, pellentesque in +Morbi tincidunt eleifend ante, eu gravida ante rutrum vel. Nunc bibendum nulla +tellus, eget egestas sapien. Nam rhoncus interdum libero, eget congue orci +imperdiet eu. Quisque pellentesque fringilla urna, ac venenatis ante ultricies +et. Pellentesque habitant morbi tristique senectus et netus et malesuada fames +ac turpis egestas. Mauris eleifend sagittis ultrices. Quisque ultrices accumsan +nisl, sed pellentesque metus porta vitae. Nulla facilisi. In et nibh tincidunt +mi volutpat pellentesque vitae nec sapien. Integer massa ipsum, pellentesque in elementum at, cursus sit amet diam. diff --git a/examples/tagblog/templates/default.html b/examples/tagblog/templates/default.html index 049a37a..0537065 100644 --- a/examples/tagblog/templates/default.html +++ b/examples/tagblog/templates/default.html @@ -4,20 +4,20 @@ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> - <title>SimpleBlog - $title</title> - <link rel="stylesheet" type="text/css" href="$root/css/default.css" /> + <title>SimpleBlog - $title$</title> + <link rel="stylesheet" type="text/css" href="/css/default.css" /> <link rel="alternate" type="application/rss+xml" title="SimpleBlog" - href="http://example.com/rss.xml" /> + href="/rss.xml" /> </head> <body> - <h1>SimpleBlog - $title</h1> + <h1>SimpleBlog - $title$</h1> <div id="navigation"> - <a href="$root/index.html">Home</a> - <a href="$root/posts.html">All posts</a> + <a href="/">Home</a> + <a href="/posts.html">All posts</a> </div> - $body + $body$ </body> </html> diff --git a/examples/tagblog/index.html b/examples/tagblog/templates/index.html index 4cade0f..7152d02 100644 --- a/examples/tagblog/index.html +++ b/examples/tagblog/templates/index.html @@ -1,11 +1,13 @@ <div id="posts"> <h1>Recent posts</h1> <ul> - $body + $posts$ </ul> - <a href="$root/posts.html">All posts...</a> + <p><a href="/posts.html">All posts…</a></p> + + <h1>Tags</h1> <div> - $tagcloud + $tagcloud$ </div> </div> diff --git a/examples/tagblog/templates/post.html b/examples/tagblog/templates/post.html index 8ecb87d..3c47f1b 100644 --- a/examples/tagblog/templates/post.html +++ b/examples/tagblog/templates/post.html @@ -1,5 +1,5 @@ -<h1>$title</h1> -by <em>$author</em> on <strong>$date</strong> -<div>Tagged as: $tags.</div> +<h1>$title$</h1> +by <em>$author$</em> on <strong>$date$</strong> +<div>Tagged as: $prettytags$.</div> -$body +$body$ diff --git a/examples/tagblog/templates/postitem.html b/examples/tagblog/templates/postitem.html index 0e62418..ccbb58e 100644 --- a/examples/tagblog/templates/postitem.html +++ b/examples/tagblog/templates/postitem.html @@ -1,4 +1,4 @@ <li> - <a href="$root/$url">$title</a> - - <em>$date</em> - by <em>$author</em> + <a href="$url$">$title$</a> + - <em>$date$</em> - by <em>$author$</em> </li> diff --git a/examples/tagblog/templates/posts.html b/examples/tagblog/templates/posts.html new file mode 100644 index 0000000..758c670 --- /dev/null +++ b/examples/tagblog/templates/posts.html @@ -0,0 +1,4 @@ +<h1>$title$</h1> +<ul> + $posts$ +</ul> |