diff options
-rw-r--r-- | compiler/app/Main.hs | 28 | ||||
-rw-r--r-- | compiler/package.yaml | 5 | ||||
-rw-r--r-- | compiler/src/Compiler.hs (renamed from compiler/src/Lib.hs) | 64 | ||||
-rw-r--r-- | compiler/src/Config.hs | 8 | ||||
-rw-r--r-- | compiler/src/Files.hs | 31 | ||||
-rw-r--r-- | compiler/src/Gallery.hs | 15 | ||||
-rw-r--r-- | compiler/src/Input.hs | 12 | ||||
-rw-r--r-- | compiler/src/Processors.hs | 221 | ||||
-rw-r--r-- | compiler/src/Resource.hs | 65 | ||||
-rw-r--r-- | example/Glacier 3000/thumbnail.jpg | bin | 0 -> 457873 bytes |
10 files changed, 369 insertions, 80 deletions
diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index ac9b441..2511998 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs | |||
@@ -1,6 +1,30 @@ | |||
1 | -- ldgallery - A static generator which turns a collection of tagged | ||
2 | -- pictures into a searchable web gallery. | ||
3 | -- | ||
4 | -- Copyright (C) 2019 Pacien TRAN-GIRARD | ||
5 | -- | ||
6 | -- This program is free software: you can redistribute it and/or modify | ||
7 | -- it under the terms of the GNU Affero General Public License as | ||
8 | -- published by the Free Software Foundation, either version 3 of the | ||
9 | -- License, or (at your option) any later version. | ||
10 | -- | ||
11 | -- This program is distributed in the hope that it will be useful, | ||
12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | -- GNU Affero General Public License for more details. | ||
15 | -- | ||
16 | -- You should have received a copy of the GNU Affero General Public License | ||
17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
18 | |||
19 | {-# LANGUAGE | ||
20 | DuplicateRecordFields | ||
21 | , DeriveGeneric | ||
22 | , DeriveAnyClass | ||
23 | #-} | ||
24 | |||
1 | module Main where | 25 | module Main where |
2 | 26 | ||
3 | import Lib | 27 | import Compiler |
4 | 28 | ||
5 | main :: IO () | 29 | main :: IO () |
6 | main = testRun | 30 | main = compileGallery "../../example" "../../out" |
diff --git a/compiler/package.yaml b/compiler/package.yaml index 9266466..85740ab 100644 --- a/compiler/package.yaml +++ b/compiler/package.yaml | |||
@@ -16,7 +16,6 @@ description: Please see the README on GitHub at <https://github.com/paci | |||
16 | 16 | ||
17 | dependencies: | 17 | dependencies: |
18 | - base >= 4.7 && < 5 | 18 | - base >= 4.7 && < 5 |
19 | #- text | ||
20 | - containers | 19 | - containers |
21 | - filepath | 20 | - filepath |
22 | - directory | 21 | - directory |
@@ -24,8 +23,8 @@ dependencies: | |||
24 | - yaml | 23 | - yaml |
25 | #- optparse-applicative | 24 | #- optparse-applicative |
26 | #- cmdargs | 25 | #- cmdargs |
27 | #- JuicyPixels | 26 | - JuicyPixels |
28 | #- JuicyPixels-extra | 27 | - JuicyPixels-extra |
29 | 28 | ||
30 | library: | 29 | library: |
31 | source-dirs: src | 30 | source-dirs: src |
diff --git a/compiler/src/Lib.hs b/compiler/src/Compiler.hs index b2bbe15..9767394 100644 --- a/compiler/src/Lib.hs +++ b/compiler/src/Compiler.hs | |||
@@ -1,5 +1,3 @@ | |||
1 | {-# LANGUAGE DuplicateRecordFields, DeriveGeneric, DeriveAnyClass #-} | ||
2 | |||
3 | -- ldgallery - A static generator which turns a collection of tagged | 1 | -- ldgallery - A static generator which turns a collection of tagged |
4 | -- pictures into a searchable web gallery. | 2 | -- pictures into a searchable web gallery. |
5 | -- | 3 | -- |
@@ -18,12 +16,18 @@ | |||
18 | -- You should have received a copy of the GNU Affero General Public License | 16 | -- You should have received a copy of the GNU Affero General Public License |
19 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. | 17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | 18 | ||
19 | {-# LANGUAGE | ||
20 | DuplicateRecordFields | ||
21 | , DeriveGeneric | ||
22 | , DeriveAnyClass | ||
23 | #-} | ||
21 | 24 | ||
22 | module Lib | 25 | module Compiler |
23 | ( testRun | 26 | ( compileGallery |
24 | ) where | 27 | ) where |
25 | 28 | ||
26 | 29 | ||
30 | import Control.Monad | ||
27 | import Data.Function ((&)) | 31 | import Data.Function ((&)) |
28 | import Data.Ord (comparing) | 32 | import Data.Ord (comparing) |
29 | import Data.List (sortBy, length) | 33 | import Data.List (sortBy, length) |
@@ -34,42 +38,49 @@ import Data.Aeson (ToJSON) | |||
34 | import qualified Data.Aeson as JSON | 38 | import qualified Data.Aeson as JSON |
35 | 39 | ||
36 | import Config | 40 | import Config |
37 | import Files (FileName, readDirectory, localPath, flattenDir, root, (/>)) | 41 | import Files (FileName, readDirectory, localPath, isHidden, nodeName, filterDir, flattenDir, root, (/>), ensureParentDir) |
38 | import Input (decodeYamlFile, readInputTree) | 42 | import Input (decodeYamlFile, readInputTree) |
39 | import Resource (ResourceTree, buildResourceTree, outputDiff) | 43 | import Resource (ResourceTree, buildResourceTree, outputDiff) |
40 | import Gallery (buildGalleryTree) | 44 | import Gallery (buildGalleryTree) |
45 | import Processors | ||
46 | |||
47 | |||
48 | itemsDir :: String | ||
49 | itemsDir = "items" | ||
41 | 50 | ||
51 | thumbnailsDir :: String | ||
52 | thumbnailsDir = "thumbnails" | ||
42 | 53 | ||
43 | process :: FilePath -> FilePath -> IO () | 54 | |
44 | process inputDirPath outputDirPath = | 55 | compileGallery :: FilePath -> FilePath -> IO () |
56 | compileGallery inputDirPath outputDirPath = | ||
45 | do | 57 | do |
46 | config <- readConfig (inputDirPath </> "gallery.yaml") | 58 | config <- readConfig (inputDirPath </> "gallery.yaml") |
47 | inputDir <- readDirectory inputDirPath | 59 | inputDir <- readDirectory inputDirPath |
48 | inputTree <- readInputTree inputDir | ||
49 | 60 | ||
50 | let resourceTree = buildResourceTree inputTree | 61 | let isGalleryFile = \n -> nodeName n == "gallery.yaml" |
51 | putStrLn "\nRESOURCE TREE" | 62 | let galleryTree = filterDir (liftM2 (&&) (not . isGalleryFile) (not . isHidden)) inputDir |
52 | putStrLn (show resourceTree) | ||
53 | 63 | ||
54 | -- TODO: make buildResourceTree build a resource compilation strategy | 64 | inputTree <- readInputTree galleryTree |
55 | -- (need to know the settings) | ||
56 | -- flatten the tree of resources and their strategies | ||
57 | -- filter resources that are already up to date | ||
58 | -- (or recompile everything if the config file has changed!) | ||
59 | -- execute in parallel | ||
60 | 65 | ||
61 | -- TODO: execute (in parallel) the resource compilation strategy list | 66 | let dirProc = dirFileProcessor inputDirPath outputDirPath itemsDir |
62 | -- need to find a good library for that | 67 | let itemProc = itemFileProcessor Nothing skipCached inputDirPath outputDirPath itemsDir |
68 | let thumbnailProc = thumbnailFileProcessor (Resolution 150 50) skipCached inputDirPath outputDirPath thumbnailsDir | ||
69 | resourceTree <- buildResourceTree dirProc itemProc thumbnailProc inputTree | ||
63 | 70 | ||
64 | cleanup resourceTree outputDirPath | 71 | putStrLn "\nRESOURCE TREE" |
72 | putStrLn (show resourceTree) | ||
73 | |||
74 | --cleanup resourceTree outputDirPath | ||
65 | 75 | ||
66 | buildGalleryTree resourceTree | 76 | buildGalleryTree resourceTree |
67 | & writeJSON (outputDirPath </> "index.json") | 77 | & ensureParentDir JSON.encodeFile (outputDirPath </> "index.json") |
68 | 78 | ||
69 | viewer config | 79 | viewer config |
70 | & writeJSON (outputDirPath </> "viewer.json") | 80 | & ensureParentDir JSON.encodeFile (outputDirPath </> "viewer.json") |
71 | 81 | ||
72 | where | 82 | where |
83 | -- TODO: delete all files, then only non-empty dirs | ||
73 | cleanup :: ResourceTree -> FileName -> IO () | 84 | cleanup :: ResourceTree -> FileName -> IO () |
74 | cleanup resourceTree outputDir = | 85 | cleanup resourceTree outputDir = |
75 | readDirectory outputDir | 86 | readDirectory outputDir |
@@ -83,12 +94,3 @@ process inputDirPath outputDirPath = | |||
83 | do | 94 | do |
84 | putStrLn $ "Removing: " ++ path | 95 | putStrLn $ "Removing: " ++ path |
85 | removePathForcibly path | 96 | removePathForcibly path |
86 | |||
87 | writeJSON :: ToJSON a => FileName -> a -> IO () | ||
88 | writeJSON path obj = | ||
89 | createDirectoryIfMissing True (dropFileName path) | ||
90 | >> JSON.encodeFile path obj | ||
91 | |||
92 | |||
93 | testRun :: IO () | ||
94 | testRun = process "../../example" "../../out" | ||
diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index 6f04818..f147bdd 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs | |||
@@ -1,5 +1,3 @@ | |||
1 | {-# LANGUAGE DuplicateRecordFields, DeriveGeneric, DeriveAnyClass #-} | ||
2 | |||
3 | -- ldgallery - A static generator which turns a collection of tagged | 1 | -- ldgallery - A static generator which turns a collection of tagged |
4 | -- pictures into a searchable web gallery. | 2 | -- pictures into a searchable web gallery. |
5 | -- | 3 | -- |
@@ -18,6 +16,11 @@ | |||
18 | -- You should have received a copy of the GNU Affero General Public License | 16 | -- You should have received a copy of the GNU Affero General Public License |
19 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. | 17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | 18 | ||
19 | {-# LANGUAGE | ||
20 | DuplicateRecordFields | ||
21 | , DeriveGeneric | ||
22 | , DeriveAnyClass | ||
23 | #-} | ||
21 | 24 | ||
22 | module Config | 25 | module Config |
23 | ( GalleryConfig(..) | 26 | ( GalleryConfig(..) |
@@ -25,6 +28,7 @@ module Config | |||
25 | , readConfig | 28 | , readConfig |
26 | ) where | 29 | ) where |
27 | 30 | ||
31 | |||
28 | import GHC.Generics (Generic) | 32 | import GHC.Generics (Generic) |
29 | import Data.Aeson (ToJSON, FromJSON) | 33 | import Data.Aeson (ToJSON, FromJSON) |
30 | import qualified Data.Aeson as JSON | 34 | import qualified Data.Aeson as JSON |
diff --git a/compiler/src/Files.hs b/compiler/src/Files.hs index 77a8c5b..0392efe 100644 --- a/compiler/src/Files.hs +++ b/compiler/src/Files.hs | |||
@@ -1,5 +1,3 @@ | |||
1 | {-# LANGUAGE DuplicateRecordFields, DeriveGeneric #-} | ||
2 | |||
3 | -- ldgallery - A static generator which turns a collection of tagged | 1 | -- ldgallery - A static generator which turns a collection of tagged |
4 | -- pictures into a searchable web gallery. | 2 | -- pictures into a searchable web gallery. |
5 | -- | 3 | -- |
@@ -18,12 +16,17 @@ | |||
18 | -- You should have received a copy of the GNU Affero General Public License | 16 | -- You should have received a copy of the GNU Affero General Public License |
19 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. | 17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | 18 | ||
19 | {-# LANGUAGE | ||
20 | DuplicateRecordFields | ||
21 | , DeriveGeneric | ||