summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hakyll.cabal3
-rw-r--r--src/Text/Hakyll/Tags.hs22
-rw-r--r--src/Text/Hakyll/Util.hs8
3 files changed, 20 insertions, 13 deletions
diff --git a/hakyll.cabal b/hakyll.cabal
index a77a184..51c3fa4 100644
--- a/hakyll.cabal
+++ b/hakyll.cabal
@@ -40,7 +40,8 @@ library
old-time == 1.*,
time >= 1.1,
binary >= 0.5,
- hamlet >= 0.4.2
+ hamlet >= 0.4.2,
+ blaze-html >= 0.2 && <= 0.3
exposed-modules: Network.Hakyll.SimpleServer
Text.Hakyll
Text.Hakyll.Context
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