diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ldgallery.1.md | 4 | ||||
-rw-r--r-- | compiler/package.yaml | 8 | ||||
-rw-r--r-- | compiler/src/Compiler.hs | 6 | ||||
-rw-r--r-- | compiler/src/FileProcessors.hs | 24 | ||||
-rw-r--r-- | compiler/src/Input.hs | 6 | ||||
-rw-r--r-- | compiler/src/ItemProcessors.hs | 5 | ||||
-rw-r--r-- | compiler/src/Resource.hs | 16 | ||||
-rw-r--r-- | compiler/stack.yaml | 2 | ||||
-rw-r--r-- | compiler/stack.yaml.lock | 8 |
9 files changed, 51 insertions, 28 deletions
diff --git a/compiler/ldgallery.1.md b/compiler/ldgallery.1.md index 2e247cd..908715f 100644 --- a/compiler/ldgallery.1.md +++ b/compiler/ldgallery.1.md | |||
@@ -2,7 +2,7 @@ | |||
2 | pagetitle: Compiler user manual - ldgallery | 2 | pagetitle: Compiler user manual - ldgallery |
3 | title: LDGALLERY(1) ldgallery | 3 | title: LDGALLERY(1) ldgallery |
4 | author: Pacien TRAN-GIRARD, Guillaume FOUET | 4 | author: Pacien TRAN-GIRARD, Guillaume FOUET |
5 | date: 2022-09-04 (v2.1) | 5 | date: 2023-02-17 (v2.2) |
6 | --- | 6 | --- |
7 | 7 | ||
8 | 8 | ||
@@ -187,7 +187,7 @@ The ldgallery source code is available on <https://ldgallery.pacien.org>. | |||
187 | 187 | ||
188 | # LICENSE | 188 | # LICENSE |
189 | 189 | ||
190 | Copyright (C) 2019-2022 Pacien TRAN-GIRARD and Guillaume FOUET. | 190 | Copyright (C) 2019-2023 Pacien TRAN-GIRARD and Guillaume FOUET. |
191 | 191 | ||
192 | 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. | 192 | 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. |
193 | 193 | ||
diff --git a/compiler/package.yaml b/compiler/package.yaml index 7bd86e9..d7c07e9 100644 --- a/compiler/package.yaml +++ b/compiler/package.yaml | |||
@@ -1,10 +1,10 @@ | |||
1 | name: ldgallery-compiler | 1 | name: ldgallery-compiler |
2 | version: 2.1 | 2 | version: 2.2 |
3 | homepage: https://ldgallery.pacien.org | 3 | homepage: https://ldgallery.pacien.org |
4 | github: "pacien/ldgallery" | 4 | github: "pacien/ldgallery" |
5 | license: AGPL-3 | 5 | license: AGPL-3.0-only |
6 | author: "Pacien TRAN-GIRARD, Guillaume FOUET" | 6 | author: "Pacien TRAN-GIRARD, Guillaume FOUET" |
7 | copyright: "2019-2021 Pacien TRAN-GIRARD, Guillaume FOUET" | 7 | copyright: "2019-2023 Pacien TRAN-GIRARD, Guillaume FOUET" |
8 | 8 | ||
9 | extra-source-files: | 9 | extra-source-files: |
10 | - readme.md | 10 | - readme.md |
@@ -32,6 +32,8 @@ dependencies: | |||
32 | 32 | ||
33 | default-extensions: | 33 | default-extensions: |
34 | - DuplicateRecordFields | 34 | - DuplicateRecordFields |
35 | - DisambiguateRecordFields | ||
36 | - OverloadedRecordDot | ||
35 | - DeriveGeneric | 37 | - DeriveGeneric |
36 | - DeriveDataTypeable | 38 | - DeriveDataTypeable |
37 | - DeriveAnyClass | 39 | - DeriveAnyClass |
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 | ||
101 | getImageResolution :: FilePath -> IO Resolution | 101 | getImageResolution :: FilePath -> IO Resolution |
102 | getImageResolution fsPath = | 102 | getImageResolution 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 | ||
115 | resourceAt :: FileDescriber Resource | 133 | resourceAt :: FileDescriber Resource |
116 | resourceAt resPath fsPath = Resource resPath <$> getModificationTime fsPath | 134 | resourceAt 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 | |||
56 | encodingOptions = JSON.defaultOptions | 56 | encodingOptions = 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 } |