on master help sign in
Added an option for categories instead/in addition to tags. Experimental.
commitf9a4b4f6f4b4e5f9b8c0121a4a45529059dae48a authorJasper Van der Jeugt <jaspervdj@gmail.com> dateWed 27 Jan 2010, 18:52 (17 years ago) parent5928459
4 files changed+15−6
src/Text/Hakyll.hs+1 src/Text/Hakyll/Hakyll.hs+2 src/Text/Hakyll/Internal/Template.hs+4−3 src/Text/Hakyll/Tags.hs+8−3
src/Text/Hakyll.hs+1
@@ -19,6 +19,7 @@ defaultHakyllConfiguration = HakyllConfiguration
1919 { additionalContext = M.empty
2020 , siteDirectory = "_site"
2121 , cacheDirectory = "_cache"
22+ , enableCategories = False
2223 }
2324
2425-- | Hakyll with a default configuration.
src/Text/Hakyll/Hakyll.hs+2
@@ -19,6 +19,8 @@ data HakyllConfiguration = HakyllConfiguration
1919 siteDirectory :: FilePath
2020 , -- | Directory for cache files.
2121 cacheDirectory :: FilePath
22+ -- | Use categories in addition to tags.
23+ , enableCategories :: Bool
2224 }
2325
2426-- | Our custom monad stack.
src/Text/Hakyll/Internal/Template.hs+4−3
@@ -12,6 +12,7 @@ import Data.List (isPrefixOf)
1212import Data.Char (isAlphaNum)
1313import Data.Binary
1414import Control.Monad (liftM, liftM2, replicateM)
15+import Control.Applicative ((<$>))
1516import Data.Maybe (fromMaybe)
1617import System.FilePath ((</>))
1718import Control.Monad.Reader (liftIO)
@@ -95,10 +96,10 @@ instance Binary Template where
9596arbitraryTemplate :: Int -> Gen Template
9697arbitraryTemplate 0 = return End
9798arbitraryTemplate length' = oneof [ do chunk <- chunk'
98− template' >>= return . Chunk chunk
99+ Chunk chunk <$> template'
99100 , do key <- key'
100− template' >>= return . Identifier key
101− , template' >>= return . EscapeCharacter
101+ Identifier key <$> template'
102+ , EscapeCharacter <$> template'
102103 ]
103104 where
104105 template' = arbitraryTemplate (length' - 1)
src/Text/Hakyll/Tags.hs+8−3
@@ -25,9 +25,9 @@ import Data.List (intercalate)
2525import Control.Monad (foldM)
2626import Control.Arrow (second)
2727import Control.Applicative ((<$>))
28−import System.FilePath ((</>))
28+import System.FilePath
2929
30−import Text.Hakyll.Hakyll (Hakyll)
30+import Text.Hakyll.Hakyll
3131import Text.Hakyll.Context (ContextManipulation, changeValue)
3232import Text.Hakyll.Regex
3333import Text.Hakyll.Util
@@ -55,8 +55,13 @@ readTagMap identifier paths = do
5555 readTagMap' = foldM addPaths M.empty paths
5656 addPaths current path = do
5757 page <- readPage path
58+ categoriesEnabled <- askHakyll enableCategories
5859 let tags = map trim $ splitRegex "," $ getValue "tags" page
59− return $ foldr (flip (M.insertWith (++)) [path]) current tags
60+ category = [getCategory path | categoriesEnabled]
61+ addPaths' = flip (M.insertWith (++)) [path]
62+ return $ foldr addPaths' current (category ++ tags)
63+
64+ getCategory = last . splitDirectories . takeDirectory
6065
6166-- | Render a tag cloud.
6267renderTagCloud :: M.Map String [FilePath] -- ^ Map as produced by @readTagMap@.