@@ -1,14 +1,17 @@
1-- | Module containing some specialized functions to deal with tags.
1-- | Module containing some specialized functions to deal with tags.
2+-- This Module follows certain conventions. Stick with them.
2module Text.Hakyll.Tags
3module Text.Hakyll.Tags
3 ( readTagMap
4 ( readTagMap
4 , renderTagCloud
5 , renderTagCloud
7import qualified Data.Map as M
9import qualified Data.Map as M
8import qualified Data.ByteString.Lazy.Char8 as B
10import qualified Data.ByteString.Lazy.Char8 as B
9−import qualified Data.List as L
11+import Data.List (intercalate)
10import Control.Monad (foldM)
12import Control.Monad (foldM)
14+import Text.Hakyll.Context (ContextManipulation, renderValue)
12import Text.Hakyll.Util
15import Text.Hakyll.Util
13import Text.Hakyll.Page
16import Text.Hakyll.Page
14import Control.Arrow (second)
17import Control.Arrow (second)
@@ -30,7 +33,7 @@ renderTagCloud :: M.Map String [FilePath] -- ^ A tag map as produced by 'readTag
30 -> Float -- ^ Biggest font size, in percent.
33 -> Float -- ^ Biggest font size, in percent.
31 -> String -- ^ Result of the render.
34 -> String -- ^ Result of the render.
32renderTagCloud tagMap urlFunction minSize maxSize =
35renderTagCloud tagMap urlFunction minSize maxSize =
33− L.intercalate " " $ map renderTag tagCount
36+ intercalate " " $ map renderTag tagCount
34 where renderTag :: (String, Float) -> String
37 where renderTag :: (String, Float) -> String
35 renderTag (tag, count) = "<a style=\"font-size: "
38 renderTag (tag, count) = "<a style=\"font-size: "
36 ++ sizeTag count ++ "\" href=\""
39 ++ sizeTag count ++ "\" href=\""
@@ -49,3 +52,9 @@ renderTagCloud tagMap urlFunction minSize maxSize =
49 tagCount :: [(String, Float)]
52 tagCount :: [(String, Float)]
50 tagCount = map (second $ fromIntegral . length) $ M.toList tagMap
53 tagCount = map (second $ fromIntegral . length) $ M.toList tagMap
55+-- Render all tags to links.
56+renderTagLinks :: (String -> String) -- ^ Function that produces an url for a tag.
57+ -> ContextManipulation
58+renderTagLinks urlFunction = renderValue "tags" "tags" renderTagLinks'
59+ where renderTagLinks' = B.pack . intercalate ", " . map urlFunction
60+ . map trim . split "," . B.unpack