diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/src/Files.hs | 2 | ||||
-rw-r--r-- | compiler/src/Input.hs | 13 | ||||
-rw-r--r-- | compiler/src/Lib.hs | 41 |
3 files changed, 42 insertions, 14 deletions
diff --git a/compiler/src/Files.hs b/compiler/src/Files.hs index 7948842..30e4b94 100644 --- a/compiler/src/Files.hs +++ b/compiler/src/Files.hs | |||
@@ -32,9 +32,9 @@ import Data.Bool (bool) | |||
32 | import Data.List (isPrefixOf, length, deleteBy) | 32 | import Data.List (isPrefixOf, length, deleteBy) |
33 | import Data.Function ((&)) | 33 | import Data.Function ((&)) |
34 | import System.Directory (doesDirectoryExist, listDirectory) | 34 | import System.Directory (doesDirectoryExist, listDirectory) |
35 | |||
35 | import qualified System.FilePath | 36 | import qualified System.FilePath |
36 | import qualified System.FilePath.Posix | 37 | import qualified System.FilePath.Posix |
37 | import Utils | ||
38 | 38 | ||
39 | 39 | ||
40 | type FileName = String | 40 | type FileName = String |
diff --git a/compiler/src/Input.hs b/compiler/src/Input.hs index 78622bf..fa36d59 100644 --- a/compiler/src/Input.hs +++ b/compiler/src/Input.hs | |||
@@ -20,7 +20,8 @@ | |||
20 | 20 | ||
21 | 21 | ||
22 | module Input | 22 | module Input |
23 | ( Sidecar, title, date, description, tags | 23 | ( decodeYamlFile |
24 | , Sidecar, title, date, description, tags | ||
24 | , InputTree(..), readInputTree | 25 | , InputTree(..), readInputTree |
25 | ) where | 26 | ) where |
26 | 27 | ||
@@ -42,12 +43,10 @@ import Utils | |||
42 | data LoadException = LoadException String ParseException deriving Show | 43 | data LoadException = LoadException String ParseException deriving Show |
43 | instance Exception LoadException | 44 | instance Exception LoadException |
44 | 45 | ||
45 | decodeYamlFile :: (MonadIO m, FromJSON a) => Path -> m a | 46 | decodeYamlFile :: (MonadIO m, FromJSON a) => FileName -> m a |
46 | decodeYamlFile path = | 47 | decodeYamlFile path = |
47 | liftIO $ Data.Yaml.decodeFileEither fpath | 48 | liftIO $ Data.Yaml.decodeFileEither path |
48 | >>= either (throwIO . LoadException fpath) return | 49 | >>= either (throwIO . LoadException path) return |
49 | where | ||
50 | fpath = localPath path | ||
51 | 50 | ||
52 | 51 | ||
53 | -- | Tree representing the input from the input directory. | 52 | -- | Tree representing the input from the input directory. |
@@ -75,7 +74,7 @@ readInputTree (AnchoredFSNode anchor root@Dir{}) = | |||
75 | where | 74 | where |
76 | mkInputNode :: FSNode -> IO (Maybe InputTree) | 75 | mkInputNode :: FSNode -> IO (Maybe InputTree) |
77 | mkInputNode (File path@(filename:pathto)) | ".yaml" `isExtensionOf` filename = | 76 | mkInputNode (File path@(filename:pathto)) | ".yaml" `isExtensionOf` filename = |
78 | decodeYamlFile (anchor /> path) | 77 | decodeYamlFile (localPath $ anchor /> path) |
79 | >>= return . InputFile ((dropExtension filename):pathto) | 78 | >>= return . InputFile ((dropExtension filename):pathto) |
80 | >>= return . Just | 79 | >>= return . Just |
81 | mkInputNode File{} = return Nothing | 80 | mkInputNode File{} = return Nothing |
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 () |