diff options
author | pacien | 2019-12-27 10:21:44 +0100 |
---|---|---|
committer | pacien | 2019-12-27 10:21:44 +0100 |
commit | 015d793b25a3f0d1ff275ed42ec211dd6a532ca0 (patch) | |
tree | 3b6f5b96631c4f8575ce32a0a07b647ebbedc0a4 | |
parent | eb7a652b2244ffa4dd5ba2440b7879127e7c6078 (diff) | |
download | ldgallery-015d793b25a3f0d1ff275ed42ec211dd6a532ca0.tar.gz |
compiler: fix old resources cleanup
-rw-r--r-- | compiler/src/Compiler.hs | 13 | ||||
-rw-r--r-- | compiler/src/Resource.hs | 10 |
2 files changed, 16 insertions, 7 deletions
diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index 9767394..991de9c 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs | |||
@@ -71,16 +71,15 @@ compileGallery inputDirPath outputDirPath = | |||
71 | putStrLn "\nRESOURCE TREE" | 71 | putStrLn "\nRESOURCE TREE" |
72 | putStrLn (show resourceTree) | 72 | putStrLn (show resourceTree) |
73 | 73 | ||
74 | --cleanup resourceTree outputDirPath | 74 | cleanup resourceTree outputDirPath |
75 | 75 | ||
76 | buildGalleryTree resourceTree | 76 | buildGalleryTree resourceTree |
77 | & ensureParentDir JSON.encodeFile (outputDirPath </> "index.json") | 77 | & writeJSON (outputDirPath </> "index.json") |
78 | 78 | ||
79 | viewer config | 79 | viewer config |
80 | & ensureParentDir JSON.encodeFile (outputDirPath </> "viewer.json") | 80 | & writeJSON (outputDirPath </> "viewer.json") |
81 | 81 | ||
82 | where | 82 | where |
83 | -- TODO: delete all files, then only non-empty dirs | ||
84 | cleanup :: ResourceTree -> FileName -> IO () | 83 | cleanup :: ResourceTree -> FileName -> IO () |
85 | cleanup resourceTree outputDir = | 84 | cleanup resourceTree outputDir = |
86 | readDirectory outputDir | 85 | readDirectory outputDir |
@@ -94,3 +93,9 @@ compileGallery inputDirPath outputDirPath = | |||
94 | do | 93 | do |
95 | putStrLn $ "Removing: " ++ path | 94 | putStrLn $ "Removing: " ++ path |
96 | removePathForcibly path | 95 | removePathForcibly path |
96 | |||
97 | writeJSON :: ToJSON a => FileName -> a -> IO () | ||
98 | writeJSON outputPath object = | ||
99 | do | ||
100 | putStrLn $ "Generating: " ++ outputPath | ||
101 | ensureParentDir JSON.encodeFile outputPath object | ||
diff --git a/compiler/src/Resource.hs b/compiler/src/Resource.hs index dc849cd..83f7438 100644 --- a/compiler/src/Resource.hs +++ b/compiler/src/Resource.hs | |||
@@ -34,7 +34,7 @@ module Resource | |||
34 | 34 | ||
35 | 35 | ||
36 | import Data.Function ((&)) | 36 | import Data.Function ((&)) |
37 | import Data.List ((\\)) | 37 | import Data.List ((\\), subsequences) |
38 | import Data.Maybe (mapMaybe) | 38 | import Data.Maybe (mapMaybe) |
39 | import Files | 39 | import Files |
40 | import Input (InputTree(..), Sidecar) | 40 | import Input (InputTree(..), Sidecar) |
@@ -93,10 +93,14 @@ flattenResourceTree dir@(DirResource items _ _) = | |||
93 | dir:(concatMap flattenResourceTree items) | 93 | dir:(concatMap flattenResourceTree items) |
94 | 94 | ||
95 | outputDiff :: ResourceTree -> FSNode -> [Path] | 95 | outputDiff :: ResourceTree -> FSNode -> [Path] |
96 | outputDiff resources ref = (fsPaths ref) \\ (resPaths $ flattenResourceTree resources) | 96 | outputDiff resources ref = |
97 | (fsPaths ref) \\ (resPaths $ flattenResourceTree resources) | ||
97 | where | 98 | where |
98 | resPaths :: [ResourceTree] -> [Path] | 99 | resPaths :: [ResourceTree] -> [Path] |
99 | resPaths resList = (map resPath resList) ++ (mapMaybe thumbnailPath resList) | 100 | resPaths resList = map resPath resList ++ thumbnailPaths resList |
101 | |||
102 | thumbnailPaths :: [ResourceTree] -> [Path] | ||
103 | thumbnailPaths = (concatMap subsequences) . (mapMaybe thumbnailPath) | ||
100 | 104 | ||
101 | fsPaths :: FSNode -> [Path] | 105 | fsPaths :: FSNode -> [Path] |
102 | fsPaths = map nodePath . tail . flattenDir | 106 | fsPaths = map nodePath . tail . flattenDir |