aboutsummaryrefslogtreecommitdiff
path: root/compiler/src
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src')
-rw-r--r--compiler/src/Config.hs (renamed from compiler/src/Utils.hs)42
-rw-r--r--compiler/src/Gallery.hs6
-rw-r--r--compiler/src/Input.hs3
-rw-r--r--compiler/src/Lib.hs35
4 files changed, 38 insertions, 48 deletions
diff --git a/compiler/src/Utils.hs b/compiler/src/Config.hs
index 794382c..6f04818 100644
--- a/compiler/src/Utils.hs
+++ b/compiler/src/Config.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--
@@ -17,33 +19,31 @@
17-- along with this program. If not, see <https://www.gnu.org/licenses/>. 19-- along with this program. If not, see <https://www.gnu.org/licenses/>.
18 20
19 21
20module Utils 22module Config
21 ( conj, neg 23 ( GalleryConfig(..)
22 , unique 24 , CompilerConfig(..)
23 , passthrough 25 , readConfig
24 ) where 26 ) where
25 27
28import GHC.Generics (Generic)
29import Data.Aeson (ToJSON, FromJSON)
30import qualified Data.Aeson as JSON
26 31
27import qualified Data.List 32import Files (FileName)
28import qualified Data.Set 33import Input (decodeYamlFile)
29
30
31-- predicates
32
33conj :: (a -> Bool) -> (a -> Bool) -> a -> Bool
34conj p q x = (p x) && (q x)
35
36neg :: (a -> Bool) -> a -> Bool
37neg p x = not (p x)
38 34
39 35
40-- lists 36data CompilerConfig = CompilerConfig
37 { dummy :: Maybe String -- TODO
38 } deriving (Generic, FromJSON, Show)
41 39
42unique :: Ord a => [a] -> [a] 40data GalleryConfig = GalleryConfig
43unique = Data.Set.toList . Data.Set.fromList 41 { compiler :: CompilerConfig
42 , viewer :: JSON.Object
43 } deriving (Generic, FromJSON, Show)
44 44
45-- TODO: add compiler config keys and their default values
45 46
46-- monads
47 47
48passthrough :: Monad m => (a -> m b) -> a -> m a 48readConfig :: FileName -> IO GalleryConfig
49passthrough f a = return a >>= f >>= \_ -> return a 49readConfig = decodeYamlFile
diff --git a/compiler/src/Gallery.hs b/compiler/src/Gallery.hs
index 3be62ad..ce52523 100644
--- a/compiler/src/Gallery.hs
+++ b/compiler/src/Gallery.hs
@@ -32,7 +32,8 @@ import Data.Maybe (fromMaybe)
32import Data.Aeson (ToJSON, genericToJSON, genericToEncoding) 32import Data.Aeson (ToJSON, genericToJSON, genericToEncoding)
33import qualified Data.Aeson as JSON 33import qualified Data.Aeson as JSON
34 34
35importĀ Utils 35import qualified Data.Set as Set
36
36import Files 37import Files
37import Input 38import Input
38import Resource 39import Resource
@@ -121,3 +122,6 @@ buildGalleryTree (DirResource dirItems path@(dirname:_) thumbnailPath) =
121 where 122 where
122 aggregateChildTags :: [GalleryItem] -> [Tag] 123 aggregateChildTags :: [GalleryItem] -> [Tag]
123 aggregateChildTags = unique . concatMap (\item -> tags (item::GalleryItem)) 124 aggregateChildTags = unique . concatMap (\item -> tags (item::GalleryItem))
125
126 unique :: Ord a => [a] -> [a]
127 unique = Set.toList . Set.fromList
diff --git a/compiler/src/Input.hs b/compiler/src/Input.hs
index fa36d59..681f169 100644
--- a/compiler/src/Input.hs
+++ b/compiler/src/Input.hs
@@ -37,7 +37,6 @@ import Data.Aeson (FromJSON)
37import System.FilePath (isExtensionOf, dropExtension) 37import System.FilePath (isExtensionOf, dropExtension)
38 38
39import Files 39import Files
40import Utils
41 40
42 41
43data LoadException = LoadException String ParseException deriving Show 42data LoadException = LoadException String ParseException deriving Show
@@ -70,7 +69,7 @@ data Sidecar = Sidecar
70 69
71readInputTree :: AnchoredFSNode -> IO InputTree 70readInputTree :: AnchoredFSNode -> IO InputTree
72readInputTree (AnchoredFSNode anchor root@Dir{}) = 71readInputTree (AnchoredFSNode anchor root@Dir{}) =
73 filterDir (neg isHidden) root & mkDirNode 72 filterDir (not . isHidden) root & mkDirNode
74 where 73 where
75 mkInputNode :: FSNode -> IO (Maybe InputTree) 74 mkInputNode :: FSNode -> IO (Maybe InputTree)
76 mkInputNode (File path@(filename:pathto)) | ".yaml" `isExtensionOf` filename = 75 mkInputNode (File path@(filename:pathto)) | ".yaml" `isExtensionOf` filename =
diff --git a/compiler/src/Lib.hs b/compiler/src/Lib.hs
index 643e5f6..b2bbe15 100644
--- a/compiler/src/Lib.hs
+++ b/compiler/src/Lib.hs
@@ -24,47 +24,28 @@ module Lib
24 ) where 24 ) where
25 25
26 26
27import GHC.Generics (Generic)
28import Data.Function ((&)) 27import Data.Function ((&))
29import Data.Ord (comparing) 28import Data.Ord (comparing)
30import Data.List (sortBy, length) 29import Data.List (sortBy, length)
31import System.Directory (createDirectoryIfMissing, removePathForcibly) 30import System.Directory (createDirectoryIfMissing, removePathForcibly)
32import System.FilePath (dropFileName, (</>)) 31import System.FilePath (dropFileName, (</>))
33 32
34import Data.Aeson (ToJSON, FromJSON) 33import Data.Aeson (ToJSON)
35import qualified Data.Aeson as JSON 34import qualified Data.Aeson as JSON
36 35
36import Config
37import Files (FileName, readDirectory, localPath, flattenDir, root, (/>)) 37import Files (FileName, readDirectory, localPath, flattenDir, root, (/>))
38import Input (decodeYamlFile, readInputTree) 38import Input (decodeYamlFile, readInputTree)
39import Resource (ResourceTree, buildResourceTree, outputDiff) 39import Resource (ResourceTree, buildResourceTree, outputDiff)
40import Gallery (buildGalleryTree) 40import Gallery (buildGalleryTree)
41 41
42 42
43data CompilerConfig = CompilerConfig
44 { dummy :: Maybe String -- TODO
45 } deriving (Generic, FromJSON, Show)
46
47data GalleryConfig = GalleryConfig
48 { compiler :: CompilerConfig
49 , viewer :: JSON.Object
50 } deriving (Generic, FromJSON, Show)
51
52readConfig :: FileName -> IO GalleryConfig
53readConfig = decodeYamlFile
54
55
56process :: FilePath -> FilePath -> IO () 43process :: FilePath -> FilePath -> IO ()
57process inputDirPath outputDirPath = 44process inputDirPath outputDirPath =
58 do 45 do
59 config <- readConfig (inputDirPath </> "gallery.yaml") 46 config <- readConfig (inputDirPath </> "gallery.yaml")
60
61 inputDir <- readDirectory inputDirPath 47 inputDir <- readDirectory inputDirPath
62 putStrLn "\nINPUT DIR"
63 putStrLn (show inputDir)
64
65 inputTree <- readInputTree inputDir 48 inputTree <- readInputTree inputDir
66 putStrLn "\nINPUT TREE"
67 putStrLn (show inputTree)
68 49
69 let resourceTree = buildResourceTree inputTree 50 let resourceTree = buildResourceTree inputTree
70 putStrLn "\nRESOURCE TREE" 51 putStrLn "\nRESOURCE TREE"
@@ -77,11 +58,11 @@ process inputDirPath outputDirPath =
77 -- (or recompile everything if the config file has changed!) 58 -- (or recompile everything if the config file has changed!)
78 -- execute in parallel 59 -- execute in parallel
79 60
80 cleanup resourceTree outputDirPath
81
82 -- TODO: execute (in parallel) the resource compilation strategy list 61 -- TODO: execute (in parallel) the resource compilation strategy list
83 -- need to find a good library for that 62 -- need to find a good library for that
84 63
64 cleanup resourceTree outputDirPath
65
85 buildGalleryTree resourceTree 66 buildGalleryTree resourceTree
86 & writeJSON (outputDirPath </> "index.json") 67 & writeJSON (outputDirPath </> "index.json")
87 68
@@ -95,7 +76,13 @@ process inputDirPath outputDirPath =
95 >>= return . outputDiff resourceTree . root 76 >>= return . outputDiff resourceTree . root
96 >>= return . sortBy (flip $ comparing length) -- nested files before dirs 77 >>= return . sortBy (flip $ comparing length) -- nested files before dirs
97 >>= return . map (localPath . (/>) outputDir) 78 >>= return . map (localPath . (/>) outputDir)
98 >>= mapM_ removePathForcibly 79 >>= mapM_ remove
80
81 remove :: FileName -> IO ()
82 remove path =
83 do
84 putStrLn $ "Removing: " ++ path
85 removePathForcibly path
99 86
100 writeJSON :: ToJSON a => FileName -> a -> IO () 87 writeJSON :: ToJSON a => FileName -> a -> IO ()
101 writeJSON path obj = 88 writeJSON path obj =