aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Compiler.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src/Compiler.hs')
-rw-r--r--compiler/src/Compiler.hs29
1 files changed, 17 insertions, 12 deletions
diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs
index fc4e272..b84dedf 100644
--- a/compiler/src/Compiler.hs
+++ b/compiler/src/Compiler.hs
@@ -23,9 +23,8 @@ module Compiler
23 23
24import Control.Monad (liftM2) 24import Control.Monad (liftM2)
25import Data.List (any) 25import Data.List (any)
26import Data.Maybe (isJust, fromMaybe)
27import Text.Regex (Regex, mkRegex, matchRegex)
28import System.FilePath ((</>)) 26import System.FilePath ((</>))
27import qualified System.FilePath.Glob as Glob
29 28
30import Data.Aeson (ToJSON) 29import Data.Aeson (ToJSON)
31import qualified Data.Aeson as JSON 30import qualified Data.Aeson as JSON
@@ -73,26 +72,30 @@ writeJSON outputPath object =
73 ensureParentDir JSON.encodeFile outputPath object 72 ensureParentDir JSON.encodeFile outputPath object
74 73
75 74
76galleryDirFilter :: Regex -> FSNode -> Bool 75galleryDirFilter :: ([Glob.Pattern], [Glob.Pattern]) -> FSNode -> Bool
77galleryDirFilter excludeRegex = 76galleryDirFilter (inclusionPatterns, exclusionPatterns) =
78 (not . isHidden) 77 (not . isHidden)
78 &&& (matchName True $ anyPattern inclusionPatterns)
79 &&& (not . isConfigFile) 79 &&& (not . isConfigFile)
80 &&& (not . containsOutputGallery) 80 &&& (not . containsOutputGallery)
81 &&& (not . excludedName) 81 &&& (not . (matchName False $ anyPattern exclusionPatterns))
82 82
83 where 83 where
84 (&&&) = liftM2 (&&) 84 (&&&) = liftM2 (&&)
85 (|||) = liftM2 (||) 85 (|||) = liftM2 (||)
86 86
87 matchName :: (FileName -> Bool) -> FSNode -> Bool 87 matchName :: Bool -> (FileName -> Bool) -> FSNode -> Bool
88 matchName cond = maybe False cond . nodeName 88 matchName matchDir _ Dir{} = matchDir
89 matchName _ cond file@File{} = maybe False cond $ nodeName file
89 90
90 isConfigFile = matchName (== galleryConf) 91 anyPattern :: [Glob.Pattern] -> FileName -> Bool
91 isGalleryIndex = matchName (== indexFile) 92 anyPattern patterns filename = any (flip Glob.match filename) patterns
92 isViewerIndex = matchName (== viewerMainFile) 93
94 isConfigFile = matchName False (== galleryConf)
95 isGalleryIndex = matchName False (== indexFile)
96 isViewerIndex = matchName False (== viewerMainFile)
93 containsOutputGallery File{} = False 97 containsOutputGallery File{} = False
94 containsOutputGallery Dir{items} = any (isGalleryIndex ||| isViewerIndex) items 98 containsOutputGallery Dir{items} = any (isGalleryIndex ||| isViewerIndex) items
95 excludedName = isJust . matchRegex excludeRegex . fromMaybe "" . nodeName
96 99
97 100
98compileGallery :: FilePath -> FilePath -> Bool -> IO () 101compileGallery :: FilePath -> FilePath -> Bool -> IO ()
@@ -102,7 +105,9 @@ compileGallery inputDirPath outputDirPath rebuildAll =
102 let config = compiler fullConfig 105 let config = compiler fullConfig
103 106
104 inputDir <- readDirectory inputDirPath 107 inputDir <- readDirectory inputDirPath
105 let sourceFilter = galleryDirFilter (mkRegex $ ignoreFiles config) 108 let inclusionPatterns = map Glob.compile $ includeFiles config
109 let exclusionPatterns = map Glob.compile $ excludeFiles config
110 let sourceFilter = galleryDirFilter (inclusionPatterns, exclusionPatterns)
106 let sourceTree = filterDir sourceFilter inputDir 111 let sourceTree = filterDir sourceFilter inputDir
107 inputTree <- readInputTree sourceTree 112 inputTree <- readInputTree sourceTree
108 113