From 987eb81cb5d98262299c7917d752c54907cbbc33 Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 23 Jan 2020 22:36:21 +0100 Subject: compiler: add directory incl and excl glob settings GitHub: closes #41 --- compiler/src/Compiler.hs | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'compiler/src/Compiler.hs') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index a347433..13e9232 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -71,30 +71,35 @@ writeJSON outputPath object = ensureParentDir JSON.encodeFile outputPath object -galleryDirFilter :: ([Glob.Pattern], [Glob.Pattern]) -> FSNode -> Bool -galleryDirFilter (inclusionPatterns, exclusionPatterns) = +galleryDirFilter :: CompilerConfig -> FSNode -> Bool +galleryDirFilter config = (not . isHidden) - &&& (matchName True $ anyPattern inclusionPatterns) - &&& (not . isConfigFile) + &&& (not . matchesFile (== galleryConf)) &&& (not . containsOutputGallery) - &&& (not . (matchName False $ anyPattern exclusionPatterns)) + &&& ((matchesDir $ anyPattern $ includedDirectories config) ||| + (matchesFile $ anyPattern $ includedFiles config)) + &&& (not . ((matchesDir $ anyPattern $ excludedDirectories config) ||| + (matchesFile $ anyPattern $ excludedFiles config))) where (&&&) = liftM2 (&&) (|||) = liftM2 (||) - matchName :: Bool -> (FileName -> Bool) -> FSNode -> Bool - matchName matchDir _ Dir{} = matchDir - matchName _ cond file@File{} = maybe False cond $ nodeName file + matchesDir :: (FileName -> Bool) -> FSNode -> Bool + matchesDir cond dir@Dir{} = maybe False cond $ nodeName dir + matchesDir _ File{} = False - anyPattern :: [Glob.Pattern] -> FileName -> Bool - anyPattern patterns filename = any (flip Glob.match filename) patterns + matchesFile :: (FileName -> Bool) -> FSNode -> Bool + matchesFile cond file@File{} = maybe False cond $ nodeName file + matchesFile _ Dir{} = False - isConfigFile = matchName False (== galleryConf) - isGalleryIndex = matchName False (== indexFile) - isViewerIndex = matchName False (== viewerMainFile) + anyPattern :: [String] -> FileName -> Bool + anyPattern patterns filename = any (flip Glob.match filename) (map Glob.compile patterns) + + containsOutputGallery :: FSNode -> Bool containsOutputGallery File{} = False - containsOutputGallery Dir{items} = any (isGalleryIndex ||| isViewerIndex) items + containsOutputGallery Dir{items} = + any (matchesFile (== indexFile) ||| matchesFile (== viewerMainFile)) items compileGallery :: FilePath -> FilePath -> Bool -> IO () @@ -104,9 +109,7 @@ compileGallery inputDirPath outputDirPath rebuildAll = let config = compiler fullConfig inputDir <- readDirectory inputDirPath - let inclusionPatterns = map Glob.compile $ includeFiles config - let exclusionPatterns = map Glob.compile $ excludeFiles config - let sourceFilter = galleryDirFilter (inclusionPatterns, exclusionPatterns) + let sourceFilter = galleryDirFilter config let sourceTree = filterDir sourceFilter inputDir inputTree <- readInputTree sourceTree -- cgit v1.2.3 From cf91102432b1196b8f3c1fa388b3963948ad49a6 Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 23 Jan 2020 23:16:07 +0100 Subject: compiler: add jpeg export quality setting GitHub: closes #2 --- compiler/src/Compiler.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'compiler/src/Compiler.hs') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index 13e9232..aca96bc 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -114,8 +114,8 @@ compileGallery inputDirPath outputDirPath rebuildAll = inputTree <- readInputTree sourceTree let cache = if rebuildAll then skipCached else withCached - let itemProc = itemProcessor (pictureMaxResolution config) cache - let thumbnailProc = thumbnailProcessor (thumbnailMaxResolution config) cache + let itemProc = itemProcessor config cache + let thumbnailProc = thumbnailProcessor config cache let galleryBuilder = buildGalleryTree itemProc thumbnailProc (tagsFromDirectories config) resources <- galleryBuilder (galleryName config) inputTree @@ -128,7 +128,11 @@ compileGallery inputDirPath outputDirPath rebuildAll = outputIndex = outputDirPath indexFile outputViewerConf = outputDirPath viewerConfFile - itemProcessor maxRes cache = - itemFileProcessor maxRes cache inputDirPath outputDirPath itemsDir - thumbnailProcessor thumbRes cache = - thumbnailFileProcessor thumbRes cache inputDirPath outputDirPath thumbnailsDir + itemProcessor config cache = + itemFileProcessor + (pictureMaxResolution config) (jpegExportQuality config) cache + inputDirPath outputDirPath itemsDir + thumbnailProcessor config cache = + thumbnailFileProcessor + (thumbnailMaxResolution config) (jpegExportQuality config) cache + inputDirPath outputDirPath thumbnailsDir -- cgit v1.2.3 From c05cbe525ad44273cc1b9b58549af757f549dcb7 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 27 Jan 2020 14:29:47 +0100 Subject: compiler: switch to imagemagick Use ImageMagick to resize images instead of JuicyPixels, using the superior Lanczos resampling and cutting memory usage. This requires ImageMagick to be installed on the host system and the `magick` executable to be present in the PATH. GitHub: closes #49 --- compiler/src/Compiler.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'compiler/src/Compiler.hs') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index aca96bc..27598b7 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -130,9 +130,9 @@ compileGallery inputDirPath outputDirPath rebuildAll = itemProcessor config cache = itemFileProcessor - (pictureMaxResolution config) (jpegExportQuality config) cache + (pictureMaxResolution config) cache inputDirPath outputDirPath itemsDir thumbnailProcessor config cache = thumbnailFileProcessor - (thumbnailMaxResolution config) (jpegExportQuality config) cache + (thumbnailMaxResolution config) cache inputDirPath outputDirPath thumbnailsDir -- cgit v1.2.3 From 15c806adec22239096a910b92b49fcfb964815bd Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 30 Jan 2020 17:01:15 +0100 Subject: compiler: add flag for output dir cleanup Making it explicit. GitHub: closes #62 --- compiler/src/Compiler.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'compiler/src/Compiler.hs') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index 27598b7..fc40a76 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -102,8 +102,8 @@ galleryDirFilter config = any (matchesFile (== indexFile) ||| matchesFile (== viewerMainFile)) items -compileGallery :: FilePath -> FilePath -> Bool -> IO () -compileGallery inputDirPath outputDirPath rebuildAll = +compileGallery :: FilePath -> FilePath -> Bool -> Bool -> IO () +compileGallery inputDirPath outputDirPath rebuildAll cleanOutput = do fullConfig <- readConfig inputGalleryConf let config = compiler fullConfig @@ -119,7 +119,11 @@ compileGallery inputDirPath outputDirPath rebuildAll = let galleryBuilder = buildGalleryTree itemProc thumbnailProc (tagsFromDirectories config) resources <- galleryBuilder (galleryName config) inputTree - galleryCleanupResourceDir resources outputDirPath + if cleanOutput then + galleryCleanupResourceDir resources outputDirPath + else + return () + writeJSON outputIndex resources writeJSON outputViewerConf $ viewer fullConfig -- cgit v1.2.3 From 2157b66f3ea43137391939992cac4dc901a4ac4e Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Fri, 31 Jan 2020 02:15:26 +0100 Subject: compiler: output viewer config.json Write a file at the root of the viewer directory with some info about the gallery root path and generation date time. --- compiler/src/Compiler.hs | 1 + 1 file changed, 1 insertion(+) (limited to 'compiler/src/Compiler.hs') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index fc40a76..8819ffc 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -18,6 +18,7 @@ module Compiler ( compileGallery + , writeJSON ) where -- cgit v1.2.3 From 4fde03c7654dcdad11a8c91ba2bcbb2706695e11 Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 30 Jan 2020 16:03:54 +0100 Subject: compiler: properly exclude out directory Use canonical paths to exclude the output directory if it is located inside the input directory instead of guessing based on special files. GitHub: closes #54 --- compiler/src/Compiler.hs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'compiler/src/Compiler.hs') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index 8819ffc..d392f74 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -26,6 +26,7 @@ import Control.Monad (liftM2) import Data.List (any) import System.FilePath (()) import qualified System.FilePath.Glob as Glob +import System.Directory (canonicalizePath) import Data.Aeson (ToJSON) import qualified Data.Aeson as JSON @@ -52,9 +53,6 @@ galleryConf = "gallery.yaml" indexFile :: String indexFile = "index.json" -viewerMainFile :: String -viewerMainFile = "index.html" - viewerConfFile :: String viewerConfFile = "viewer.json" @@ -72,11 +70,11 @@ writeJSON outputPath object = ensureParentDir JSON.encodeFile outputPath object -galleryDirFilter :: CompilerConfig -> FSNode -> Bool -galleryDirFilter config = +galleryDirFilter :: CompilerConfig -> FilePath -> FSNode -> Bool +galleryDirFilter config outputDir = (not . isHidden) + &&& (not . isOutputGallery) &&& (not . matchesFile (== galleryConf)) - &&& (not . containsOutputGallery) &&& ((matchesDir $ anyPattern $ includedDirectories config) ||| (matchesFile $ anyPattern $ includedFiles config)) &&& (not . ((matchesDir $ anyPattern $ excludedDirectories config) ||| @@ -97,10 +95,9 @@ galleryDirFilter config = anyPattern :: [String] -> FileName -> Bool anyPattern patterns filename = any (flip Glob.match filename) (map Glob.compile patterns) - containsOutputGallery :: FSNode -> Bool - containsOutputGallery File{} = False - containsOutputGallery Dir{items} = - any (matchesFile (== indexFile) ||| matchesFile (== viewerMainFile)) items + isOutputGallery :: FSNode -> Bool + isOutputGallery Dir{canonicalPath} = canonicalPath == outputDir + isOutputGallery File{} = False compileGallery :: FilePath -> FilePath -> Bool -> Bool -> IO () @@ -110,7 +107,8 @@ compileGallery inputDirPath outputDirPath rebuildAll cleanOutput = let config = compiler fullConfig inputDir <- readDirectory inputDirPath - let sourceFilter = galleryDirFilter config + canonicalOutPath <- canonicalizePath outputDirPath + let sourceFilter = galleryDirFilter config canonicalOutPath let sourceTree = filterDir sourceFilter inputDir inputTree <- readInputTree sourceTree -- cgit v1.2.3 From c7c872291c2b053afc2c27f999f33b2cfb6c23f1 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 3 Feb 2020 14:27:33 +0100 Subject: compiler: fix viewer output directory exclusion GitHub: closes #87 --- compiler/src/Compiler.hs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'compiler/src/Compiler.hs') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index d392f74..adc4a5f 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -70,10 +70,10 @@ writeJSON outputPath object = ensureParentDir JSON.encodeFile outputPath object -galleryDirFilter :: CompilerConfig -> FilePath -> FSNode -> Bool -galleryDirFilter config outputDir = +galleryDirFilter :: CompilerConfig -> [FilePath] -> FSNode -> Bool +galleryDirFilter config excludedCanonicalDirs = (not . isHidden) - &&& (not . isOutputGallery) + &&& (not . isExcludedDir) &&& (not . matchesFile (== galleryConf)) &&& ((matchesDir $ anyPattern $ includedDirectories config) ||| (matchesFile $ anyPattern $ includedFiles config)) @@ -95,20 +95,20 @@ galleryDirFilter config outputDir = anyPattern :: [String] -> FileName -> Bool anyPattern patterns filename = any (flip Glob.match filename) (map Glob.compile patterns) - isOutputGallery :: FSNode -> Bool - isOutputGallery Dir{canonicalPath} = canonicalPath == outputDir - isOutputGallery File{} = False + isExcludedDir :: FSNode -> Bool + isExcludedDir Dir{canonicalPath} = any (canonicalPath ==) excludedCanonicalDirs + isExcludedDir File{} = False -compileGallery :: FilePath -> FilePath -> Bool -> Bool -> IO () -compileGallery inputDirPath outputDirPath rebuildAll cleanOutput = +compileGallery :: FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () +compileGallery inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = do fullConfig <- readConfig inputGalleryConf let config = compiler fullConfig inputDir <- readDirectory inputDirPath - canonicalOutPath <- canonicalizePath outputDirPath - let sourceFilter = galleryDirFilter config canonicalOutPath + excludedCanonicalDirs <- mapM canonicalizePath excludedDirs + let sourceFilter = galleryDirFilter config excludedCanonicalDirs let sourceTree = filterDir sourceFilter inputDir inputTree <- readInputTree sourceTree -- cgit v1.2.3 From b757ee814c01c83b17b495c4805fcc70d7e08c89 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 3 Feb 2020 15:08:46 +0100 Subject: compiler: simplify checks --- compiler/src/Compiler.hs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'compiler/src/Compiler.hs') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index adc4a5f..2a0dccc 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -22,7 +22,7 @@ module Compiler ) where -import Control.Monad (liftM2) +import Control.Monad (liftM2, when) import Data.List (any) import System.FilePath (()) import qualified System.FilePath.Glob as Glob @@ -118,11 +118,7 @@ compileGallery inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = let galleryBuilder = buildGalleryTree itemProc thumbnailProc (tagsFromDirectories config) resources <- galleryBuilder (galleryName config) inputTree - if cleanOutput then - galleryCleanupResourceDir resources outputDirPath - else - return () - + when cleanOutput $ galleryCleanupResourceDir resources outputDirPath writeJSON outputIndex resources writeJSON outputViewerConf $ viewer fullConfig -- cgit v1.2.3 From 395a76bc4193c0c7182f87778458a68d0079e836 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 14 Feb 2020 15:39:56 +0100 Subject: compiler: metadata sidecar for whole directories GitHub: closes #3 --- compiler/src/Compiler.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compiler/src/Compiler.hs') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index 2a0dccc..bfefa63 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -116,7 +116,7 @@ compileGallery inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = let itemProc = itemProcessor config cache let thumbnailProc = thumbnailProcessor config cache let galleryBuilder = buildGalleryTree itemProc thumbnailProc (tagsFromDirectories config) - resources <- galleryBuilder (galleryName config) inputTree + resources <- galleryBuilder inputTree when cleanOutput $ galleryCleanupResourceDir resources outputDirPath writeJSON outputIndex resources -- cgit v1.2.3 From ce0b7ec230703d239b3d77e09352c0b1d515d8f5 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 21 Feb 2020 15:39:01 +0100 Subject: compiler: add gallery config file CLI argument GitHub: closes #136 --- compiler/src/Compiler.hs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'compiler/src/Compiler.hs') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index bfefa63..bb0ee97 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -47,8 +47,8 @@ import Processors , skipCached, withCached ) -galleryConf :: String -galleryConf = "gallery.yaml" +defaultGalleryConf :: String +defaultGalleryConf = "gallery.yaml" indexFile :: String indexFile = "index.json" @@ -74,7 +74,6 @@ galleryDirFilter :: CompilerConfig -> [FilePath] -> FSNode -> Bool galleryDirFilter config excludedCanonicalDirs = (not . isHidden) &&& (not . isExcludedDir) - &&& (not . matchesFile (== galleryConf)) &&& ((matchesDir $ anyPattern $ includedDirectories config) ||| (matchesFile $ anyPattern $ includedFiles config)) &&& (not . ((matchesDir $ anyPattern $ excludedDirectories config) ||| @@ -100,10 +99,10 @@ galleryDirFilter config excludedCanonicalDirs = isExcludedDir File{} = False -compileGallery :: FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () -compileGallery inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = +compileGallery :: FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () +compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = do - fullConfig <- readConfig inputGalleryConf + fullConfig <- readConfig $ inputGalleryConf configPath let config = compiler fullConfig inputDir <- readDirectory inputDirPath @@ -123,7 +122,10 @@ compileGallery inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = writeJSON outputViewerConf $ viewer fullConfig where - inputGalleryConf = inputDirPath galleryConf + inputGalleryConf :: FilePath -> FilePath + inputGalleryConf "" = inputDirPath defaultGalleryConf + inputGalleryConf file = file + outputIndex = outputDirPath indexFile outputViewerConf = outputDirPath viewerConfFile -- cgit v1.2.3 From e42f4e864bac21ed3b19d1869df2cdd4f8c3433c Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 22 Feb 2020 14:53:03 +0100 Subject: compiler: flatten gallery config GitHub: closes #129 --- compiler/src/Compiler.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'compiler/src/Compiler.hs') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index bb0ee97..73ac8a4 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -70,7 +70,7 @@ writeJSON outputPath object = ensureParentDir JSON.encodeFile outputPath object -galleryDirFilter :: CompilerConfig -> [FilePath] -> FSNode -> Bool +galleryDirFilter :: GalleryConfig -> [FilePath] -> FSNode -> Bool galleryDirFilter config excludedCanonicalDirs = (not . isHidden) &&& (not . isExcludedDir) @@ -102,8 +102,7 @@ galleryDirFilter config excludedCanonicalDirs = compileGallery :: FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = do - fullConfig <- readConfig $ inputGalleryConf configPath - let config = compiler fullConfig + config <- readConfig $ inputGalleryConf configPath inputDir <- readDirectory inputDirPath excludedCanonicalDirs <- mapM canonicalizePath excludedDirs @@ -119,7 +118,7 @@ compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cle when cleanOutput $ galleryCleanupResourceDir resources outputDirPath writeJSON outputIndex resources - writeJSON outputViewerConf $ viewer fullConfig + writeJSON outputViewerConf $ viewerConfig config where inputGalleryConf :: FilePath -> FilePath -- cgit v1.2.3 From 2766f5f9a491c5f7ebf1eeac1c970daec3656be2 Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 25 Feb 2020 16:03:00 +0100 Subject: transverse: combine item tree and gallery-wide properties GitHub: closes #142 --- compiler/src/Compiler.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'compiler/src/Compiler.hs') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index 73ac8a4..2970102 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -22,6 +22,7 @@ module Compiler ) where +import GHC.Generics (Generic) import Control.Monad (liftM2, when) import Data.List (any) import System.FilePath (()) @@ -33,7 +34,7 @@ import qualified Data.Aeson as JSON import Config import Input (readInputTree) -import Resource (buildGalleryTree, galleryCleanupResourceDir) +import Resource (GalleryItem, buildGalleryTree, galleryCleanupResourceDir) import Files ( FileName , FSNode(..) @@ -53,9 +54,6 @@ defaultGalleryConf = "gallery.yaml" indexFile :: String indexFile = "index.json" -viewerConfFile :: String -viewerConfFile = "viewer.json" - itemsDir :: String itemsDir = "items" @@ -63,6 +61,12 @@ thumbnailsDir :: String thumbnailsDir = "thumbnails" +data GalleryIndex = GalleryIndex + { properties :: ViewerConfig + , tree :: GalleryItem + } deriving (Generic, Show, ToJSON) + + writeJSON :: ToJSON a => FileName -> a -> IO () writeJSON outputPath object = do @@ -117,17 +121,13 @@ compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cle resources <- galleryBuilder inputTree when cleanOutput $ galleryCleanupResourceDir resources outputDirPath - writeJSON outputIndex resources - writeJSON outputViewerConf $ viewerConfig config + writeJSON (outputDirPath indexFile) $ GalleryIndex (viewerConfig config) resources where inputGalleryConf :: FilePath -> FilePath inputGalleryConf "" = inputDirPath defaultGalleryConf inputGalleryConf file = file - outputIndex = outputDirPath indexFile - outputViewerConf = outputDirPath viewerConfFile - itemProcessor config cache = itemFileProcessor (pictureMaxResolution config) cache -- cgit v1.2.3 From 74e4a83ac7511086f45d2fa9880b7ae5728020bd Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 25 Feb 2020 20:19:54 +0100 Subject: compiler: add cli arg for output gallery index GitHub: closes #143 --- compiler/src/Compiler.hs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'compiler/src/Compiler.hs') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index 2970102..51f5065 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -51,8 +51,8 @@ import Processors defaultGalleryConf :: String defaultGalleryConf = "gallery.yaml" -indexFile :: String -indexFile = "index.json" +defaultIndexFile :: String +defaultIndexFile = "index.json" itemsDir :: String itemsDir = "items" @@ -103,8 +103,8 @@ galleryDirFilter config excludedCanonicalDirs = isExcludedDir File{} = False -compileGallery :: FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () -compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cleanOutput = +compileGallery :: FilePath -> FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () +compileGallery configPath inputDirPath outputDirPath outputIndexPath excludedDirs rebuildAll cleanOutput = do config <- readConfig $ inputGalleryConf configPath @@ -121,13 +121,17 @@ compileGallery configPath inputDirPath outputDirPath excludedDirs rebuildAll cle resources <- galleryBuilder inputTree when cleanOutput $ galleryCleanupResourceDir resources outputDirPath - writeJSON (outputDirPath indexFile) $ GalleryIndex (viewerConfig config) resources + writeJSON (outputGalleryIndex outputIndexPath) $ GalleryIndex (viewerConfig config) resources where inputGalleryConf :: FilePath -> FilePath inputGalleryConf "" = inputDirPath defaultGalleryConf inputGalleryConf file = file + outputGalleryIndex :: FilePath -> FilePath + outputGalleryIndex "" = outputDirPath defaultIndexFile + outputGalleryIndex file = file + itemProcessor config cache = itemFileProcessor (pictureMaxResolution config) cache -- cgit v1.2.3 From f09e9d9fa29284bd9ae872efe5ba1d526e349011 Mon Sep 17 00:00:00 2001 From: pacien Date: Wed, 26 Feb 2020 22:13:00 +0100 Subject: compiler: add tag inclusion and exclusion globs GitHub: closes #30 --- compiler/src/Compiler.hs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'compiler/src/Compiler.hs') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index 51f5065..fa405a2 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -25,6 +25,7 @@ module Compiler import GHC.Generics (Generic) import Control.Monad (liftM2, when) import Data.List (any) +import Data.Maybe (fromMaybe) import System.FilePath (()) import qualified System.FilePath.Glob as Glob import System.Directory (canonicalizePath) @@ -33,7 +34,7 @@ import Data.Aeson (ToJSON) import qualified Data.Aeson as JSON import Config -import Input (readInputTree) +import Input (InputTree, readInputTree, filterInputTree, sidecar, tags) import Resource (GalleryItem, buildGalleryTree, galleryCleanupResourceDir) import Files ( FileName @@ -74,6 +75,15 @@ writeJSON outputPath object = ensureParentDir JSON.encodeFile outputPath object +(&&&) :: (a -> Bool) -> (a -> Bool) -> a -> Bool +(&&&) = liftM2 (&&) + +(|||) :: (a -> Bool) -> (a -> Bool) -> a -> Bool +(|||) = liftM2 (||) + +anyPattern :: [String] -> String -> Bool +anyPattern patterns string = any (flip Glob.match string) (map Glob.compile patterns) + galleryDirFilter :: GalleryConfig -> [FilePath] -> FSNode -> Bool galleryDirFilter config excludedCanonicalDirs = (not . isHidden) @@ -84,9 +94,6 @@ galleryDirFilter config excludedCanonicalDirs = (matchesFile $ anyPattern $ excludedFiles config))) where - (&&&) = liftM2 (&&) - (|||) = liftM2 (||) - matchesDir :: (FileName -> Bool) -> FSNode -> Bool matchesDir cond dir@Dir{} = maybe False cond $ nodeName dir matchesDir _ File{} = False @@ -95,13 +102,19 @@ galleryDirFilter config excludedCanonicalDirs = matchesFile cond file@File{} = maybe False cond $ nodeName file matchesFile _ Dir{} = False - anyPattern :: [String] -> FileName -> Bool - anyPattern patterns filename = any (flip Glob.match filename) (map Glob.compile patterns) - isExcludedDir :: FSNode -> Bool isExcludedDir Dir{canonicalPath} = any (canonicalPath ==) excludedCanonicalDirs isExcludedDir File{} = False +inputTreeFilter :: GalleryConfig -> InputTree -> Bool +inputTreeFilter GalleryConfig{includedTags, excludedTags} = + (hasTagMatching $ anyPattern includedTags) + &&& (not . (hasTagMatching $ anyPattern excludedTags)) + + where + hasTagMatching :: (String -> Bool) -> InputTree -> Bool + hasTagMatching cond = (any cond) . (fromMaybe [""] . tags) . sidecar + compileGallery :: FilePath -> FilePath -> FilePath -> FilePath -> [FilePath] -> Bool -> Bool -> IO () compileGallery configPath inputDirPath outputDirPath outputIndexPath excludedDirs rebuildAll cleanOutput = @@ -113,12 +126,13 @@ compileGallery configPath inputDirPath outputDirPath outputIndexPath excludedDir let sourceFilter = galleryDirFilter config excludedCanonicalDirs let sourceTree = filterDir sourceFilter inputDir inputTree <- readInputTree sourceTree + let curatedInputTree = filterInputTree (inputTreeFilter config) inputTree let cache = if rebuildAll then skipCached else withCached let itemProc = itemProcessor config cache let thumbnailProc = thumbnailProcessor config cache let galleryBuilder = buildGalleryTree itemProc thumbnailProc (tagsFromDirectories config) - resources <- galleryBuilder inputTree + resources <- galleryBuilder curatedInputTree when cleanOutput $ galleryCleanupResourceDir resources outputDirPath writeJSON (outputGalleryIndex outputIndexPath) $ GalleryIndex (viewerConfig config) resources -- cgit v1.2.3 From b04c5a58f449db6f8de0e837ffed1e087238787d Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 25 Apr 2020 21:34:00 +0200 Subject: compiler: bump stackage lts to 15.9 --- compiler/src/Compiler.hs | 1 - 1 file changed, 1 deletion(-) (limited to 'compiler/src/Compiler.hs') diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index fa405a2..749872d 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -24,7 +24,6 @@ module Compiler import GHC.Generics (Generic) import Control.Monad (liftM2, when) -import Data.List (any) import Data.Maybe (fromMaybe) import System.FilePath (()) import qualified System.FilePath.Glob as Glob -- cgit v1.2.3