diff options
-rw-r--r-- | compiler/package.yaml | 2 | ||||
-rw-r--r-- | compiler/src/Compiler.hs | 29 | ||||
-rw-r--r-- | compiler/src/Config.hs | 6 | ||||
-rw-r--r-- | example/gallery.yaml | 7 | ||||
-rw-r--r-- | ldgallery.1.md | 7 |
5 files changed, 33 insertions, 18 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 | ||
31 | default-extensions: | 31 | default-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 | ||
24 | import Control.Monad (liftM2) | 24 | import Control.Monad (liftM2) |
25 | import Data.List (any) | 25 | import Data.List (any) |
26 | import Data.Maybe (isJust, fromMaybe) | ||
27 | import Text.Regex (Regex, mkRegex, matchRegex) | ||
28 | import System.FilePath ((</>)) | 26 | import System.FilePath ((</>)) |
27 | import qualified System.FilePath.Glob as Glob | ||
29 | 28 | ||
30 | import Data.Aeson (ToJSON) | 29 | import Data.Aeson (ToJSON) |
31 | import qualified Data.Aeson as JSON | 30 | import 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 | ||
76 | galleryDirFilter :: Regex -> FSNode -> Bool | 75 | galleryDirFilter :: ([Glob.Pattern], [Glob.Pattern]) -> FSNode -> Bool |
77 | galleryDirFilter excludeRegex = | 76 | galleryDirFilter (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 | ||
98 | compileGallery :: FilePath -> FilePath -> Bool -> IO () | 101 | compileGallery :: 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 | ||
35 | data CompilerConfig = CompilerConfig | 35 | data 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 | |||
43 | instance FromJSON CompilerConfig where | 44 | instance 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" |
diff --git a/example/gallery.yaml b/example/gallery.yaml index 5da7328..ccdb16b 100644 --- a/example/gallery.yaml +++ b/example/gallery.yaml | |||
@@ -1,6 +1,11 @@ | |||
1 | compiler: | 1 | compiler: |
2 | galleryName: Example gallery | 2 | galleryName: Example gallery |
3 | ignoreFiles: .*\.md | 3 | |
4 | includeFiles: | ||
5 | - "*.jpg" | ||
6 | |||
7 | #excludeFiles: | ||
8 | #- "*.md" | ||
4 | 9 | ||
5 | tagsFromDirectories: 0 # default | 10 | tagsFromDirectories: 0 # default |
6 | 11 | ||
diff --git a/ldgallery.1.md b/ldgallery.1.md index ec685c6..abaeb16 100644 --- a/ldgallery.1.md +++ b/ldgallery.1.md | |||
@@ -90,8 +90,11 @@ The gallery settings reside in a file named "gallery.yaml" located at the root o | |||
90 | compiler.galleryName | 90 | compiler.galleryName |
91 | : Name of the gallery. Defaults to "Gallery". | 91 | : Name of the gallery. Defaults to "Gallery". |
92 | 92 | ||
93 | compiler.ignoreFiles | 93 | compiler.includeFiles[] |
94 | : Regular expression matching the name of files to ignore. | 94 | : Glob patterns of file names to include in the gallery. Defaults to ["*"] (matches all file names). |
95 | |||
96 | compiler.excludeFiles[] | ||
97 | : Glob patterns of file names to exclude from the gallery. Defaults to [] (none). | ||
95 | 98 | ||
96 | compiler.tagsFromDirectories | 99 | compiler.tagsFromDirectories |
97 | : How far to look at parent directories to add implicit tags. Defaults to 0. | 100 | : How far to look at parent directories to add implicit tags. Defaults to 0. |