on master help sign in
Migrate to BlazeHtml for HTML generation
commit3631e42f49708a324f0be401c04f4b70685a8f76 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateThu 23 Sep 2010, 11:59 (16 years ago) parentae7cc9f
3 files changed+20−13
hakyll.cabal+2−1 src/Text/Hakyll/Tags.hs+12−10 src/Text/Hakyll/Util.hs+6−2
hakyll.cabal+2−1
@@ -40,7 +40,8 @@ library
4040 old-time == 1.*,
4141 time >= 1.1,
4242 binary >= 0.5,
43− hamlet >= 0.4.2
43+ hamlet >= 0.4.2,
44+ blaze-html >= 0.2 && <= 0.3
4445 exposed-modules: Network.Hakyll.SimpleServer
4546 Text.Hakyll
4647 Text.Hakyll.Context
src/Text/Hakyll/Tags.hs+12−10
@@ -27,6 +27,7 @@
2727-- @readTagMap@ or @readCategoryMap@ function, you also have to give a unique
2828-- identifier to it. This identifier is simply for caching reasons, so Hakyll
2929-- can tell different maps apart; it has no other use.
30+--
3031module Text.Hakyll.Tags
3132 ( TagMap
3233 , readTagMap
@@ -40,9 +41,15 @@ import qualified Data.Map as M
4041import Data.List (intercalate)
4142import Data.Maybe (fromMaybe, maybeToList)
4243import Control.Arrow (second, (>>>))
44+import Data.Monoid (mappend)
4345import Control.Applicative ((<$>))
4446import System.FilePath
4547
48+import Text.Blaze.Renderer.String (renderHtml)
49+import Text.Blaze.Html5 ((!), string, stringValue)
50+import qualified Text.Blaze.Html5 as H
51+import qualified Text.Blaze.Html5.Attributes as A
52+
4653import Text.Hakyll.Context (Context (..))
4754import Text.Hakyll.ContextManipulations (changeValue)
4855import Text.Hakyll.CreateContext (createPage)
@@ -130,16 +137,11 @@ renderTagCloud urlFunction minSize maxSize = createHakyllAction renderTagCloud'
130137 renderTagCloud' tagMap =
131138 return $ intercalate " " $ map (renderTag tagMap) (tagCount tagMap)
132139
133− renderTag tagMap (tag, count) =
134− finalSubstitute linkTemplate $ Context $ M.fromList
135− [ ("size", sizeTag tagMap count)
136− , ("url", urlFunction tag)
137− , ("tag", tag)
138− ]
139−
140− linkTemplate =
141− fromString "<a style=\"font-size: $size\" href=\"$url\">$tag</a>"
142−
140+ renderTag tagMap (tag, count) = renderHtml $
141+ H.a ! A.style (stringValue $ "font-size: " ++ sizeTag tagMap count)
142+ ! A.href (stringValue $ urlFunction tag)
143+ $ string tag
144+
143145 sizeTag tagMap count = show (size' :: Int) ++ "%"
144146 where
145147 size' = floor $ minSize + relative tagMap count * (maxSize - minSize)
src/Text/Hakyll/Util.hs+6−2
@@ -7,6 +7,10 @@ module Text.Hakyll.Util
77
88import Data.Char (isSpace)
99
10+import Text.Blaze.Html5 ((!), string, stringValue, a)
11+import Text.Blaze.Html5.Attributes (href)
12+import Text.Blaze.Renderer.String (renderHtml)
13+
1014-- | Trim a string (drop spaces, tabs and newlines at both sides).
1115trim :: String -> String
1216trim = reverse . trim' . reverse . trim'
@@ -30,5 +34,5 @@ stripHtml str = let (beforeTag, rest) = break (== '<') str
3034link :: String -- ^ Link text.
3135 -> String -- ^ Link destination.
3236 -> String
33−link text destination = "<a href=\"" ++ destination ++ "\">"
34− ++ text ++ "</a>"
37+link text destination = renderHtml $ a ! href (stringValue destination)
38+ $ string text