From 003734442486876153911d339f07d4379e8dca20 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sun, 17 Jan 2010 12:14:54 +0100 Subject: Use Text.Hakyll.Render.Internal to render tag cloud. --- src/Text/Hakyll/Tags.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/Text/Hakyll') diff --git a/src/Text/Hakyll/Tags.hs b/src/Text/Hakyll/Tags.hs index 209d479..667c2ee 100644 --- a/src/Text/Hakyll/Tags.hs +++ b/src/Text/Hakyll/Tags.hs @@ -12,6 +12,7 @@ import Control.Monad (foldM) import Text.Hakyll.Hakyll (Hakyll) import Text.Hakyll.Context (ContextManipulation, renderValue) +import Text.Hakyll.Render.Internal (finalSubstitute) import Text.Hakyll.Regex import Text.Hakyll.Util import Text.Hakyll.Page @@ -29,8 +30,8 @@ readTagMap paths = foldM addPaths M.empty paths return $ foldr (\t -> M.insertWith (++) t [path]) current tags -- | Render a tag cloud. -renderTagCloud :: M.Map String [FilePath] -- ^ A tag map as produced by 'readTagMap'. - -> (String -> String) -- ^ Function that produces an url for a tag. +renderTagCloud :: M.Map String [FilePath] -- ^ Map as produced by 'readTagMap'. + -> (String -> String) -- ^ Function to produce an url for a tag. -> Float -- ^ Smallest font size, in percent. -> Float -- ^ Biggest font size, in percent. -> String -- ^ Result of the render. @@ -38,10 +39,12 @@ renderTagCloud tagMap urlFunction minSize maxSize = intercalate " " $ map renderTag tagCount where renderTag :: (String, Float) -> String - renderTag (tag, count) = "" - ++ tag ++ "" + renderTag (tag, count) = + finalSubstitute "$tag" $ + M.fromList [ ("size", sizeTag count) + , ("url", urlFunction tag) + , ("tag", tag) + ] sizeTag :: Float -> String sizeTag count = show size' ++ "%" -- cgit v1.2.3