on master help sign in
Added renderTagLinks function.
commitb403d35b087683a7a38e57b943c63449613b3115 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateFri 8 Jan 2010, 12:04 (17 years ago) parent547f98d
1 file changed+11−2
src/Text/Hakyll/Tags.hs+11−2
src/Text/Hakyll/Tags.hs+11−2
@@ -1,14 +1,17 @@
11-- | Module containing some specialized functions to deal with tags.
2+-- This Module follows certain conventions. Stick with them.
23module Text.Hakyll.Tags
34 ( readTagMap
45 , renderTagCloud
6+ , renderTagLinks
57 ) where
68
79import qualified Data.Map as M
810import qualified Data.ByteString.Lazy.Char8 as B
9−import qualified Data.List as L
11+import Data.List (intercalate)
1012import Control.Monad (foldM)
1113
14+import Text.Hakyll.Context (ContextManipulation, renderValue)
1215import Text.Hakyll.Util
1316import Text.Hakyll.Page
1417import Control.Arrow (second)
@@ -30,7 +33,7 @@ renderTagCloud :: M.Map String [FilePath] -- ^ A tag map as produced by 'readTag
3033 -> Float -- ^ Biggest font size, in percent.
3134 -> String -- ^ Result of the render.
3235renderTagCloud tagMap urlFunction minSize maxSize =
33− L.intercalate " " $ map renderTag tagCount
36+ intercalate " " $ map renderTag tagCount
3437 where renderTag :: (String, Float) -> String
3538 renderTag (tag, count) = "<a style=\"font-size: "
3639 ++ sizeTag count ++ "\" href=\""
@@ -49,3 +52,9 @@ renderTagCloud tagMap urlFunction minSize maxSize =
4952 tagCount :: [(String, Float)]
5053 tagCount = map (second $ fromIntegral . length) $ M.toList tagMap
5154
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