aboutsummaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/package.yaml2
-rw-r--r--compiler/src/Compiler.hs29
-rw-r--r--compiler/src/Config.hs6
3 files changed, 22 insertions, 15 deletions
diff --git a/compiler/package.yaml b/compiler/package.yaml
index 18d8a33..0922c36 100644
--- a/compiler/package.yaml
+++ b/compiler/package.yaml
@@ -26,7 +26,7 @@ dependencies:
26- JuicyPixels 26- JuicyPixels
27- JuicyPixels-extra 27- JuicyPixels-extra
28- parallel-io 28- parallel-io
29- regex-compat 29- Glob
30 30
31default-extensions: 31default-extensions:
32- DuplicateRecordFields 32- DuplicateRecordFields
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
diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs
index 20bc3bb..53333a5 100644
--- a/compiler/src/Config.hs
+++ b/compiler/src/Config.hs
@@ -34,7 +34,8 @@ import Resource (Resolution(..))
34 34
35data CompilerConfig = CompilerConfig 35data CompilerConfig = CompilerConfig
36 { galleryName :: String 36 { galleryName :: String
37 , ignoreFiles :: String 37 , includeFiles :: [String]
38 , excludeFiles :: [String]
38 , tagsFromDirectories :: Int 39 , tagsFromDirectories :: Int
39 , thumbnailMaxResolution :: Resolution 40 , thumbnailMaxResolution :: Resolution
40 , pictureMaxResolution :: Maybe Resolution 41 , pictureMaxResolution :: Maybe Resolution
@@ -43,7 +44,8 @@ data CompilerConfig = CompilerConfig
43instance FromJSON CompilerConfig where 44instance FromJSON CompilerConfig where
44 parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig 45 parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig
45 <$> v .:? "galleryName" .!= "Gallery" 46 <$> v .:? "galleryName" .!= "Gallery"
46 <*> v .:? "ignoreFiles" .!= ".^" 47 <*> v .:? "includeFiles" .!= ["*"]
48 <*> v .:? "excludeFiles" .!= []
47 <*> v .:? "tagsFromDirectories" .!= 0 49 <*> v .:? "tagsFromDirectories" .!= 0
48 <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 400) 50 <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 400)
49 <*> v .:? "pictureMaxResolution" 51 <*> v .:? "pictureMaxResolution"