diff options
author | pacien | 2019-12-31 08:38:15 +0100 |
---|---|---|
committer | pacien | 2019-12-31 08:38:15 +0100 |
commit | 6691b14cf4e867a9018f38c174fa98f1ada19f82 (patch) | |
tree | ff43476e81ee80c38ad4fb28822853849be03929 /compiler | |
parent | 641ea85d4da795cb2c67d9777cb3db3dfede1d8b (diff) | |
download | ldgallery-6691b14cf4e867a9018f38c174fa98f1ada19f82.tar.gz |
compiler: add option to ignore files matching a regex
GitHub: closes #10
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/package.yaml | 1 | ||||
-rw-r--r-- | compiler/src/Compiler.hs | 47 | ||||
-rw-r--r-- | compiler/src/Config.hs | 2 |
3 files changed, 37 insertions, 13 deletions
diff --git a/compiler/package.yaml b/compiler/package.yaml index 0b03887..0577bb5 100644 --- a/compiler/package.yaml +++ b/compiler/package.yaml | |||
@@ -26,6 +26,7 @@ dependencies: | |||
26 | - JuicyPixels | 26 | - JuicyPixels |
27 | - JuicyPixels-extra | 27 | - JuicyPixels-extra |
28 | - parallel-io | 28 | - parallel-io |
29 | - regex-compat | ||
29 | 30 | ||
30 | data-dir: data | 31 | data-dir: data |
31 | data-files: ["**/*"] | 32 | data-files: ["**/*"] |
diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index 9572d50..0132b1a 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs | |||
@@ -30,6 +30,8 @@ module Compiler | |||
30 | import Control.Monad (liftM2) | 30 | import Control.Monad (liftM2) |
31 | import Data.Function ((&)) | 31 | import Data.Function ((&)) |
32 | import Data.List (any) | 32 | import Data.List (any) |
33 | import Data.Maybe (isJust) | ||
34 | import Text.Regex (Regex, mkRegex, matchRegex) | ||
33 | import System.FilePath ((</>)) | 35 | import System.FilePath ((</>)) |
34 | 36 | ||
35 | import Data.Aeson (ToJSON) | 37 | import Data.Aeson (ToJSON) |
@@ -52,6 +54,14 @@ import Processors | |||
52 | , skipCached, withCached ) | 54 | , skipCached, withCached ) |
53 | 55 | ||
54 | 56 | ||
57 | galleryConf = "gallery.yaml" | ||
58 | indexFile = "index.json" | ||
59 | viewerMainFile = "index.html" | ||
60 | viewerConfFile = "viewer.json" | ||
61 | itemsDir = "items" | ||
62 | thumbnailsDir = "thumbnails" | ||
63 | |||
64 | |||
55 | writeJSON :: ToJSON a => FileName -> a -> IO () | 65 | writeJSON :: ToJSON a => FileName -> a -> IO () |
56 | writeJSON outputPath object = | 66 | writeJSON outputPath object = |
57 | do | 67 | do |
@@ -59,6 +69,28 @@ writeJSON outputPath object = | |||
59 | ensureParentDir JSON.encodeFile outputPath object | 69 | ensureParentDir JSON.encodeFile outputPath object |
60 | 70 | ||
61 | 71 | ||
72 | galleryDirFilter :: Regex -> FSNode -> Bool | ||
73 | galleryDirFilter excludeRegex = | ||
74 | (not . isHidden) | ||
75 | &&& (not . isConfigFile) | ||
76 | &&& (not . containsOutputGallery) | ||
77 | &&& (not . excludedName) | ||
78 | |||
79 | where | ||
80 | (&&&) = liftM2 (&&) | ||
81 | (|||) = liftM2 (||) | ||
82 | |||
83 | isConfigFile = (galleryConf ==) . nodeName | ||
84 | |||
85 | isGalleryIndex = (indexFile ==) | ||
86 | isViewerIndex = (viewerMainFile ==) | ||
87 | containsOutputGallery (File _) = False | ||
88 | containsOutputGallery (Dir _ items) = | ||
89 | any ((isGalleryIndex ||| isViewerIndex) . nodeName) items | ||
90 | |||
91 | excludedName = isJust . matchRegex excludeRegex . nodeName | ||
92 | |||
93 | |||
62 | compileGallery :: FilePath -> FilePath -> Bool -> IO () | 94 | compileGallery :: FilePath -> FilePath -> Bool -> IO () |
63 | compileGallery inputDirPath outputDirPath rebuildAll = | 95 | compileGallery inputDirPath outputDirPath rebuildAll = |
64 | do | 96 | do |
@@ -66,7 +98,8 @@ compileGallery inputDirPath outputDirPath rebuildAll = | |||
66 | let config = compiler fullConfig | 98 | let config = compiler fullConfig |
67 | 99 | ||
68 | inputDir <- readDirectory inputDirPath | 100 | inputDir <- readDirectory inputDirPath |
69 | let sourceTree = filterDir galleryDirFilter inputDir | 101 | let sourceFilter = galleryDirFilter (mkRegex $ ignoreFiles config) |
102 | let sourceTree = filterDir sourceFilter inputDir | ||
70 | inputTree <- readInputTree sourceTree | 103 | inputTree <- readInputTree sourceTree |
71 | 104 | ||
72 | invalidateCache <- isOutdated False inputGalleryConf outputIndex | 105 | invalidateCache <- isOutdated False inputGalleryConf outputIndex |
@@ -82,22 +115,10 @@ compileGallery inputDirPath outputDirPath rebuildAll = | |||
82 | writeJSON outputViewerConf $ viewer fullConfig | 115 | writeJSON outputViewerConf $ viewer fullConfig |
83 | 116 | ||
84 | where | 117 | where |
85 | galleryConf = "gallery.yaml" | ||
86 | indexFile = "index.json" | ||
87 | viewerConfFile = "viewer.json" | ||
88 | itemsDir = "items" | ||
89 | thumbnailsDir = "thumbnails" | ||
90 | |||
91 | inputGalleryConf = inputDirPath </> galleryConf | 118 | inputGalleryConf = inputDirPath </> galleryConf |
92 | outputIndex = outputDirPath </> indexFile | 119 | outputIndex = outputDirPath </> indexFile |
93 | outputViewerConf = outputDirPath </> viewerConfFile | 120 | outputViewerConf = outputDirPath </> viewerConfFile |
94 | 121 | ||
95 | (&&&) = liftM2 (&&) | ||
96 | galleryDirFilter = (not . containsOutputGallery) &&& (not . isConfigFile) &&& (not . isHidden) | ||
97 | isConfigFile = (==) galleryConf . nodeName | ||
98 | containsOutputGallery (File _) = False | ||
99 | containsOutputGallery (Dir _ items) = any ((==) indexFile . nodeName) items | ||
100 | |||
101 | dirProcessor = dirFileProcessor inputDirPath outputDirPath itemsDir | 122 | dirProcessor = dirFileProcessor inputDirPath outputDirPath itemsDir |
102 | itemProcessor maxRes cache = | 123 | itemProcessor maxRes cache = |
103 | itemFileProcessor maxRes cache inputDirPath outputDirPath itemsDir | 124 | itemFileProcessor maxRes cache inputDirPath outputDirPath itemsDir |
diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index d025afd..ca3259f 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs | |||
@@ -42,6 +42,7 @@ import Resource (Resolution(..)) | |||
42 | 42 | ||
43 | data CompilerConfig = CompilerConfig | 43 | data CompilerConfig = CompilerConfig |
44 | { galleryName :: String | 44 | { galleryName :: String |
45 | , ignoreFiles :: String | ||
45 | , implicitDirectoryTag :: Bool | 46 | , implicitDirectoryTag :: Bool |
46 | , thumbnailResolution :: Resolution | 47 | , thumbnailResolution :: Resolution |
47 | , pictureMaxResolution :: Maybe Resolution | 48 | , pictureMaxResolution :: Maybe Resolution |
@@ -50,6 +51,7 @@ data CompilerConfig = CompilerConfig | |||
50 | instance FromJSON CompilerConfig where | 51 | instance FromJSON CompilerConfig where |
51 | parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig | 52 | parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig |
52 | <$> v .:? "galleryName" .!= "Gallery" | 53 | <$> v .:? "galleryName" .!= "Gallery" |
54 | <*> v .:? "ignoreFiles" .!= ".^" | ||
53 | <*> v .:? "implicitDirectoryTag" .!= False | 55 | <*> v .:? "implicitDirectoryTag" .!= False |
54 | <*> v .:? "thumbnailResolution" .!= (Resolution 400 400) | 56 | <*> v .:? "thumbnailResolution" .!= (Resolution 400 400) |
55 | <*> v .:? "pictureMaxResolution" | 57 | <*> v .:? "pictureMaxResolution" |