aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/src/Files.hs2
-rw-r--r--compiler/src/Input.hs13
-rw-r--r--compiler/src/Lib.hs41
-rw-r--r--example/gallery.yaml2
4 files changed, 44 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)
32import Data.List (isPrefixOf, length, deleteBy) 32import Data.List (isPrefixOf, length, deleteBy)
33import Data.Function ((&)) 33import Data.Function ((&))
34import System.Directory (doesDirectoryExist, listDirectory) 34import System.Directory (doesDirectoryExist, listDirectory)
35
35import qualified System.FilePath 36import qualified System.FilePath
36import qualified System.FilePath.Posix 37import qualified System.FilePath.Posix
37import Utils
38 38
39 39
40type FileName = String 40type 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
22module Input 22module 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
42data LoadException = LoadException String ParseException deriving Show 43data LoadException = LoadException String ParseException deriving Show
43instance Exception LoadException 44instance Exception LoadException
44 45
45decodeYamlFile :: (MonadIO m, FromJSON a) => Path -> m a 46decodeYamlFile :: (MonadIO m, FromJSON a) => FileName -> m a
46decodeYamlFile path = 47decodeYamlFile 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)
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 ()
diff --git a/example/gallery.yaml b/example/gallery.yaml
new file mode 100644
index 0000000..fc4bdf9
--- /dev/null
+++ b/example/gallery.yaml
@@ -0,0 +1,2 @@
1compiler: {}
2viewer: {}