aboutsummaryrefslogtreecommitdiff
path: root/compiler/src
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src')
-rw-r--r--compiler/src/Compiler.hs59
1 files changed, 35 insertions, 24 deletions
diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs
index 854fd03..2584570 100644
--- a/compiler/src/Compiler.hs
+++ b/compiler/src/Compiler.hs
@@ -27,31 +27,33 @@ module Compiler
27 ) where 27 ) where
28 28
29 29
30import Control.Monad 30import Control.Monad (liftM2)
31import Data.Function ((&)) 31import Data.Function ((&))
32import Data.List (any)
32import System.FilePath ((</>)) 33import System.FilePath ((</>))
33 34
34import Data.Aeson (ToJSON) 35import Data.Aeson (ToJSON)
35import qualified Data.Aeson as JSON 36import qualified Data.Aeson as JSON
36 37
37import Config 38import Config
39import Input (decodeYamlFile, readInputTree)
40import Resource (ResourceTree, buildResourceTree, cleanupResourceDir)
41import Gallery (buildGalleryTree)
38import Files 42import Files
39 ( FileName 43 ( FileName
44 , FSNode(..)
40 , readDirectory 45 , readDirectory
41 , localPath
42 , isHidden 46 , isHidden
43 , nodeName 47 , nodeName
44 , filterDir 48 , filterDir
45 , flattenDir
46 , root
47 , (/>)
48 , ensureParentDir 49 , ensureParentDir
49 , isOutdated ) 50 , isOutdated )
50
51import Input (decodeYamlFile, readInputTree)
52import Resource (ResourceTree, buildResourceTree, cleanupResourceDir)
53import Gallery (buildGalleryTree)
54import Processors 51import Processors
52 ( dirFileProcessor
53 , itemFileProcessor
54 , thumbnailFileProcessor
55 , skipCached
56 , withCached )
55 57
56 58
57writeJSON :: ToJSON a => FileName -> a -> IO () 59writeJSON :: ToJSON a => FileName -> a -> IO ()
@@ -61,26 +63,21 @@ writeJSON outputPath object =
61 ensureParentDir JSON.encodeFile outputPath object 63 ensureParentDir JSON.encodeFile outputPath object
62 64
63 65
64compileGallery :: FilePath -> FilePath -> IO () 66compileGallery :: FilePath -> FilePath -> Bool -> IO ()
65compileGallery inputDirPath outputDirPath = 67compileGallery inputDirPath outputDirPath rebuildAll =
66 do 68 do
67 fullConfig <- readConfig inputGalleryConf 69 fullConfig <- readConfig inputGalleryConf
68 let config = compiler fullConfig 70 let config = compiler fullConfig
69 71
70 -- TODO: exclude output dir if it's under the input dir
71 inputDir <- readDirectory inputDirPath 72 inputDir <- readDirectory inputDirPath
72 73 let sourceTree = filterDir galleryDirFilter inputDir
73 let isGalleryFile = \n -> nodeName n == galleryConf 74 inputTree <- readInputTree sourceTree
74 let galleryTree = filterDir (liftM2 (&&) (not . isGalleryFile) (not . isHidden)) inputDir
75
76 inputTree <- readInputTree galleryTree
77 75
78 invalidateCache <- isOutdated inputGalleryConf outputIndex 76 invalidateCache <- isOutdated inputGalleryConf outputIndex
79 let cache = if invalidateCache then skipCached else withCached 77 let cache = if invalidateCache || rebuildAll then skipCached else withCached
80 let dirProc = dirFileProcessor inputDirPath outputDirPath itemsDir 78 let itemProc = itemProcessor (pictureMaxResolution config) cache
81 let itemProc = itemFileProcessor (pictureMaxResolution config) cache inputDirPath outputDirPath itemsDir 79 let thumbnailProc = thumbnailProcessor (thumbnailResolution config) cache
82 let thumbnailProc = thumbnailFileProcessor (thumbnailResolution config) cache inputDirPath outputDirPath thumbnailsDir 80 resourceTree <- buildResourceTree dirProcessor itemProc thumbnailProc inputTree
83 resourceTree <- buildResourceTree dirProc itemProc thumbnailProc inputTree
84 81
85 cleanupResourceDir resourceTree outputDirPath 82 cleanupResourceDir resourceTree outputDirPath
86 83
@@ -92,9 +89,23 @@ compileGallery inputDirPath outputDirPath =
92 89
93 where 90 where
94 galleryConf = "gallery.yaml" 91 galleryConf = "gallery.yaml"
92 indexFile = "index.json"
93 viewerConfFile = "viewer.json"
95 itemsDir = "items" 94 itemsDir = "items"
96 thumbnailsDir = "thumbnails" 95 thumbnailsDir = "thumbnails"
97 96
98 inputGalleryConf = inputDirPath </> galleryConf 97 inputGalleryConf = inputDirPath </> galleryConf
99 outputIndex = outputDirPath </> "index.json" 98 outputIndex = outputDirPath </> indexFile
100 outputViewerConf = outputDirPath </> "viewer.json" 99 outputViewerConf = outputDirPath </> viewerConfFile
100
101 (&&&) = liftM2 (&&)
102 galleryDirFilter = (not . containsOutputGallery) &&& (not . isConfigFile) &&& (not . isHidden)
103 isConfigFile = (==) galleryConf . nodeName
104 containsOutputGallery (File _) = False
105 containsOutputGallery (Dir _ items) = any ((==) indexFile . nodeName) items
106
107 dirProcessor = dirFileProcessor inputDirPath outputDirPath itemsDir
108 itemProcessor maxRes cache =
109 itemFileProcessor maxRes cache inputDirPath outputDirPath itemsDir
110 thumbnailProcessor thumbRes cache =
111 thumbnailFileProcessor thumbRes cache inputDirPath outputDirPath thumbnailsDir