diff options
author | pacien | 2019-12-25 22:48:34 +0100 |
---|---|---|
committer | pacien | 2019-12-25 22:48:34 +0100 |
commit | 5b35285daa62fb9c10280fb43e340ba7b0746f5a (patch) | |
tree | 982561d1bb179dd76b6537d2e14fd58d17e749b6 /compiler/src/Lib.hs | |
parent | 0b2f6fb420d213b4ee718b9ac79cc3f9fa7678d5 (diff) | |
download | ldgallery-5b35285daa62fb9c10280fb43e340ba7b0746f5a.tar.gz |
compiler: add gallery config file handling
Diffstat (limited to 'compiler/src/Lib.hs')
-rw-r--r-- | compiler/src/Lib.hs | 41 |
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) | |||
26 | import Data.Function ((&)) | 28 | import Data.Function ((&)) |
27 | import System.Directory (createDirectoryIfMissing) | 29 | import System.Directory (createDirectoryIfMissing) |
28 | import System.FilePath (dropFileName, (</>)) | 30 | import System.FilePath (dropFileName, (</>)) |
29 | import Data.Aeson (ToJSON, encodeFile) | 31 | import Data.Aeson (Object, ToJSON, FromJSON, encodeFile) |
30 | 32 | ||
31 | import Files (FileName, readDirectory) | 33 | import Files (FileName, readDirectory) |
32 | import Input (readInputTree) | 34 | import Input (decodeYamlFile, readInputTree) |
33 | import Resource (buildResourceTree) | 35 | import Resource (buildResourceTree) |
34 | import Gallery (buildGalleryTree) | 36 | import Gallery (buildGalleryTree) |
35 | 37 | ||
36 | 38 | ||
37 | writeJSON :: ToJSON a => FileName -> a -> IO () | 39 | data CompilerConfig = CompilerConfig |
38 | writeJSON path obj = | 40 | { dummy :: Maybe String -- TODO |
39 | createDirectoryIfMissing True (dropFileName path) | 41 | } deriving (Generic, FromJSON, Show) |
40 | >> encodeFile path obj | 42 | |
43 | data GalleryConfig = GalleryConfig | ||
44 | { compiler :: CompilerConfig | ||
45 | , viewer :: Data.Aeson.Object | ||
46 | } deriving (Generic, FromJSON, Show) | ||
47 | |||
48 | readConfig :: FileName -> IO GalleryConfig | ||
49 | readConfig = decodeYamlFile | ||
41 | 50 | ||
42 | 51 | ||
43 | process :: FilePath -> FilePath -> IO () | 52 | process :: FilePath -> FilePath -> IO () |
44 | process inputDirPath outputDirPath = | 53 | process 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 | ||
69 | testRun :: IO () | 98 | testRun :: IO () |