aboutsummaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorpacien2020-01-23 22:36:21 +0100
committerNotkea2020-01-26 21:54:21 +0100
commit987eb81cb5d98262299c7917d752c54907cbbc33 (patch)
tree984c73e9a30676f33f05203cb96f57a6a7fda7e9 /compiler
parent8b83c3a77d4bf2ff01b3da789aba7197ff183f30 (diff)
downloadldgallery-987eb81cb5d98262299c7917d752c54907cbbc33.tar.gz
compiler: add directory incl and excl glob settings
GitHub: closes #41
Diffstat (limited to 'compiler')
-rw-r--r--compiler/src/Compiler.hs37
-rw-r--r--compiler/src/Config.hs12
2 files changed, 28 insertions, 21 deletions
diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs
index a347433..13e9232 100644
--- a/compiler/src/Compiler.hs
+++ b/compiler/src/Compiler.hs
@@ -71,30 +71,35 @@ writeJSON outputPath object =
71 ensureParentDir JSON.encodeFile outputPath object 71 ensureParentDir JSON.encodeFile outputPath object
72 72
73 73
74galleryDirFilter :: ([Glob.Pattern], [Glob.Pattern]) -> FSNode -> Bool 74galleryDirFilter :: CompilerConfig -> FSNode -> Bool
75galleryDirFilter (inclusionPatterns, exclusionPatterns) = 75galleryDirFilter config =
76 (not . isHidden) 76 (not . isHidden)
77 &&& (matchName True $ anyPattern inclusionPatterns) 77 &&& (not . matchesFile (== galleryConf))
78 &&& (not . isConfigFile)
79 &&& (not . containsOutputGallery) 78 &&& (not . containsOutputGallery)
80 &&& (not . (matchName False $ anyPattern exclusionPatterns)) 79 &&& ((matchesDir $ anyPattern $ includedDirectories config) |||
80 (matchesFile $ anyPattern $ includedFiles config))
81 &&& (not . ((matchesDir $ anyPattern $ excludedDirectories config) |||
82 (matchesFile $ anyPattern $ excludedFiles config)))
81 83
82 where 84 where
83 (&&&) = liftM2 (&&) 85 (&&&) = liftM2 (&&)
84 (|||) = liftM2 (||) 86 (|||) = liftM2 (||)
85 87
86 matchName :: Bool -> (FileName -> Bool) -> FSNode -> Bool 88 matchesDir :: (FileName -> Bool) -> FSNode -> Bool
87 matchName matchDir _ Dir{} = matchDir 89 matchesDir cond dir@Dir{} = maybe False cond $ nodeName dir
88 matchName _ cond file@File{} = maybe False cond $ nodeName file 90 matchesDir _ File{} = False
89 91
90 anyPattern :: [Glob.Pattern] -> FileName -> Bool 92 matchesFile :: (FileName -> Bool) -> FSNode -> Bool
91 anyPattern patterns filename = any (flip Glob.match filename) patterns 93 matchesFile cond file@File{} = maybe False cond $ nodeName file
94 matchesFile _ Dir{} = False
92 95
93 isConfigFile = matchName False (== galleryConf) 96 anyPattern :: [String] -> FileName -> Bool
94 isGalleryIndex = matchName False (== indexFile) 97 anyPattern patterns filename = any (flip Glob.match filename) (map Glob.compile patterns)
95 isViewerIndex = matchName False (== viewerMainFile) 98
99 containsOutputGallery :: FSNode -> Bool
96 containsOutputGallery File{} = False 100 containsOutputGallery File{} = False
97 containsOutputGallery Dir{items} = any (isGalleryIndex ||| isViewerIndex) items 101 containsOutputGallery Dir{items} =
102 any (matchesFile (== indexFile) ||| matchesFile (== viewerMainFile)) items
98 103
99 104
100compileGallery :: FilePath -> FilePath -> Bool -> IO () 105compileGallery :: FilePath -> FilePath -> Bool -> IO ()
@@ -104,9 +109,7 @@ compileGallery inputDirPath outputDirPath rebuildAll =
104 let config = compiler fullConfig 109 let config = compiler fullConfig
105 110
106 inputDir <- readDirectory inputDirPath 111 inputDir <- readDirectory inputDirPath
107 let inclusionPatterns = map Glob.compile $ includeFiles config 112 let sourceFilter = galleryDirFilter config
108 let exclusionPatterns = map Glob.compile $ excludeFiles config
109 let sourceFilter = galleryDirFilter (inclusionPatterns, exclusionPatterns)
110 let sourceTree = filterDir sourceFilter inputDir 113 let sourceTree = filterDir sourceFilter inputDir
111 inputTree <- readInputTree sourceTree 114 inputTree <- readInputTree sourceTree
112 115
diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs
index 53333a5..d670aae 100644
--- a/compiler/src/Config.hs
+++ b/compiler/src/Config.hs
@@ -34,8 +34,10 @@ import Resource (Resolution(..))
34 34
35data CompilerConfig = CompilerConfig 35data CompilerConfig = CompilerConfig
36 { galleryName :: String 36 { galleryName :: String
37 , includeFiles :: [String] 37 , includedDirectories :: [String]
38 , excludeFiles :: [String] 38 , excludedDirectories :: [String]
39 , includedFiles :: [String]
40 , excludedFiles :: [String]
39 , tagsFromDirectories :: Int 41 , tagsFromDirectories :: Int
40 , thumbnailMaxResolution :: Resolution 42 , thumbnailMaxResolution :: Resolution
41 , pictureMaxResolution :: Maybe Resolution 43 , pictureMaxResolution :: Maybe Resolution
@@ -44,8 +46,10 @@ data CompilerConfig = CompilerConfig
44instance FromJSON CompilerConfig where 46instance FromJSON CompilerConfig where
45 parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig 47 parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig
46 <$> v .:? "galleryName" .!= "Gallery" 48 <$> v .:? "galleryName" .!= "Gallery"
47 <*> v .:? "includeFiles" .!= ["*"] 49 <*> v .:? "includedDirectories" .!= ["*"]
48 <*> v .:? "excludeFiles" .!= [] 50 <*> v .:? "excludedDirectories" .!= []
51 <*> v .:? "includedFiles" .!= ["*"]
52 <*> v .:? "excludedFiles" .!= []
49 <*> v .:? "tagsFromDirectories" .!= 0 53 <*> v .:? "tagsFromDirectories" .!= 0
50 <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 400) 54 <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 400)
51 <*> v .:? "pictureMaxResolution" 55 <*> v .:? "pictureMaxResolution"