summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-09-23 11:59:50 +0200
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-09-23 11:59:50 +0200
commit3631e42f49708a324f0be401c04f4b70685a8f76 (patch)
tree3e58e0eabf0c19ed66d933e5364740d203d4c252 /src/Text/Hakyll
parentae7cc9f324064561c060f03b0a3797b9ed95f521 (diff)
downloadhakyll-3631e42f49708a324f0be401c04f4b70685a8f76.tar.gz
Migrate to BlazeHtml for HTML generation
Diffstat (limited to 'src/Text/Hakyll')
-rw-r--r--src/Text/Hakyll/Tags.hs22
-rw-r--r--src/Text/Hakyll/Util.hs8
2 files changed, 18 insertions, 12 deletions
diff --git a/src/Text/Hakyll/Tags.hs b/src/Text/Hakyll/Tags.hs
index 1ca74a5..6e2d956 100644
--- a/src/Text/Hakyll/Tags.hs
+++ b/src/Text/Hakyll/Tags.hs
@@ -27,6 +27,7 @@
-- @readTagMap@ or @readCategoryMap@ function, you also have to give a unique
-- identifier to it. This identifier is simply for caching reasons, so Hakyll
-- can tell different maps apart; it has no other use.
+--
module Text.Hakyll.Tags
( TagMap
, readTagMap
@@ -40,9 +41,15 @@ import qualified Data.Map as M
import Data.List (intercalate)
import Data.Maybe (fromMaybe, maybeToList)
import Control.Arrow (second, (>>>))
+import Data.Monoid (mappend)
import Control.Applicative ((<$>))
import System.FilePath
+import Text.Blaze.Renderer.String (renderHtml)
+import Text.Blaze.Html5 ((!), string, stringValue)
+import qualified Text.Blaze.Html5 as H
+import qualified Text.Blaze.Html5.Attributes as A
+
import Text.Hakyll.Context (Context (..))
import Text.Hakyll.ContextManipulations (changeValue)
import Text.Hakyll.CreateContext (createPage)
@@ -130,16 +137,11 @@ renderTagCloud urlFunction minSize maxSize = createHakyllAction renderTagCloud'
renderTagCloud' tagMap =
return $ intercalate " " $ map (renderTag tagMap) (tagCount tagMap)
- renderTag tagMap (tag, count) =
- finalSubstitute linkTemplate $ Context $ M.fromList
- [ ("size", sizeTag tagMap count)
- , ("url", urlFunction tag)
- , ("tag", tag)
- ]
-
- linkTemplate =
- fromString "<a style=\"font-size: $size\" href=\"$url\">$tag</a>"
-
+ renderTag tagMap (tag, count) = renderHtml $
+ H.a ! A.style (stringValue $ "font-size: " ++ sizeTag tagMap count)
+ ! A.href (stringValue $ urlFunction tag)
+ $ string tag
+
sizeTag tagMap count = show (size' :: Int) ++ "%"
where
size' = floor $ minSize + relative tagMap count * (maxSize - minSize)
diff --git a/src/Text/Hakyll/Util.hs b/src/Text/Hakyll/Util.hs
index d900d6e..84d6257 100644
--- a/src/Text/Hakyll/Util.hs
+++ b/src/Text/Hakyll/Util.hs
@@ -7,6 +7,10 @@ module Text.Hakyll.Util
import Data.Char (isSpace)
+import Text.Blaze.Html5 ((!), string, stringValue, a)
+import Text.Blaze.Html5.Attributes (href)
+import Text.Blaze.Renderer.String (renderHtml)
+
-- | Trim a string (drop spaces, tabs and newlines at both sides).
trim :: String -> String
trim = reverse . trim' . reverse . trim'
@@ -30,5 +34,5 @@ stripHtml str = let (beforeTag, rest) = break (== '<') str
link :: String -- ^ Link text.
-> String -- ^ Link destination.
-> String
-link text destination = "<a href=\"" ++ destination ++ "\">"
- ++ text ++ "</a>"
+link text destination = renderHtml $ a ! href (stringValue destination)
+ $ string text