aboutsummaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/app/Main.hs15
-rw-r--r--compiler/src/Compiler.hs18
2 files changed, 20 insertions, 13 deletions
diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs
index 1229e88..404de4b 100644
--- a/compiler/app/Main.hs
+++ b/compiler/app/Main.hs
@@ -24,11 +24,11 @@ import Control.Monad (when)
24import Data.Version (showVersion) 24import Data.Version (showVersion)
25import Data.Aeson (ToJSON) 25import Data.Aeson (ToJSON)
26import System.FilePath ((</>)) 26import System.FilePath ((</>))
27import System.Directory (canonicalizePath) 27import System.Directory (canonicalizePath, listDirectory)
28import System.Console.CmdArgs 28import System.Console.CmdArgs
29 29
30import Compiler 30import Compiler
31import Files (readDirectory, copyTo) 31import Files (readDirectory, copyTo, remove)
32 32
33 33
34data ViewerConfig = ViewerConfig 34data ViewerConfig = ViewerConfig
@@ -95,12 +95,13 @@ main =
95 opts <- cmdArgs options 95 opts <- cmdArgs options
96 buildGallery opts 96 buildGallery opts
97 when (withViewer opts) $ do 97 when (withViewer opts) $ do
98 when (cleanOutput opts) $ cleanViewerDir (outputDir opts)
98 copyViewer (outputDir opts) 99 copyViewer (outputDir opts)
99 writeViewerConfig (outputDir opts </> "config.json") 100 writeViewerConfig (outputDir opts </> "config.json")
100 101
101 where 102 where
102 gallerySubdir :: String 103 gallerySubdir :: String
103 gallerySubdir = "gallery/" 104 gallerySubdir = "gallery"
104 105
105 buildGallery :: Options -> IO () 106 buildGallery :: Options -> IO ()
106 buildGallery opts = 107 buildGallery opts =
@@ -123,6 +124,12 @@ main =
123 if withViewer opts then outputBase </> gallerySubdir else outputBase 124 if withViewer opts then outputBase </> gallerySubdir else outputBase
124 where outputBase = outputDir opts 125 where outputBase = outputDir opts
125 126
127 cleanViewerDir :: FilePath -> IO ()
128 cleanViewerDir target =
129 listDirectory target
130 >>= return . filter (/= gallerySubdir)
131 >>= mapM_ remove . map (target </>)
132
126 copyViewer :: FilePath -> IO () 133 copyViewer :: FilePath -> IO ()
127 copyViewer target = 134 copyViewer target =
128 putStrLn "Copying viewer webapp" 135 putStrLn "Copying viewer webapp"
@@ -131,4 +138,4 @@ main =
131 >>= copyTo target 138 >>= copyTo target
132 139
133 writeViewerConfig :: FilePath -> IO () 140 writeViewerConfig :: FilePath -> IO ()
134 writeViewerConfig fileName = writeJSON fileName $ ViewerConfig gallerySubdir 141 writeViewerConfig fileName = writeJSON fileName $ ViewerConfig (gallerySubdir ++ "/")
diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs
index 73ac8a4..2970102 100644
--- a/compiler/src/Compiler.hs
+++ b/compiler/src/Compiler.hs
@@ -22,6 +22,7 @@ module Compiler
22 ) where 22 ) where
23 23
24 24
25import GHC.Generics (Generic)
25import Control.Monad (liftM2, when) 26import Control.Monad (liftM2, when)
26import Data.List (any) 27import Data.List (any)
27import System.FilePath ((</>)) 28import System.FilePath ((</>))
@@ -33,7 +34,7 @@ import qualified Data.Aeson as JSON
33 34
34import Config 35import Config
35import Input (readInputTree) 36import Input (readInputTree)
36import Resource (buildGalleryTree, galleryCleanupResourceDir) 37import Resource (GalleryItem, buildGalleryTree, galleryCleanupResourceDir)
37import Files 38import Files
38 ( FileName 39 ( FileName
39 , FSNode(..) 40 , FSNode(..)
@@ -53,9 +54,6 @@ defaultGalleryConf = "gallery.yaml"
53indexFile :: String 54indexFile :: String
54indexFile = "index.json" 55indexFile = "index.json"
55 56
56viewerConfFile :: String
57viewerConfFile = "viewer.json"
58
59itemsDir :: String 57itemsDir :: String
60itemsDir = "items" 58itemsDir = "items"
61 59
@@ -63,6 +61,12 @@ thumbnailsDir :: String
63thumbnailsDir = "thumbnails" 61thumbnailsDir = "thumbnails"
64 62
65 63
64data GalleryIndex = GalleryIndex
65 { properties :: ViewerConfig
66 , tree :: GalleryItem
67 } deriving (Generic, Show, ToJSON)
68
69
66writeJSON :: ToJSON a => FileName -> a -> IO () 70writeJSON :: ToJSON a => FileName -> a -> IO ()
67writeJSON outputPath object = 71writeJSON outputPath object =
68 do 72 do
@@ -117,17 +121,13 @@ compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cle
117 resources <- galleryBuilder inputTree 121 resources <- galleryBuilder inputTree
118 122
119 when cleanOutput $ galleryCleanupResourceDir resources outputDirPath 123 when cleanOutput $ galleryCleanupResourceDir resources outputDirPath
120 writeJSON outputIndex resources 124 writeJSON (outputDirPath </> indexFile) $ GalleryIndex (viewerConfig config) resources
121 writeJSON outputViewerConf $ viewerConfig config
122 125
123 where 126 where
124 inputGalleryConf :: FilePath -> FilePath 127 inputGalleryConf :: FilePath -> FilePath
125 inputGalleryConf "" = inputDirPath </> defaultGalleryConf 128 inputGalleryConf "" = inputDirPath </> defaultGalleryConf
126 inputGalleryConf file = file 129 inputGalleryConf file = file
127 130
128 outputIndex = outputDirPath </> indexFile
129 outputViewerConf = outputDirPath </> viewerConfFile
130
131 itemProcessor config cache = 131 itemProcessor config cache =
132 itemFileProcessor 132 itemFileProcessor
133 (pictureMaxResolution config) cache 133 (pictureMaxResolution config) cache