on master help sign in
Small fixes
commitbc192a127b8c57ccb45ff6c773f5917fdbf7ec85 authorJasper Van der Jeugt <m@jaspervdj.be> dateSat 24 Nov 2012, 10:24 (14 years ago) parentc54c7a0
4 files changed+14−13
hakyll.cabal+1−1 src/Hakyll/Core/Identifier/Pattern.hs+5−3 src/Hakyll/Web/Tags.hs+7−7 src/Hakyll/Web/Template/Context.hs+1−2
hakyll.cabal+1−1
@@ -120,7 +120,7 @@ Library
120120 Hakyll.Web.Pandoc
121121 Hakyll.Web.Pandoc.Biblio
122122 Hakyll.Web.Pandoc.FileType
123− -- Hakyll.Web.Tags
123+ Hakyll.Web.Tags
124124 Hakyll.Web.Template
125125 Hakyll.Web.Template.Context
126126 Hakyll.Web.Template.List
src/Hakyll/Core/Identifier/Pattern.hs+5−3
@@ -68,6 +68,8 @@ import Data.Binary (Binary (..), getWord8, putWord8)
6868import Data.List (inits, isPrefixOf, tails)
6969import Data.Maybe (isJust)
7070import Data.Monoid (Monoid, mappend, mempty)
71+import Data.Set (Set)
72+import qualified Data.Set as S
7173
7274
7375--------------------------------------------------------------------------------
@@ -108,7 +110,7 @@ data Pattern
108110 | Complement Pattern
109111 | And Pattern Pattern
110112 | Glob [GlobComponent]
111− | List [Identifier] -- TODO Maybe use a set here
113+ | List (Set Identifier)
112114 | Regex String
113115 | Version (Maybe String)
114116 deriving (Show)
@@ -162,7 +164,7 @@ fromGlob = Glob . parse'
162164--------------------------------------------------------------------------------
163165-- | Create a 'Pattern' from a list of 'Identifier's it should match
164166fromList :: [Identifier] -> Pattern
165−fromList = List
167+fromList = List . S.fromList
166168
167169
168170--------------------------------------------------------------------------------
@@ -205,7 +207,7 @@ matches Everything _ = True
205207matches (Complement p) i = not $ matches p i
206208matches (And x y) i = matches x i && matches y i
207209matches (Glob p) i = isJust $ capture (Glob p) i
208−matches (List l) i = i `elem` l
210+matches (List l) i = i `S.member` l
209211matches (Regex r) i = toFilePath i =~ r
210212matches (Version v) i = identifierVersion i == v
211213
src/Hakyll/Web/Tags.hs+7−7
@@ -66,6 +66,7 @@ import qualified Text.Blaze.Html5.Attributes as A
6666--------------------------------------------------------------------------------
6767import Hakyll.Core.Compiler
6868import Hakyll.Core.Identifier
69+import Hakyll.Core.Identifier.Pattern
6970import Hakyll.Core.Item
7071import Hakyll.Core.Metadata
7172import Hakyll.Core.Util.String
@@ -102,10 +103,11 @@ getCategory = return . return . takeBaseName . takeDirectory . toFilePath
102103
103104
104105--------------------------------------------------------------------------------
105−-- | Higher-level function to read tags
106+-- | Higher-order function to read tags
106107buildTagsWith :: MonadMetadata m
107− => (Identifier -> m [String]) -> [Identifier] -> m Tags
108−buildTagsWith f ids = do
108+ => (Identifier -> m [String]) -> Pattern -> m Tags
109+buildTagsWith f pattern = do
110+ ids <- getMatches pattern
109111 tagMap <- foldM addTags M.empty ids
110112 return $ Tags $ M.toList tagMap
111113 where
@@ -117,15 +119,13 @@ buildTagsWith f ids = do
117119
118120--------------------------------------------------------------------------------
119121-- | Read a tagmap using the @tags@ metadata field
120−-- TODO: Should use pattern
121−buildTags :: MonadMetadata m => [Identifier] -> m Tags
122+buildTags :: MonadMetadata m => Pattern -> m Tags
122123buildTags = buildTagsWith getTags
123124
124125
125126--------------------------------------------------------------------------------
126127-- | Read a tagmap using the @category@ metadata field
127−-- TODO: Should use pattern
128−buildCategory :: MonadMetadata m => [Identifier] -> m Tags
128+buildCategory :: MonadMetadata m => Pattern -> m Tags
129129buildCategory = buildTagsWith getCategory
130130
131131
src/Hakyll/Web/Template/Context.hs+1−2
@@ -28,8 +28,7 @@ import qualified Data.Map as M
2828import Data.Monoid (Monoid (..))
2929import Data.Time.Clock (UTCTime (..))
3030import Data.Time.Format (formatTime, parseTime)
31−import System.FilePath (takeBaseName, takeDirectory,
32− takeFileName)
31+import System.FilePath (takeBaseName, takeFileName)
3332import System.Locale (TimeLocale, defaultTimeLocale)
3433
3534