summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-17 12:14:54 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-17 12:14:54 +0100
commit003734442486876153911d339f07d4379e8dca20 (patch)
tree6ec2fde774586175efefac0198e142d6312e618e
parent6bacab4f22213df62d6162296a209173701171b8 (diff)
downloadhakyll-003734442486876153911d339f07d4379e8dca20.tar.gz
Use Text.Hakyll.Render.Internal to render tag cloud.
-rw-r--r--src/Text/Hakyll/Tags.hs15
1 files changed, 9 insertions, 6 deletions
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) = "<a style=\"font-size: "
- ++ sizeTag count ++ "\" href=\""
- ++ urlFunction tag ++ "\">"
- ++ tag ++ "</a>"
+ renderTag (tag, count) =
+ finalSubstitute "<a style=\"font-size: $size\" href=\"$url\">$tag</a>" $
+ M.fromList [ ("size", sizeTag count)
+ , ("url", urlFunction tag)
+ , ("tag", tag)
+ ]
sizeTag :: Float -> String
sizeTag count = show size' ++ "%"