diff options
author | pacien | 2020-01-23 22:36:21 +0100 |
---|---|---|
committer | Notkea | 2020-01-26 21:54:21 +0100 |
commit | 987eb81cb5d98262299c7917d752c54907cbbc33 (patch) | |
tree | 984c73e9a30676f33f05203cb96f57a6a7fda7e9 | |
parent | 8b83c3a77d4bf2ff01b3da789aba7197ff183f30 (diff) | |
download | ldgallery-987eb81cb5d98262299c7917d752c54907cbbc33.tar.gz |
compiler: add directory incl and excl glob settings
GitHub: closes #41
-rw-r--r-- | compiler/src/Compiler.hs | 37 | ||||
-rw-r--r-- | compiler/src/Config.hs | 12 | ||||
-rw-r--r-- | example/gallery.yaml | 7 | ||||
-rw-r--r-- | ldgallery.1.md | 10 |
4 files changed, 41 insertions, 25 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 | ||
74 | galleryDirFilter :: ([Glob.Pattern], [Glob.Pattern]) -> FSNode -> Bool | 74 | galleryDirFilter :: CompilerConfig -> FSNode -> Bool |
75 | galleryDirFilter (inclusionPatterns, exclusionPatterns) = | 75 | galleryDirFilter 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 | ||
100 | compileGallery :: FilePath -> FilePath -> Bool -> IO () | 105 | compileGallery :: 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 | ||
35 | data CompilerConfig = CompilerConfig | 35 | data 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 | |||
44 | instance FromJSON CompilerConfig where | 46 | instance 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" |
diff --git a/example/gallery.yaml b/example/gallery.yaml index ccdb16b..7fb2c92 100644 --- a/example/gallery.yaml +++ b/example/gallery.yaml | |||
@@ -1,10 +1,13 @@ | |||
1 | compiler: | 1 | compiler: |
2 | galleryName: Example gallery | 2 | galleryName: Example gallery |
3 | 3 | ||
4 | includeFiles: | 4 | #includedDirectories: ["*"] |
5 | #excludedDirectories: [] | ||
6 | |||
7 | includedFiles: | ||
5 | - "*.jpg" | 8 | - "*.jpg" |
6 | 9 | ||
7 | #excludeFiles: | 10 | #excludedFiles: |
8 | #- "*.md" | 11 | #- "*.md" |
9 | 12 | ||
10 | tagsFromDirectories: 0 # default | 13 | tagsFromDirectories: 0 # default |
diff --git a/ldgallery.1.md b/ldgallery.1.md index 981dda7..febe2e2 100644 --- a/ldgallery.1.md +++ b/ldgallery.1.md | |||
@@ -93,10 +93,16 @@ The gallery settings reside in a file named "gallery.yaml" located at the root o | |||
93 | compiler.galleryName | 93 | compiler.galleryName |
94 | : Name of the gallery. Defaults to "Gallery". | 94 | : Name of the gallery. Defaults to "Gallery". |
95 | 95 | ||
96 | compiler.includeFiles[] | 96 | compiler.includedDirectories[] |
97 | : Glob patterns of directory names to include in the gallery. Defaults to ["*"] (matches all directory names). | ||
98 | |||
99 | compiler.excludedDirectories[] | ||
100 | : Glob patterns of directory names to exclude from the gallery. Defaults to [] (none). | ||
101 | |||
102 | compiler.includedFiles[] | ||
97 | : Glob patterns of file names to include in the gallery. Defaults to ["*"] (matches all file names). | 103 | : Glob patterns of file names to include in the gallery. Defaults to ["*"] (matches all file names). |
98 | 104 | ||
99 | compiler.excludeFiles[] | 105 | compiler.excludedFiles[] |
100 | : Glob patterns of file names to exclude from the gallery. Defaults to [] (none). | 106 | : Glob patterns of file names to exclude from the gallery. Defaults to [] (none). |
101 | 107 | ||
102 | compiler.tagsFromDirectories | 108 | compiler.tagsFromDirectories |