aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Lib.hs
diff options
context:
space:
mode:
authorpacien2019-12-25 22:48:34 +0100
committerpacien2019-12-25 22:48:34 +0100
commit5b35285daa62fb9c10280fb43e340ba7b0746f5a (patch)
tree982561d1bb179dd76b6537d2e14fd58d17e749b6 /compiler/src/Lib.hs
parent0b2f6fb420d213b4ee718b9ac79cc3f9fa7678d5 (diff)
downloadldgallery-5b35285daa62fb9c10280fb43e340ba7b0746f5a.tar.gz
compiler: add gallery config file handling
Diffstat (limited to 'compiler/src/Lib.hs')
-rw-r--r--compiler/src/Lib.hs41
1 files changed, 35 insertions, 6 deletions
diff --git a/compiler/src/Lib.hs b/compiler/src/Lib.hs
index bab7e9c..abdbeb7 100644
--- a/compiler/src/Lib.hs
+++ b/compiler/src/Lib.hs
@@ -1,3 +1,5 @@
1{-# LANGUAGE DuplicateRecordFields, DeriveGeneric, DeriveAnyClass #-}
2
1-- ldgallery - A static generator which turns a collection of tagged 3-- ldgallery - A static generator which turns a collection of tagged
2-- pictures into a searchable web gallery. 4-- pictures into a searchable web gallery.
3-- 5--
@@ -26,23 +28,32 @@ import GHC.Generics (Generic)
26import Data.Function ((&)) 28import Data.Function ((&))
27import System.Directory (createDirectoryIfMissing) 29import System.Directory (createDirectoryIfMissing)
28import System.FilePath (dropFileName, (</>)) 30import System.FilePath (dropFileName, (</>))
29import Data.Aeson (ToJSON, encodeFile) 31import Data.Aeson (Object, ToJSON, FromJSON, encodeFile)
30 32
31import Files (FileName, readDirectory) 33import Files (FileName, readDirectory)
32import Input (readInputTree) 34import Input (decodeYamlFile, readInputTree)
33import Resource (buildResourceTree) 35import Resource (buildResourceTree)
34import Gallery (buildGalleryTree) 36import Gallery (buildGalleryTree)
35 37
36 38
37writeJSON :: ToJSON a => FileName -> a -> IO () 39data CompilerConfig = CompilerConfig
38writeJSON path obj = 40 { dummy :: Maybe String -- TODO
39 createDirectoryIfMissing True (dropFileName path) 41 } deriving (Generic, FromJSON, Show)
40 >> encodeFile path obj 42
43data GalleryConfig = GalleryConfig
44 { compiler :: CompilerConfig
45 , viewer :: Data.Aeson.Object
46 } deriving (Generic, FromJSON, Show)
47
48readConfig :: FileName -> IO GalleryConfig
49readConfig = decodeYamlFile
41 50
42 51
43process :: FilePath -> FilePath -> IO () 52process :: FilePath -> FilePath -> IO ()
44process inputDirPath outputDirPath = 53process inputDirPath outputDirPath =
45 do 54 do
55 config <- readConfig (inputDirPath </> "gallery.yaml")
56
46 inputDir <- readDirectory inputDirPath 57 inputDir <- readDirectory inputDirPath
47 putStrLn "\nINPUT DIR" 58 putStrLn "\nINPUT DIR"
48 putStrLn (show inputDir) 59 putStrLn (show inputDir)
@@ -60,10 +71,28 @@ process inputDirPath outputDirPath =
60 putStrLn (show resourceTree) 71 putStrLn (show resourceTree)
61 72
62 -- TODO: make buildResourceTree build a resource compilation strategy 73 -- TODO: make buildResourceTree build a resource compilation strategy
74 -- (need to know the settings)
75 -- flatten the tree of resources and their strategies
76 -- filter resources that are already up to date
77 -- (or recompile everything if the config file has changed!)
78 -- execute in parallel
79
63 -- TODO: clean up output dir by comparing its content with the resource tree 80 -- TODO: clean up output dir by comparing its content with the resource tree
81 -- aggregate both trees as list
82 -- compute the difference
83 -- sort by deepest and erase files and dirs
84
64 -- TODO: execute (in parallel) the resource compilation strategy list 85 -- TODO: execute (in parallel) the resource compilation strategy list
86 -- need to find a good library for that
65 87
66 buildGalleryTree resourceTree & writeJSON (outputDirPath </> "index.json") 88 buildGalleryTree resourceTree & writeJSON (outputDirPath </> "index.json")
89 writeJSON (outputDirPath </> "viewer.json") (viewer config)
90
91 where
92 writeJSON :: ToJSON a => FileName -> a -> IO ()
93 writeJSON path obj =
94 createDirectoryIfMissing True (dropFileName path)
95 >> encodeFile path obj
67 96
68 97
69testRun :: IO () 98testRun :: IO ()