@@ -1,5 +1,19 @@
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.
2-- This Module follows certain conventions. Stick with them.
4+-- More concrete: all functions in this module assume that the tags are
5+-- located in the @tags@ field, and separated by commas. An example file
6+-- @foo.markdown@ could look like:
9+-- > author: Philip K. Dick
10+-- > title: Do androids dream of electric sheep?
11+-- > tags: future, science fiction, humanoid
13+-- > The novel is set in a post-apocalyptic near future, where the Earth and
14+-- > its populations have been damaged greatly by Nuclear...
16+-- All the following functions would work with such a format.
3module Text.Hakyll.Tags
17module Text.Hakyll.Tags
4 ( readTagMap
18 ( readTagMap
5 , renderTagCloud
19 , renderTagCloud
@@ -12,15 +26,13 @@ import Control.Monad (foldM)
12import Control.Arrow (second)
26import Control.Arrow (second)
14import Text.Hakyll.Hakyll (Hakyll)
28import Text.Hakyll.Hakyll (Hakyll)
15−import Text.Hakyll.Context (ContextManipulation, renderValue)
29+import Text.Hakyll.Context (ContextManipulation, changeValue)
16import Text.Hakyll.Render.Internal (finalSubstitute)
30import Text.Hakyll.Render.Internal (finalSubstitute)
17import Text.Hakyll.Regex
31import Text.Hakyll.Regex
18import Text.Hakyll.Util
32import Text.Hakyll.Util
19import Text.Hakyll.Page
33import Text.Hakyll.Page
21−-- | Read a tag map. This creates a map from tags to page paths. This function
35+-- | Read a tag map. This creates a map from tags to page paths.
22−-- assumes the tags are located in the @tags@ metadata field, separated by
24readTagMap :: [FilePath] -> Hakyll (M.Map String [FilePath])
36readTagMap :: [FilePath] -> Hakyll (M.Map String [FilePath])
25readTagMap paths = foldM addPaths M.empty paths
37readTagMap paths = foldM addPaths M.empty paths
@@ -59,10 +71,19 @@ renderTagCloud tagMap urlFunction minSize maxSize =
59 tagCount :: [(String, Float)]
71 tagCount :: [(String, Float)]
60 tagCount = map (second $ fromIntegral . length) $ M.toList tagMap
72 tagCount = map (second $ fromIntegral . length) $ M.toList tagMap
62−-- Render all tags to links.
74+-- | Render all tags to links.
76+-- On your side, it is nice if you can display the tags on a page, but
77+-- naturally, most people would expect these are clickable.
79+-- So, this function takes a function to produce an url for a given tag, and
80+-- applies it on all tags.
82+-- Note that it is your own responsibility to ensure a page which such an url
63−renderTagLinks :: (String -> String) -- ^ Function that produces an url for a tag.
84+renderTagLinks :: (String -> String) -- ^ Function to produce an url for a tag.
64 -> ContextManipulation
85 -> ContextManipulation
65−renderTagLinks urlFunction = renderValue "tags" "tags" renderTagLinks'
86+renderTagLinks urlFunction = changeValue "tags" renderTagLinks'
67 renderTagLinks' = intercalate ", "
88 renderTagLinks' = intercalate ", "
68 . map ((\t -> link t $ urlFunction t) . trim)
89 . map ((\t -> link t $ urlFunction t) . trim)