diff options
author | pacien | 2019-12-27 13:38:47 +0100 |
---|---|---|
committer | pacien | 2019-12-27 13:38:47 +0100 |
commit | 1e57d76eadb2192be2b3d9343d4ddfeccc996bcb (patch) | |
tree | d001300af03a431b6e0b51a1ca0292429c0eb8e8 /compiler/src | |
parent | 63b06627f200f155f66ecdb6c5f41ab44808dd6b (diff) | |
download | ldgallery-1e57d76eadb2192be2b3d9343d4ddfeccc996bcb.tar.gz |
compiler: exclude output dir from input
Diffstat (limited to 'compiler/src')
-rw-r--r-- | compiler/src/Compiler.hs | 59 |
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 | ||
30 | import Control.Monad | 30 | import Control.Monad (liftM2) |
31 | import Data.Function ((&)) | 31 | import Data.Function ((&)) |
32 | import Data.List (any) | ||
32 | import System.FilePath ((</>)) | 33 | import System.FilePath ((</>)) |
33 | 34 | ||
34 | import Data.Aeson (ToJSON) | 35 | import Data.Aeson (ToJSON) |
35 | import qualified Data.Aeson as JSON | 36 | import qualified Data.Aeson as JSON |
36 | 37 | ||
37 | import Config | 38 | import Config |
39 | import Input (decodeYamlFile, readInputTree) | ||
40 | import Resource (ResourceTree, buildResourceTree, cleanupResourceDir) | ||
41 | import Gallery (buildGalleryTree) | ||
38 | import Files | 42 | import 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 | |||
51 | import Input (decodeYamlFile, readInputTree) | ||
52 | import Resource (ResourceTree, buildResourceTree, cleanupResourceDir) | ||
53 | import Gallery (buildGalleryTree) | ||
54 | import Processors | 51 | import Processors |
52 | ( dirFileProcessor | ||
53 | , itemFileProcessor | ||
54 | , thumbnailFileProcessor | ||
55 | , skipCached | ||
56 | , withCached ) | ||
55 | 57 | ||
56 | 58 | ||
57 | writeJSON :: ToJSON a => FileName -> a -> IO () | 59 | writeJSON :: 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 | ||
64 | compileGallery :: FilePath -> FilePath -> IO () | 66 | compileGallery :: FilePath -> FilePath -> Bool -> IO () |
65 | compileGallery inputDirPath outputDirPath = | 67 | compileGallery 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 | ||