aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Compiler.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src/Compiler.hs')
-rw-r--r--compiler/src/Compiler.hs35
1 files changed, 28 insertions, 7 deletions
diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs
index 5c47521..854fd03 100644
--- a/compiler/src/Compiler.hs
+++ b/compiler/src/Compiler.hs
@@ -35,7 +35,19 @@ import Data.Aeson (ToJSON)
35import qualified Data.Aeson as JSON 35import qualified Data.Aeson as JSON
36 36
37import Config 37import Config
38import Files (FileName, readDirectory, localPath, isHidden, nodeName, filterDir, flattenDir, root, (/>), ensureParentDir) 38import Files
39 ( FileName
40 , readDirectory
41 , localPath
42 , isHidden
43 , nodeName
44 , filterDir
45 , flattenDir
46 , root
47 , (/>)
48 , ensureParentDir
49 , isOutdated )
50
39import Input (decodeYamlFile, readInputTree) 51import Input (decodeYamlFile, readInputTree)
40import Resource (ResourceTree, buildResourceTree, cleanupResourceDir) 52import Resource (ResourceTree, buildResourceTree, cleanupResourceDir)
41import Gallery (buildGalleryTree) 53import Gallery (buildGalleryTree)
@@ -52,7 +64,10 @@ writeJSON outputPath object =
52compileGallery :: FilePath -> FilePath -> IO () 64compileGallery :: FilePath -> FilePath -> IO ()
53compileGallery inputDirPath outputDirPath = 65compileGallery inputDirPath outputDirPath =
54 do 66 do
55 config <- readConfig (inputDirPath </> galleryConf) 67 fullConfig <- readConfig inputGalleryConf
68 let config = compiler fullConfig
69
70 -- TODO: exclude output dir if it's under the input dir
56 inputDir <- readDirectory inputDirPath 71 inputDir <- readDirectory inputDirPath
57 72
58 let isGalleryFile = \n -> nodeName n == galleryConf 73 let isGalleryFile = \n -> nodeName n == galleryConf
@@ -60,20 +75,26 @@ compileGallery inputDirPath outputDirPath =
60 75
61 inputTree <- readInputTree galleryTree 76 inputTree <- readInputTree galleryTree
62 77
78 invalidateCache <- isOutdated inputGalleryConf outputIndex
79 let cache = if invalidateCache then skipCached else withCached
63 let dirProc = dirFileProcessor inputDirPath outputDirPath itemsDir 80 let dirProc = dirFileProcessor inputDirPath outputDirPath itemsDir
64 let itemProc = itemFileProcessor Nothing skipCached inputDirPath outputDirPath itemsDir 81 let itemProc = itemFileProcessor (pictureMaxResolution config) cache inputDirPath outputDirPath itemsDir
65 let thumbnailProc = thumbnailFileProcessor (Resolution 150 50) skipCached inputDirPath outputDirPath thumbnailsDir 82 let thumbnailProc = thumbnailFileProcessor (thumbnailResolution config) cache inputDirPath outputDirPath thumbnailsDir
66 resourceTree <- buildResourceTree dirProc itemProc thumbnailProc inputTree 83 resourceTree <- buildResourceTree dirProc itemProc thumbnailProc inputTree
67 84
68 cleanupResourceDir resourceTree outputDirPath 85 cleanupResourceDir resourceTree outputDirPath
69 86
70 buildGalleryTree resourceTree 87 buildGalleryTree resourceTree
71 & writeJSON (outputDirPath </> "index.json") 88 & writeJSON outputIndex
72 89
73 viewer config 90 viewer fullConfig
74 & writeJSON (outputDirPath </> "viewer.json") 91 & writeJSON outputViewerConf
75 92
76 where 93 where
77 galleryConf = "gallery.yaml" 94 galleryConf = "gallery.yaml"
78 itemsDir = "items" 95 itemsDir = "items"
79 thumbnailsDir = "thumbnails" 96 thumbnailsDir = "thumbnails"
97
98 inputGalleryConf = inputDirPath </> galleryConf
99 outputIndex = outputDirPath </> "index.json"
100 outputViewerConf = outputDirPath </> "viewer.json"