diff options
Diffstat (limited to 'compiler/src/Compiler.hs')
-rw-r--r-- | compiler/src/Compiler.hs | 35 |
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) | |||
35 | import qualified Data.Aeson as JSON | 35 | import qualified Data.Aeson as JSON |
36 | 36 | ||
37 | import Config | 37 | import Config |
38 | import Files (FileName, readDirectory, localPath, isHidden, nodeName, filterDir, flattenDir, root, (/>), ensureParentDir) | 38 | import Files |
39 | ( FileName | ||
40 | , readDirectory | ||
41 | , localPath | ||
42 | , isHidden | ||
43 | , nodeName | ||
44 | , filterDir | ||
45 | , flattenDir | ||
46 | , root | ||
47 | , (/>) | ||
48 | , ensureParentDir | ||
49 | , isOutdated ) | ||
50 | |||
39 | import Input (decodeYamlFile, readInputTree) | 51 | import Input (decodeYamlFile, readInputTree) |
40 | import Resource (ResourceTree, buildResourceTree, cleanupResourceDir) | 52 | import Resource (ResourceTree, buildResourceTree, cleanupResourceDir) |
41 | import Gallery (buildGalleryTree) | 53 | import Gallery (buildGalleryTree) |
@@ -52,7 +64,10 @@ writeJSON outputPath object = | |||
52 | compileGallery :: FilePath -> FilePath -> IO () | 64 | compileGallery :: FilePath -> FilePath -> IO () |
53 | compileGallery inputDirPath outputDirPath = | 65 | compileGallery 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" | ||