on master help sign in
Migrate to BlazeHtml for HTML generation
3631e42Jasper Van der Jeugt
hakyll.cabal+2−1
@@ -40,7 +40,8 @@ library
40 old-time == 1.*,
40 old-time == 1.*,
41 time >= 1.1,
41 time >= 1.1,
42 binary >= 0.5,
42 binary >= 0.5,
43− hamlet >= 0.4.2
43+ hamlet >= 0.4.2,
44+ blaze-html >= 0.2 && <= 0.3
44 exposed-modules: Network.Hakyll.SimpleServer
45 exposed-modules: Network.Hakyll.SimpleServer
45 Text.Hakyll
46 Text.Hakyll
46 Text.Hakyll.Context
47 Text.Hakyll.Context
src/Text/Hakyll/Tags.hs+12−10
@@ -27,6 +27,7 @@
27-- @readTagMap@ or @readCategoryMap@ function, you also have to give a unique
27-- @readTagMap@ or @readCategoryMap@ function, you also have to give a unique
28-- identifier to it. This identifier is simply for caching reasons, so Hakyll
28-- identifier to it. This identifier is simply for caching reasons, so Hakyll
29-- can tell different maps apart; it has no other use.
29-- can tell different maps apart; it has no other use.
30+--
30module Text.Hakyll.Tags
31module Text.Hakyll.Tags
31 ( TagMap
32 ( TagMap
32 , readTagMap
33 , readTagMap
@@ -40,9 +41,15 @@ import qualified Data.Map as M
40import Data.List (intercalate)
41import Data.List (intercalate)
41import Data.Maybe (fromMaybe, maybeToList)
42import Data.Maybe (fromMaybe, maybeToList)
42import Control.Arrow (second, (>>>))
43import Control.Arrow (second, (>>>))
44+import Data.Monoid (mappend)
43import Control.Applicative ((<$>))
45import Control.Applicative ((<$>))
44import System.FilePath
46import System.FilePath
45
47
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+
46import Text.Hakyll.Context (Context (..))
53import Text.Hakyll.Context (Context (..))
47import Text.Hakyll.ContextManipulations (changeValue)
54import Text.Hakyll.ContextManipulations (changeValue)
48import Text.Hakyll.CreateContext (createPage)
55import Text.Hakyll.CreateContext (createPage)
@@ -130,16 +137,11 @@ renderTagCloud urlFunction minSize maxSize = createHakyllAction renderTagCloud'
130 renderTagCloud' tagMap =
137 renderTagCloud' tagMap =
131 return $ intercalate " " $ map (renderTag tagMap) (tagCount tagMap)
138 return $ intercalate " " $ map (renderTag tagMap) (tagCount tagMap)
132
139
133− renderTag tagMap (tag, count) =
140+ renderTag tagMap (tag, count) = renderHtml $
134− finalSubstitute linkTemplate $ Context $ M.fromList
141+ H.a ! A.style (stringValue $ "font-size: " ++ sizeTag tagMap count)
135− [ ("size", sizeTag tagMap count)
142+ ! A.href (stringValue $ urlFunction tag)
136− , ("url", urlFunction tag)
143+ $ string tag
137− , ("tag", tag)
144+
138− ]
139−
140− linkTemplate =
141− fromString "<a style=\"font-size: $size\" href=\"$url\">$tag</a>"
142−
143 sizeTag tagMap count = show (size' :: Int) ++ "%"
145 sizeTag tagMap count = show (size' :: Int) ++ "%"
144 where
146 where
145 size' = floor $ minSize + relative tagMap count * (maxSize - minSize)
147 size' = floor $ minSize + relative tagMap count * (maxSize - minSize)
src/Text/Hakyll/Util.hs+6−2
@@ -7,6 +7,10 @@ module Text.Hakyll.Util
7
7
8import Data.Char (isSpace)
8import Data.Char (isSpace)
9
9
10+import Text.Blaze.Html5 ((!), string, stringValue, a)
11+import Text.Blaze.Html5.Attributes (href)
12+import Text.Blaze.Renderer.String (renderHtml)
13+
10-- | Trim a string (drop spaces, tabs and newlines at both sides).
14-- | Trim a string (drop spaces, tabs and newlines at both sides).
11trim :: String -> String
15trim :: String -> String
12trim = reverse . trim' . reverse . trim'
16trim = reverse . trim' . reverse . trim'
@@ -30,5 +34,5 @@ stripHtml str = let (beforeTag, rest) = break (== '<') str
30link :: String -- ^ Link text.
34link :: String -- ^ Link text.
31 -> String -- ^ Link destination.
35 -> String -- ^ Link destination.
32 -> String
36 -> String
33−link text destination = "<a href=\"" ++ destination ++ "\">"
37+link text destination = renderHtml $ a ! href (stringValue destination)
34− ++ text ++ "</a>"
38+ $ string text