From aead07929e6ed13375b86539b1679a88993c9cf5 Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 26 Dec 2019 08:03:31 +0100 Subject: compiler: extract config and remove utils --- compiler/src/Config.hs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 compiler/src/Config.hs (limited to 'compiler/src/Config.hs') diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs new file mode 100644 index 0000000..6f04818 --- /dev/null +++ b/compiler/src/Config.hs @@ -0,0 +1,49 @@ +{-# LANGUAGE DuplicateRecordFields, DeriveGeneric, DeriveAnyClass #-} + +-- ldgallery - A static generator which turns a collection of tagged +-- pictures into a searchable web gallery. +-- +-- Copyright (C) 2019 Pacien TRAN-GIRARD +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU Affero General Public License as +-- published by the Free Software Foundation, either version 3 of the +-- License, or (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Affero General Public License for more details. +-- +-- You should have received a copy of the GNU Affero General Public License +-- along with this program. If not, see . + + +module Config + ( GalleryConfig(..) + , CompilerConfig(..) + , readConfig + ) where + +import GHC.Generics (Generic) +import Data.Aeson (ToJSON, FromJSON) +import qualified Data.Aeson as JSON + +import Files (FileName) +import Input (decodeYamlFile) + + +data CompilerConfig = CompilerConfig + { dummy :: Maybe String -- TODO + } deriving (Generic, FromJSON, Show) + +data GalleryConfig = GalleryConfig + { compiler :: CompilerConfig + , viewer :: JSON.Object + } deriving (Generic, FromJSON, Show) + +-- TODO: add compiler config keys and their default values + + +readConfig :: FileName -> IO GalleryConfig +readConfig = decodeYamlFile -- cgit v1.2.3 From eb7a652b2244ffa4dd5ba2440b7879127e7c6078 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 27 Dec 2019 10:08:19 +0100 Subject: compiler: implement resource processing but break directory cleanup --- compiler/src/Config.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'compiler/src/Config.hs') 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 @@ -{-# LANGUAGE DuplicateRecordFields, DeriveGeneric, DeriveAnyClass #-} - -- ldgallery - A static generator which turns a collection of tagged -- pictures into a searchable web gallery. -- @@ -18,6 +16,11 @@ -- You should have received a copy of the GNU Affero General Public License -- along with this program. If not, see . +{-# LANGUAGE + DuplicateRecordFields + , DeriveGeneric + , DeriveAnyClass +#-} module Config ( GalleryConfig(..) @@ -25,6 +28,7 @@ module Config , readConfig ) where + import GHC.Generics (Generic) import Data.Aeson (ToJSON, FromJSON) import qualified Data.Aeson as JSON -- cgit v1.2.3 From 63b06627f200f155f66ecdb6c5f41ab44808dd6b Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 27 Dec 2019 12:38:01 +0100 Subject: compiler: add compiler config keys --- compiler/src/Config.hs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'compiler/src/Config.hs') diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index f147bdd..fe981c3 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs @@ -20,6 +20,7 @@ DuplicateRecordFields , DeriveGeneric , DeriveAnyClass + , OverloadedStrings #-} module Config @@ -29,25 +30,31 @@ module Config ) where +import Data.Text (Text) import GHC.Generics (Generic) -import Data.Aeson (ToJSON, FromJSON) +import Data.Aeson (ToJSON, FromJSON, withObject, (.:?), (.!=)) import qualified Data.Aeson as JSON import Files (FileName) import Input (decodeYamlFile) +import Processors (Resolution(..)) data CompilerConfig = CompilerConfig - { dummy :: Maybe String -- TODO - } deriving (Generic, FromJSON, Show) + { thumbnailResolution :: Resolution + , pictureMaxResolution :: Maybe Resolution + } deriving (Generic, Show) + +instance FromJSON CompilerConfig where + parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig + <$> v .:? "thumbnailResolution" .!= (Resolution 400 400) + <*> v .:? "pictureMaxResolution" + data GalleryConfig = GalleryConfig { compiler :: CompilerConfig , viewer :: JSON.Object } deriving (Generic, FromJSON, Show) --- TODO: add compiler config keys and their default values - - readConfig :: FileName -> IO GalleryConfig readConfig = decodeYamlFile -- cgit v1.2.3 From 538996dc84b03eab1429ddd693334673b857c005 Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 28 Dec 2019 19:04:54 +0100 Subject: compiler: parameterise gallery name --- compiler/src/Config.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'compiler/src/Config.hs') diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index fe981c3..044a155 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs @@ -41,13 +41,15 @@ import Processors (Resolution(..)) data CompilerConfig = CompilerConfig - { thumbnailResolution :: Resolution + { galleryName :: String + , thumbnailResolution :: Resolution , pictureMaxResolution :: Maybe Resolution } deriving (Generic, Show) instance FromJSON CompilerConfig where parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig - <$> v .:? "thumbnailResolution" .!= (Resolution 400 400) + <$> v .:? "galleryName" .!= "Gallery" + <*> v .:? "thumbnailResolution" .!= (Resolution 400 400) <*> v .:? "pictureMaxResolution" -- cgit v1.2.3 From d0962ef2dea7e8a0c25ca8fdbc55fcbafeeb2f79 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 30 Dec 2019 23:18:49 +0100 Subject: compiler: refactor resource transformation pipeline --- compiler/src/Config.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compiler/src/Config.hs') diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index 044a155..c75ab01 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs @@ -37,7 +37,7 @@ import qualified Data.Aeson as JSON import Files (FileName) import Input (decodeYamlFile) -import Processors (Resolution(..)) +import Resource (Resolution(..)) data CompilerConfig = CompilerConfig -- cgit v1.2.3 From 7ef9f09c0f3be1cd5e1f38c9abc845abc9ed3639 Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 31 Dec 2019 01:39:23 +0100 Subject: compiler: add option to add implicit directory tags GitHub: closes #7 --- compiler/src/Config.hs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'compiler/src/Config.hs') diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index c75ab01..d025afd 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs @@ -42,6 +42,7 @@ import Resource (Resolution(..)) data CompilerConfig = CompilerConfig { galleryName :: String + , implicitDirectoryTag :: Bool , thumbnailResolution :: Resolution , pictureMaxResolution :: Maybe Resolution } deriving (Generic, Show) @@ -49,6 +50,7 @@ data CompilerConfig = CompilerConfig instance FromJSON CompilerConfig where parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig <$> v .:? "galleryName" .!= "Gallery" + <*> v .:? "implicitDirectoryTag" .!= False <*> v .:? "thumbnailResolution" .!= (Resolution 400 400) <*> v .:? "pictureMaxResolution" -- cgit v1.2.3 From 6691b14cf4e867a9018f38c174fa98f1ada19f82 Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 31 Dec 2019 08:38:15 +0100 Subject: compiler: add option to ignore files matching a regex GitHub: closes #10 --- compiler/src/Config.hs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'compiler/src/Config.hs') diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index d025afd..ca3259f 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs @@ -42,6 +42,7 @@ import Resource (Resolution(..)) data CompilerConfig = CompilerConfig { galleryName :: String + , ignoreFiles :: String , implicitDirectoryTag :: Bool , thumbnailResolution :: Resolution , pictureMaxResolution :: Maybe Resolution @@ -50,6 +51,7 @@ data CompilerConfig = CompilerConfig instance FromJSON CompilerConfig where parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig <$> v .:? "galleryName" .!= "Gallery" + <*> v .:? "ignoreFiles" .!= ".^" <*> v .:? "implicitDirectoryTag" .!= False <*> v .:? "thumbnailResolution" .!= (Resolution 400 400) <*> v .:? "pictureMaxResolution" -- cgit v1.2.3 From 1a0f4b17fc77c4b330c43185a15230e67116a3aa Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 5 Jan 2020 10:43:30 +0100 Subject: compiler: rename max thumbnail size option --- compiler/src/Config.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'compiler/src/Config.hs') diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index ca3259f..9bb2860 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs @@ -44,7 +44,7 @@ data CompilerConfig = CompilerConfig { galleryName :: String , ignoreFiles :: String , implicitDirectoryTag :: Bool - , thumbnailResolution :: Resolution + , thumbnailMaxResolution :: Resolution , pictureMaxResolution :: Maybe Resolution } deriving (Generic, Show) @@ -53,7 +53,7 @@ instance FromJSON CompilerConfig where <$> v .:? "galleryName" .!= "Gallery" <*> v .:? "ignoreFiles" .!= ".^" <*> v .:? "implicitDirectoryTag" .!= False - <*> v .:? "thumbnailResolution" .!= (Resolution 400 400) + <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 400) <*> v .:? "pictureMaxResolution" -- cgit v1.2.3 From 9dd271504160b624284dbc438cdc867b6ca0d0e7 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 5 Jan 2020 16:24:02 +0100 Subject: compiler: enable warnings and fix them GitHub: fixes #9 --- compiler/src/Config.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'compiler/src/Config.hs') diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index 9bb2860..c6d77af 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs @@ -1,7 +1,7 @@ -- ldgallery - A static generator which turns a collection of tagged -- pictures into a searchable web gallery. -- --- Copyright (C) 2019 Pacien TRAN-GIRARD +-- Copyright (C) 2019-2020 Pacien TRAN-GIRARD -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU Affero General Public License as @@ -30,9 +30,8 @@ module Config ) where -import Data.Text (Text) import GHC.Generics (Generic) -import Data.Aeson (ToJSON, FromJSON, withObject, (.:?), (.!=)) +import Data.Aeson (FromJSON, withObject, (.:?), (.!=)) import qualified Data.Aeson as JSON import Files (FileName) -- cgit v1.2.3 From ee222b40569b9f40c482dd9df518f6445c1c304d Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 5 Jan 2020 16:42:09 +0100 Subject: compiler: enable language extensions on whole project --- compiler/src/Config.hs | 7 ------- 1 file changed, 7 deletions(-) (limited to 'compiler/src/Config.hs') diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index c6d77af..b9434ba 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs @@ -16,13 +16,6 @@ -- You should have received a copy of the GNU Affero General Public License -- along with this program. If not, see . -{-# LANGUAGE - DuplicateRecordFields - , DeriveGeneric - , DeriveAnyClass - , OverloadedStrings -#-} - module Config ( GalleryConfig(..) , CompilerConfig(..) -- cgit v1.2.3 From 2ad60869c2e8d0846672ccb18b2de99c9cf33671 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 5 Jan 2020 19:24:50 +0100 Subject: compiler: add option to add tags from n parent directories GitHub: closes #15 --- compiler/src/Config.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'compiler/src/Config.hs') diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index b9434ba..20bc3bb 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs @@ -35,7 +35,7 @@ import Resource (Resolution(..)) data CompilerConfig = CompilerConfig { galleryName :: String , ignoreFiles :: String - , implicitDirectoryTag :: Bool + , tagsFromDirectories :: Int , thumbnailMaxResolution :: Resolution , pictureMaxResolution :: Maybe Resolution } deriving (Generic, Show) @@ -44,7 +44,7 @@ instance FromJSON CompilerConfig where parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig <$> v .:? "galleryName" .!= "Gallery" <*> v .:? "ignoreFiles" .!= ".^" - <*> v .:? "implicitDirectoryTag" .!= False + <*> v .:? "tagsFromDirectories" .!= 0 <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 400) <*> v .:? "pictureMaxResolution" -- cgit v1.2.3 From 1e3a0e39cb6cdc86a6ba6b570c72c44931cf1c3b Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 5 Jan 2020 20:40:41 +0100 Subject: compiler: replace file filter with inclusino and exclusion glob lists GitHub: closes #16 --- compiler/src/Config.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'compiler/src/Config.hs') diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index 20bc3bb..53333a5 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs @@ -34,7 +34,8 @@ import Resource (Resolution(..)) data CompilerConfig = CompilerConfig { galleryName :: String - , ignoreFiles :: String + , includeFiles :: [String] + , excludeFiles :: [String] , tagsFromDirectories :: Int , thumbnailMaxResolution :: Resolution , pictureMaxResolution :: Maybe Resolution @@ -43,7 +44,8 @@ data CompilerConfig = CompilerConfig instance FromJSON CompilerConfig where parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig <$> v .:? "galleryName" .!= "Gallery" - <*> v .:? "ignoreFiles" .!= ".^" + <*> v .:? "includeFiles" .!= ["*"] + <*> v .:? "excludeFiles" .!= [] <*> v .:? "tagsFromDirectories" .!= 0 <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 400) <*> v .:? "pictureMaxResolution" -- cgit v1.2.3