diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/app/Main.hs | 15 | ||||
-rw-r--r-- | compiler/src/Compiler.hs | 18 |
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) | |||
24 | import Data.Version (showVersion) | 24 | import Data.Version (showVersion) |
25 | import Data.Aeson (ToJSON) | 25 | import Data.Aeson (ToJSON) |
26 | import System.FilePath ((</>)) | 26 | import System.FilePath ((</>)) |
27 | import System.Directory (canonicalizePath) | 27 | import System.Directory (canonicalizePath, listDirectory) |
28 | import System.Console.CmdArgs | 28 | import System.Console.CmdArgs |
29 | 29 | ||
30 | import Compiler | 30 | import Compiler |
31 | import Files (readDirectory, copyTo) | 31 | import Files (readDirectory, copyTo, remove) |
32 | 32 | ||
33 | 33 | ||
34 | data ViewerConfig = ViewerConfig | 34 | data 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 | ||
25 | import GHC.Generics (Generic) | ||
25 | import Control.Monad (liftM2, when) | 26 | import Control.Monad (liftM2, when) |
26 | import Data.List (any) | 27 | import Data.List (any) |
27 | import System.FilePath ((</>)) | 28 | import System.FilePath ((</>)) |
@@ -33,7 +34,7 @@ import qualified Data.Aeson as JSON | |||
33 | 34 | ||
34 | import Config | 35 | import Config |
35 | import Input (readInputTree) | 36 | import Input (readInputTree) |
36 | import Resource (buildGalleryTree, galleryCleanupResourceDir) | 37 | import Resource (GalleryItem, buildGalleryTree, galleryCleanupResourceDir) |
37 | import Files | 38 | import Files |
38 | ( FileName | 39 | ( FileName |
39 | , FSNode(..) | 40 | , FSNode(..) |
@@ -53,9 +54,6 @@ defaultGalleryConf = "gallery.yaml" | |||
53 | indexFile :: String | 54 | indexFile :: String |
54 | indexFile = "index.json" | 55 | indexFile = "index.json" |
55 | 56 | ||
56 | viewerConfFile :: String | ||
57 | viewerConfFile = "viewer.json" | ||
58 | |||
59 | itemsDir :: String | 57 | itemsDir :: String |
60 | itemsDir = "items" | 58 | itemsDir = "items" |
61 | 59 | ||
@@ -63,6 +61,12 @@ thumbnailsDir :: String | |||
63 | thumbnailsDir = "thumbnails" | 61 | thumbnailsDir = "thumbnails" |
64 | 62 | ||
65 | 63 | ||
64 | data GalleryIndex = GalleryIndex | ||
65 | { properties :: ViewerConfig | ||
66 | , tree :: GalleryItem | ||
67 | } deriving (Generic, Show, ToJSON) | ||
68 | |||
69 | |||
66 | writeJSON :: ToJSON a => FileName -> a -> IO () | 70 | writeJSON :: ToJSON a => FileName -> a -> IO () |
67 | writeJSON outputPath object = | 71 | writeJSON 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 |