aboutsummaryrefslogtreecommitdiff
path: root/compiler/src
diff options
context:
space:
mode:
authorpacien2023-02-17 22:57:38 +0100
committerpacien2023-02-17 22:57:38 +0100
commit46cd42de44e402fbf33522d999fa2649729ffaa8 (patch)
tree1281beefda5d9b6d2411bc47ec1327fbf0b38dde /compiler/src
parent11bbbae2850b9c45da697a8ed9626495a50a38c0 (diff)
parente939712a284dff9af6d81cc1fcd4e7f7ec9ad503 (diff)
downloadldgallery-46cd42de44e402fbf33522d999fa2649729ffaa8.tar.gz
Merge branch 'develop': release v2.2v2.2
Diffstat (limited to 'compiler/src')
-rw-r--r--compiler/src/Compiler.hs6
-rw-r--r--compiler/src/FileProcessors.hs24
-rw-r--r--compiler/src/Input.hs6
-rw-r--r--compiler/src/ItemProcessors.hs5
-rw-r--r--compiler/src/Resource.hs16
5 files changed, 39 insertions, 18 deletions
diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs
index 4111f02..d92d8e9 100644
--- a/compiler/src/Compiler.hs
+++ b/compiler/src/Compiler.hs
@@ -85,7 +85,8 @@ loadGalleryIndex path =
85 doesFileExist path >>= bool (return Nothing) decodeIndex 85 doesFileExist path >>= bool (return Nothing) decodeIndex
86 where 86 where
87 decodeIndex = 87 decodeIndex =
88 JSON.eitherDecodeFileStrict path 88 putStrLn ("Loading previous index:\t" ++ path)
89 >> JSON.eitherDecodeFileStrict path
89 >>= either (\err -> warn err >> return Nothing) (return . Just) 90 >>= either (\err -> warn err >> return Nothing) (return . Just)
90 warn = putStrLn . ("Warning:\tUnable to reuse existing index as cache: " ++) 91 warn = putStrLn . ("Warning:\tUnable to reuse existing index as cache: " ++)
91 92
@@ -136,10 +137,13 @@ compileGallery configPath inputDirPath outputDirPath outputIndexPath excludedDir
136 do 137 do
137 config <- readConfig $ inputGalleryConf configPath 138 config <- readConfig $ inputGalleryConf configPath
138 139
140 putStrLn "Inventorying input files"
139 inputDir <- readDirectory inputDirPath 141 inputDir <- readDirectory inputDirPath
140 excludedCanonicalDirs <- mapM canonicalizePath excludedDirs 142 excludedCanonicalDirs <- mapM canonicalizePath excludedDirs
143
141 let sourceFilter = galleryDirFilter config excludedCanonicalDirs 144 let sourceFilter = galleryDirFilter config excludedCanonicalDirs
142 let sourceTree = filterDir sourceFilter inputDir 145 let sourceTree = filterDir sourceFilter inputDir
146 putStrLn "Reading input metadata"
143 inputTree <- readInputTree sourceTree 147 inputTree <- readInputTree sourceTree
144 let curatedInputTree = filterInputTree (inputTreeFilter config) inputTree 148 let curatedInputTree = filterInputTree (inputTreeFilter config) inputTree
145 149
diff --git a/compiler/src/FileProcessors.hs b/compiler/src/FileProcessors.hs
index 6e1738e..78e7351 100644
--- a/compiler/src/FileProcessors.hs
+++ b/compiler/src/FileProcessors.hs
@@ -100,17 +100,35 @@ type FileDescriber a =
100 100
101getImageResolution :: FilePath -> IO Resolution 101getImageResolution :: FilePath -> IO Resolution
102getImageResolution fsPath = 102getImageResolution fsPath =
103 readProcess "magick" ["identify", "-format", "%w %h", firstFrame] [] 103 readProcess "magick"
104 >>= parseResolution . break (== ' ') 104 [ "identify"
105 , "-ping"
106 , "-format", "%[orientation] %w %h"
107 , firstFrame
108 ] []
109 >>= parseOutput . words
110
105 where 111 where
106 firstFrame :: FilePath 112 firstFrame :: FilePath
107 firstFrame = fsPath ++ "[0]" 113 firstFrame = fsPath ++ "[0]"
108 114
115 -- Flip the dimensions when necessary according to the metadata.
116 -- ImageMagick's `-auto-orient` flag does the same, but isn't compatible
117 -- with `-ping` and causes the whole image file to be loaded.
118 parseOutput :: [String] -> IO Resolution
119 parseOutput ["RightTop", w, h] = parseResolution (h, w)
120 parseOutput ["LeftBottom", w, h] = parseResolution (h, w)
121 parseOutput [_, w, h] = parseResolution (w, h)
122 parseOutput _ = throwIO failedRead
123
109 parseResolution :: (String, String) -> IO Resolution 124 parseResolution :: (String, String) -> IO Resolution
110 parseResolution (widthString, heightString) = 125 parseResolution (widthString, heightString) =
111 case (readMaybe widthString, readMaybe heightString) of 126 case (readMaybe widthString, readMaybe heightString) of
112 (Just w, Just h) -> return $ Resolution w h 127 (Just w, Just h) -> return $ Resolution w h
113 _ -> throwIO $ ProcessingException fsPath "Unable to read image resolution." 128 _ -> throwIO failedRead
129
130 failedRead :: ProcessingException
131 failedRead = ProcessingException fsPath "Unable to read image resolution."
114 132
115resourceAt :: FileDescriber Resource 133resourceAt :: FileDescriber Resource
116resourceAt resPath fsPath = Resource resPath <$> getModificationTime fsPath 134resourceAt resPath fsPath = Resource resPath <$> getModificationTime fsPath
diff --git a/compiler/src/Input.hs b/compiler/src/Input.hs
index 4cfabe6..7990571 100644
--- a/compiler/src/Input.hs
+++ b/compiler/src/Input.hs
@@ -1,7 +1,7 @@
1-- ldgallery - A static generator which turns a collection of tagged 1-- ldgallery - A static generator which turns a collection of tagged
2-- pictures into a searchable web gallery. 2-- pictures into a searchable web gallery.
3-- 3--
4-- Copyright (C) 2019-2021 Pacien TRAN-GIRARD 4-- Copyright (C) 2019-2022 Pacien TRAN-GIRARD
5-- 5--
6-- This program is free software: you can redistribute it and/or modify 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 7-- it under the terms of the GNU Affero General Public License as
@@ -153,6 +153,4 @@ filterInputTree cond = filterNode
153 filterNode :: InputTree -> InputTree 153 filterNode :: InputTree -> InputTree
154 filterNode inputFile@InputFile{} = inputFile 154 filterNode inputFile@InputFile{} = inputFile
155 filterNode inputDir@InputDir{items} = 155 filterNode inputDir@InputDir{items} =
156 filter cond items 156 inputDir { Input.items = filter cond items & map filterNode }
157 & map filterNode
158 & \curatedItems -> inputDir { items = curatedItems } :: InputTree
diff --git a/compiler/src/ItemProcessors.hs b/compiler/src/ItemProcessors.hs
index fa99316..6035477 100644
--- a/compiler/src/ItemProcessors.hs
+++ b/compiler/src/ItemProcessors.hs
@@ -1,7 +1,7 @@
1-- ldgallery - A static generator which turns a collection of tagged 1-- ldgallery - A static generator which turns a collection of tagged
2-- pictures into a searchable web gallery. 2-- pictures into a searchable web gallery.
3-- 3--
4-- Copyright (C) 2019-2021 Pacien TRAN-GIRARD 4-- Copyright (C) 2019-2022 Pacien TRAN-GIRARD
5-- 5--
6-- This program is free software: you can redistribute it and/or modify 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 7-- it under the terms of the GNU Affero General Public License as
@@ -38,6 +38,7 @@ data Format =
38 | PlainTextFormat 38 | PlainTextFormat
39 | MarkdownFormat 39 | MarkdownFormat
40 | PortableDocumentFormat 40 | PortableDocumentFormat
41 | EPUBFormat
41 | VideoFormat 42 | VideoFormat
42 | AudioFormat 43 | AudioFormat
43 | Unknown 44 | Unknown
@@ -59,6 +60,7 @@ formatFromPath =
59 ".txt" -> PlainTextFormat 60 ".txt" -> PlainTextFormat
60 ".md" -> MarkdownFormat 61 ".md" -> MarkdownFormat
61 ".pdf" -> PortableDocumentFormat 62 ".pdf" -> PortableDocumentFormat
63 ".epub" -> EPUBFormat
62 ".wav" -> AudioFormat 64 ".wav" -> AudioFormat
63 ".oga" -> AudioFormat 65 ".oga" -> AudioFormat
64 ".ogg" -> AudioFormat 66 ".ogg" -> AudioFormat
@@ -103,6 +105,7 @@ itemFileProcessor maxResolution =
103 processorFor PlainTextFormat _ = copyResource PlainText 105 processorFor PlainTextFormat _ = copyResource PlainText
104 processorFor MarkdownFormat _ = copyResource Markdown 106 processorFor MarkdownFormat _ = copyResource Markdown
105 processorFor PortableDocumentFormat _ = copyResource PDF 107 processorFor PortableDocumentFormat _ = copyResource PDF
108 processorFor EPUBFormat _ = copyResource EPUB
106 processorFor VideoFormat _ = copyResource Video 109 processorFor VideoFormat _ = copyResource Video
107 processorFor AudioFormat _ = copyResource Audio 110 processorFor AudioFormat _ = copyResource Audio
108 processorFor Unknown _ = copyResource Other 111 processorFor Unknown _ = copyResource Other
diff --git a/compiler/src/Resource.hs b/compiler/src/Resource.hs
index 804c9a1..e8ca58c 100644
--- a/compiler/src/Resource.hs
+++ b/compiler/src/Resource.hs
@@ -1,7 +1,7 @@
1-- ldgallery - A static generator which turns a collection of tagged 1-- ldgallery - A static generator which turns a collection of tagged
2-- pictures into a searchable web gallery. 2-- pictures into a searchable web gallery.
3-- 3--
4-- Copyright (C) 2019-2021 Pacien TRAN-GIRARD 4-- Copyright (C) 2019-2022 Pacien TRAN-GIRARD
5-- 5--
6-- This program is free software: you can redistribute it and/or modify 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 7-- it under the terms of the GNU Affero General Public License as
@@ -56,7 +56,7 @@ encodingOptions :: JSON.Options
56encodingOptions = JSON.defaultOptions 56encodingOptions = JSON.defaultOptions
57 { JSON.fieldLabelModifier = map toLower 57 { JSON.fieldLabelModifier = map toLower
58 , JSON.constructorTagModifier = map toLower 58 , JSON.constructorTagModifier = map toLower
59 , JSON.sumEncoding = JSON.defaultTaggedObject 59 , JSON.sumEncoding = JSON.TaggedObject
60 { JSON.tagFieldName = "type" 60 { JSON.tagFieldName = "type"
61 , JSON.contentsFieldName = "contents" 61 , JSON.contentsFieldName = "contents"
62 } 62 }
@@ -92,6 +92,7 @@ data GalleryItemProps =
92 | PlainText { resource :: Resource } 92 | PlainText { resource :: Resource }
93 | Markdown { resource :: Resource } 93 | Markdown { resource :: Resource }
94 | PDF { resource :: Resource } 94 | PDF { resource :: Resource }
95 | EPUB { resource :: Resource }
95 | Video { resource :: Resource } 96 | Video { resource :: Resource }
96 | Audio { resource :: Resource } 97 | Audio { resource :: Resource }
97 | Other { resource :: Resource } 98 | Other { resource :: Resource }
@@ -179,7 +180,7 @@ buildGalleryTree processItem processThumbnail tagsFromDirsConfig =
179 & map (prefix tagsFromDirsConfig ++) 180 & map (prefix tagsFromDirsConfig ++)
180 181
181 aggregateTags :: [GalleryItem] -> [Tag] 182 aggregateTags :: [GalleryItem] -> [Tag]
182 aggregateTags = concatMap (\item -> tags (item::GalleryItem)) 183 aggregateTags = concatMap Resource.tags
183 184
184 maybeThumbnail :: Path -> Maybe Path -> IO (Maybe Thumbnail) 185 maybeThumbnail :: Path -> Maybe Path -> IO (Maybe Thumbnail)
185 maybeThumbnail _ Nothing = return Nothing 186 maybeThumbnail _ Nothing = return Nothing
@@ -187,7 +188,7 @@ buildGalleryTree processItem processThumbnail tagsFromDirsConfig =
187 188
188 mostRecentModTime :: [GalleryItem] -> Maybe ZonedTime 189 mostRecentModTime :: [GalleryItem] -> Maybe ZonedTime
189 mostRecentModTime = 190 mostRecentModTime =
190 maximumByMay comparingTime . map (datetime::(GalleryItem -> ZonedTime)) 191 maximumByMay comparingTime . map Resource.datetime
191 192
192 comparingTime :: ZonedTime -> ZonedTime -> Ordering 193 comparingTime :: ZonedTime -> ZonedTime -> Ordering
193 comparingTime l r = compare (zonedTimeToUTC l) (zonedTimeToUTC r) 194 comparingTime l r = compare (zonedTimeToUTC l) (zonedTimeToUTC r)
@@ -219,14 +220,11 @@ galleryOutputDiff resources ref =
219 220
220 resPath :: GalleryItemProps -> Maybe Path 221 resPath :: GalleryItemProps -> Maybe Path
221 resPath Directory{} = Nothing 222 resPath Directory{} = Nothing
222 resPath resourceProps = 223 resPath resourceProps = Just $ resourcePath $ resourceProps.resource
223 Just
224 $ resourcePath
225 $ (resource :: (GalleryItemProps -> Resource)) resourceProps
226 224
227 thumbnailPaths :: [GalleryItem] -> [Path] 225 thumbnailPaths :: [GalleryItem] -> [Path]
228 thumbnailPaths = 226 thumbnailPaths =
229 map (resourcePath . (resource :: (Thumbnail -> Resource))) 227 map (\thumbnail -> resource