aboutsummaryrefslogtreecommitdiff
path: root/compiler/src
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src')
-rw-r--r--compiler/src/Compiler.hs47
-rw-r--r--compiler/src/Config.hs2
2 files changed, 36 insertions, 13 deletions
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"