diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-09-23 11:59:50 +0200 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-09-23 11:59:50 +0200 |
commit | 3631e42f49708a324f0be401c04f4b70685a8f76 (patch) | |
tree | 3e58e0eabf0c19ed66d933e5364740d203d4c252 | |
parent | ae7cc9f324064561c060f03b0a3797b9ed95f521 (diff) | |
download | hakyll-3631e42f49708a324f0be401c04f4b70685a8f76.tar.gz |
Migrate to BlazeHtml for HTML generation
-rw-r--r-- | hakyll.cabal | 3 | ||||
-rw-r--r-- | src/Text/Hakyll/Tags.hs | 22 | ||||
-rw-r--r-- | src/Text/Hakyll/Util.hs | 8 |
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 |