on master help sign in
Added an option for categories instead/in addition to tags. Experimental.
f9a4b4fJasper Van der Jeugt
src/Text/Hakyll.hs+1
@@ -19,6 +19,7 @@ defaultHakyllConfiguration = HakyllConfiguration
19 { additionalContext = M.empty
19 { additionalContext = M.empty
20 , siteDirectory = "_site"
20 , siteDirectory = "_site"
21 , cacheDirectory = "_cache"
21 , cacheDirectory = "_cache"
22+ , enableCategories = False
22 }
23 }
23
24
24-- | Hakyll with a default configuration.
25-- | Hakyll with a default configuration.
src/Text/Hakyll/Hakyll.hs+2
@@ -19,6 +19,8 @@ data HakyllConfiguration = HakyllConfiguration
19 siteDirectory :: FilePath
19 siteDirectory :: FilePath
20 , -- | Directory for cache files.
20 , -- | Directory for cache files.
21 cacheDirectory :: FilePath
21 cacheDirectory :: FilePath
22+ -- | Use categories in addition to tags.
23+ , enableCategories :: Bool
22 }
24 }
23
25
24-- | Our custom monad stack.
26-- | Our custom monad stack.
src/Text/Hakyll/Internal/Template.hs+4−3
@@ -12,6 +12,7 @@ import Data.List (isPrefixOf)
12import Data.Char (isAlphaNum)
12import Data.Char (isAlphaNum)
13import Data.Binary
13import Data.Binary
14import Control.Monad (liftM, liftM2, replicateM)
14import Control.Monad (liftM, liftM2, replicateM)
15+import Control.Applicative ((<$>))
15import Data.Maybe (fromMaybe)
16import Data.Maybe (fromMaybe)
16import System.FilePath ((</>))
17import System.FilePath ((</>))
17import Control.Monad.Reader (liftIO)
18import Control.Monad.Reader (liftIO)
@@ -95,10 +96,10 @@ instance Binary Template where
95arbitraryTemplate :: Int -> Gen Template
96arbitraryTemplate :: Int -> Gen Template
96arbitraryTemplate 0 = return End
97arbitraryTemplate 0 = return End
97arbitraryTemplate length' = oneof [ do chunk <- chunk'
98arbitraryTemplate length' = oneof [ do chunk <- chunk'
98− template' >>= return . Chunk chunk
99+ Chunk chunk <$> template'
99 , do key <- key'
100 , do key <- key'
100− template' >>= return . Identifier key
101+ Identifier key <$> template'
101− , template' >>= return . EscapeCharacter
102+ , EscapeCharacter <$> template'
102 ]
103 ]
103 where
104 where
104 template' = arbitraryTemplate (length' - 1)
105 template' = arbitraryTemplate (length' - 1)
src/Text/Hakyll/Tags.hs+8−3
@@ -25,9 +25,9 @@ import Data.List (intercalate)
25import Control.Monad (foldM)
25import Control.Monad (foldM)
26import Control.Arrow (second)
26import Control.Arrow (second)
27import Control.Applicative ((<$>))
27import Control.Applicative ((<$>))
28−import System.FilePath ((</>))
28+import System.FilePath
29
29
30−import Text.Hakyll.Hakyll (Hakyll)
30+import Text.Hakyll.Hakyll
31import Text.Hakyll.Context (ContextManipulation, changeValue)
31import Text.Hakyll.Context (ContextManipulation, changeValue)
32import Text.Hakyll.Regex
32import Text.Hakyll.Regex
33import Text.Hakyll.Util
33import Text.Hakyll.Util
@@ -55,8 +55,13 @@ readTagMap identifier paths = do
55 readTagMap' = foldM addPaths M.empty paths
55 readTagMap' = foldM addPaths M.empty paths
56 addPaths current path = do
56 addPaths current path = do
57 page <- readPage path
57 page <- readPage path
58+ categoriesEnabled <- askHakyll enableCategories
58 let tags = map trim $ splitRegex "," $ getValue "tags" page
59 let tags = map trim $ splitRegex "," $ getValue "tags" page
60+ category = [getCategory path | categoriesEnabled]
61+ addPaths' = flip (M.insertWith (++)) [path]
59− return $ foldr (flip (M.insertWith (++)) [path]) current tags
62+ return $ foldr addPaths' current (category ++ tags)
63+
64+ getCategory = last . splitDirectories . takeDirectory
60
65
61-- | Render a tag cloud.
66-- | Render a tag cloud.
62renderTagCloud :: M.Map String [FilePath] -- ^ Map as produced by @readTagMap@.
67renderTagCloud :: M.Map String [FilePath] -- ^ Map as produced by @readTagMap@.