summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll/Tags.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-11 13:56:32 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-11 13:56:32 +0100
commitdae0258a62a714fb7fd9b47473bf259eb858f9f1 (patch)
treede6c4480cbd87ec9e8689dcdbefeee5618c8a3ef /src/Text/Hakyll/Tags.hs
parent7a765f29a2f5dcf753e5418c96a9c40ddb9112be (diff)
downloadhakyll-dae0258a62a714fb7fd9b47473bf259eb858f9f1.tar.gz
Readability++.
Diffstat (limited to 'src/Text/Hakyll/Tags.hs')
-rw-r--r--src/Text/Hakyll/Tags.hs52
1 files changed, 28 insertions, 24 deletions
diff --git a/src/Text/Hakyll/Tags.hs b/src/Text/Hakyll/Tags.hs
index 801b9b1..625584e 100644
--- a/src/Text/Hakyll/Tags.hs
+++ b/src/Text/Hakyll/Tags.hs
@@ -21,10 +21,11 @@ import Control.Arrow (second)
-- commas.
readTagMap :: [FilePath] -> IO (M.Map String [FilePath])
readTagMap paths = foldM addPaths M.empty paths
- where addPaths current path = do
- page <- readPage path
- let tags = map trim $ splitRegex "," $ getValue ("tags") page
- return $ foldr (\t -> M.insertWith (++) t [path]) current tags
+ where
+ addPaths current path = do
+ page <- readPage path
+ let tags = map trim $ splitRegex "," $ getValue ("tags") page
+ 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'.
@@ -34,28 +35,31 @@ renderTagCloud :: M.Map String [FilePath] -- ^ A tag map as produced by 'readTag
-> String -- ^ Result of the render.
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>"
-
- sizeTag :: Float -> String
- sizeTag count = show size' ++ "%"
- where size' :: Int
- size' = floor (minSize + (relative count) * (maxSize - minSize))
-
- minCount = minimum $ map snd $ tagCount
- maxCount = maximum $ map snd $ tagCount
- relative count = (count - minCount) / (maxCount - minCount)
-
- tagCount :: [(String, Float)]
- tagCount = map (second $ fromIntegral . length) $ M.toList tagMap
+ where
+ renderTag :: (String, Float) -> String
+ renderTag (tag, count) = "<a style=\"font-size: "
+ ++ sizeTag count ++ "\" href=\""
+ ++ urlFunction tag ++ "\">"
+ ++ tag ++ "</a>"
+
+ sizeTag :: Float -> String
+ sizeTag count = show size' ++ "%"
+ where
+ size' :: Int
+ size' = floor (minSize + (relative count) * (maxSize - minSize))
+
+ minCount = minimum $ map snd $ tagCount
+ maxCount = maximum $ map snd $ tagCount
+ relative count = (count - minCount) / (maxCount - minCount)
+
+ tagCount :: [(String, Float)]
+ tagCount = map (second $ fromIntegral . length) $ M.toList tagMap
-- Render all tags to links.
renderTagLinks :: (String -> String) -- ^ Function that produces an url for a tag.
-> ContextManipulation
renderTagLinks urlFunction = renderValue "tags" "tags" renderTagLinks'
- where renderTagLinks' = intercalate ", "
- . map (\t -> link t $ urlFunction t)
- . map trim . splitRegex ","
+ where
+ renderTagLinks' = intercalate ", "
+ . map (\t -> link t $ urlFunction t)
+ . map trim . splitRegex ","