aboutsummaryrefslogtreecommitdiff
path: root/compiler/src
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src')
-rw-r--r--compiler/src/Compiler.hs13
-rw-r--r--compiler/src/Resource.hs10
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
36import Data.Function ((&)) 36import Data.Function ((&))
37import Data.List ((\\)) 37import Data.List ((\\), subsequences)
38import Data.Maybe (mapMaybe) 38import Data.Maybe (mapMaybe)
39import Files 39import Files
40import Input (InputTree(..), Sidecar) 40import Input (InputTree(..), Sidecar)
@@ -93,10 +93,14 @@ flattenResourceTree dir@(DirResource items _ _) =
93 dir:(concatMap flattenResourceTree items) 93 dir:(concatMap flattenResourceTree items)
94 94
95outputDiff :: ResourceTree -> FSNode -> [Path] 95outputDiff :: ResourceTree -> FSNode -> [Path]
96outputDiff resources ref = (fsPaths ref) \\ (resPaths $ flattenResourceTree resources) 96outputDiff 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