aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpacien2019-12-31 08:38:15 +0100
committerpacien2019-12-31 08:38:15 +0100
commit6691b14cf4e867a9018f38c174fa98f1ada19f82 (patch)
treeff43476e81ee80c38ad4fb28822853849be03929
parent641ea85d4da795cb2c67d9777cb3db3dfede1d8b (diff)
downloadldgallery-6691b14cf4e867a9018f38c174fa98f1ada19f82.tar.gz
compiler: add option to ignore files matching a regex
GitHub: closes #10
-rw-r--r--compiler/package.yaml1
-rw-r--r--compiler/src/Compiler.hs47
-rw-r--r--compiler/src/Config.hs2
-rw-r--r--example/gallery.yaml10
4 files changed, 42 insertions, 18 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
30data-dir: data 31data-dir: data
31data-files: ["**/*"] 32data-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
30import Control.Monad (liftM2) 30import Control.Monad (liftM2)
31import Data.Function ((&)) 31import Data.Function ((&))
32import Data.List (any) 32import Data.List (any)
33import Data.Maybe (isJust)
34import Text.Regex (Regex, mkRegex, matchRegex)
33import System.FilePath ((</>)) 35import System.FilePath ((</>))
34 36
35import Data.Aeson (ToJSON) 37import Data.Aeson (ToJSON)
@@ -52,6 +54,14 @@ import Processors
52 , skipCached, withCached ) 54 , skipCached, withCached )
53 55
54 56
57galleryConf = "gallery.yaml"
58indexFile = "index.json"
59viewerMainFile = "index.html"
60viewerConfFile = "viewer.json"
61itemsDir = "items"
62thumbnailsDir = "thumbnails"
63
64
55writeJSON :: ToJSON a => FileName -> a -> IO () 65writeJSON :: ToJSON a => FileName -> a -> IO ()
56writeJSON outputPath object = 66writeJSON 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
72galleryDirFilter :: Regex -> FSNode -> Bool
73galleryDirFilter 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
62compileGallery :: FilePath -> FilePath -> Bool -> IO () 94compileGallery :: FilePath -> FilePath -> Bool -> IO ()
63compileGallery inputDirPath outputDirPath rebuildAll = 95compileGallery 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
43data CompilerConfig = CompilerConfig 43data 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
50instance FromJSON CompilerConfig where 51instance 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"
diff --git a/example/gallery.yaml b/example/gallery.yaml
index 3fd2265..fb25161 100644
--- a/example/gallery.yaml
+++ b/example/gallery.yaml
@@ -1,11 +1,11 @@
1compiler: 1compiler:
2 galleryName: Example gallery 2 galleryName: Example gallery
3 ignoreFiles: .*\.md
4 implicitDirectoryTag: false # default
3 5
4 #implicitDirectoryTag: false # default 6 thumbnailResolution:
5 7 width: 400 # default
6 #thumbnailResolution: 8 height: 400 # default
7 # width: 400 # default
8 # height: 400 # default
9 9
10 pictureMaxResolution: 10 pictureMaxResolution:
11 width: 1024 11 width: 1024