@@ -1,5 +1,19 @@
11-- | Module containing some specialized functions to deal with tags.
22-- This Module follows certain conventions. Stick with them.
3+--
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:
7+--
8+-- > ---
9+-- > author: Philip K. Dick
10+-- > title: Do androids dream of electric sheep?
11+-- > tags: future, science fiction, humanoid
12+-- > ---
13+-- > The novel is set in a post-apocalyptic near future, where the Earth and
14+-- > its populations have been damaged greatly by Nuclear...
15+--
16+-- All the following functions would work with such a format.
317module Text.Hakyll.Tags
418 ( readTagMap
519 , renderTagCloud
@@ -12,15 +26,13 @@ import Control.Monad (foldM)
1226import Control.Arrow (second)
1327
1428import Text.Hakyll.Hakyll (Hakyll)
15−import Text.Hakyll.Context (ContextManipulation, renderValue)
29+import Text.Hakyll.Context (ContextManipulation, changeValue)
1630import Text.Hakyll.Render.Internal (finalSubstitute)
1731import Text.Hakyll.Regex
1832import Text.Hakyll.Util
1933import Text.Hakyll.Page
2034
21−-- | Read a tag map. This creates a map from tags to page paths. This function
22−-- assumes the tags are located in the @tags@ metadata field, separated by
23−-- commas.
35+-- | Read a tag map. This creates a map from tags to page paths.
2436readTagMap :: [FilePath] -> Hakyll (M.Map String [FilePath])
2537readTagMap paths = foldM addPaths M.empty paths
2638 where
@@ -59,10 +71,19 @@ renderTagCloud tagMap urlFunction minSize maxSize =
5971 tagCount :: [(String, Float)]
6072 tagCount = map (second $ fromIntegral . length) $ M.toList tagMap
6173
62−-- Render all tags to links.
63−renderTagLinks :: (String -> String) -- ^ Function that produces an url for a tag.
74+-- | Render all tags to links.
75+--
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.
78+--
79+-- So, this function takes a function to produce an url for a given tag, and
80+-- applies it on all tags.
81+--
82+-- Note that it is your own responsibility to ensure a page which such an url
83+-- exists.
84+renderTagLinks :: (String -> String) -- ^ Function to produce an url for a tag.
6485 -> ContextManipulation
65−renderTagLinks urlFunction = renderValue "tags" "tags" renderTagLinks'
86+renderTagLinks urlFunction = changeValue "tags" renderTagLinks'
6687 where
6788 renderTagLinks' = intercalate ", "
6889 . map ((\t -> link t $ urlFunction t) . trim)