From 80c83b921b440ea345783b8a9f26dc0acb87abd4 Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 25 Oct 2022 17:16:52 +0200 Subject: compiler: fix exif-rotated image dimension retrieval GitHub: fixes #336 --- compiler/src/FileProcessors.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'compiler') diff --git a/compiler/src/FileProcessors.hs b/compiler/src/FileProcessors.hs index 6e1738e..db5c9a1 100644 --- a/compiler/src/FileProcessors.hs +++ b/compiler/src/FileProcessors.hs @@ -100,7 +100,8 @@ type FileDescriber a = getImageResolution :: FilePath -> IO Resolution getImageResolution fsPath = - readProcess "magick" ["identify", "-format", "%w %h", firstFrame] [] + readProcess "magick" + ["identify", "-auto-orient", "-format", "%w %h", firstFrame] [] >>= parseResolution . break (== ' ') where firstFrame :: FilePath -- cgit v1.2.3 From 0fddc74a3f9add47841124b4d77b097f4646d14f Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 30 Oct 2022 01:05:45 +0200 Subject: compiler: fix support for non-utf8 terminals The compiler echoes the names of the files being processed. Those file names may contain UTF-8 characters. However, some consoles may not support those. This is notably the case of the Windows CMD or on Linux with the legacy C locale. This caused the following error: ldgallery: : commitBuffer: invalid argument (invalid character) This patch adds automatic transliteration when a non-UTF8 terminal is detected, so that neither the compiler or the terminal crash due to UTF8 characters. GitHub: closes #341 --- compiler/app/Main.hs | 5 +++-- compiler/package.yaml | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'compiler') diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 3e6f254..a9630ce 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -1,7 +1,7 @@ -- ldgallery - A static generator which turns a collection of tagged -- pictures into a searchable web gallery. -- --- Copyright (C) 2019-2021 Pacien TRAN-GIRARD +-- Copyright (C) 2019-2022 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 @@ -28,6 +28,7 @@ import Data.Aeson (ToJSON) import System.FilePath (()) import System.Directory (canonicalizePath, listDirectory) import System.Console.CmdArgs +import Main.Utf8 (withUtf8) import Compiler import Files (readDirectory, copyTo, remove) @@ -103,7 +104,7 @@ options = Options main :: IO () main = - do + withUtf8 $ do opts <- cmdArgs options buildGallery opts deployViewer opts diff --git a/compiler/package.yaml b/compiler/package.yaml index 7bd86e9..0c07efe 100644 --- a/compiler/package.yaml +++ b/compiler/package.yaml @@ -4,7 +4,7 @@ homepage: https://ldgallery.pacien.org github: "pacien/ldgallery" license: AGPL-3 author: "Pacien TRAN-GIRARD, Guillaume FOUET" -copyright: "2019-2021 Pacien TRAN-GIRARD, Guillaume FOUET" +copyright: "2019-2022 Pacien TRAN-GIRARD, Guillaume FOUET" extra-source-files: - readme.md @@ -29,6 +29,7 @@ dependencies: - safe - time - process +- with-utf8 default-extensions: - DuplicateRecordFields -- cgit v1.2.3 From f23c5e5b2cc837093e029884eae1f2edeaa4c888 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 30 Oct 2022 01:31:47 +0200 Subject: compiler: add log messages for early steps This adds some messages signaling that the compiler is doing something when it is enumerating the input tree and reading metadata files, which may take a while on systems with slow IO such as when using a network share. GitHub: closes #344 --- compiler/src/Compiler.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'compiler') 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 = doesFileExist path >>= bool (return Nothing) decodeIndex where decodeIndex = - JSON.eitherDecodeFileStrict path + putStrLn ("Loading previous index:\t" ++ path) + >> JSON.eitherDecodeFileStrict path >>= either (\err -> warn err >> return Nothing) (return . Just) warn = putStrLn . ("Warning:\tUnable to reuse existing index as cache: " ++) @@ -136,10 +137,13 @@ compileGallery configPath inputDirPath outputDirPath outputIndexPath excludedDir do config <- readConfig $ inputGalleryConf configPath + putStrLn "Inventorying input files" inputDir <- readDirectory inputDirPath excludedCanonicalDirs <- mapM canonicalizePath excludedDirs + let sourceFilter = galleryDirFilter config excludedCanonicalDirs let sourceTree = filterDir sourceFilter inputDir + putStrLn "Reading input metadata" inputTree <- readInputTree sourceTree let curatedInputTree = filterInputTree (inputTreeFilter config) inputTree -- cgit v1.2.3 From 7ae7e904303dd623398495c2d61d1acadfe96fb1 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 30 Oct 2022 01:58:22 +0200 Subject: compiler: update stack resolver lts-16.19 -> lts-19.30 To have with-utf8 1.0.2.3, because 1.0.2.1 fails building on Windows with the following error: Module `GHC.IO.Encoding.Iconv' does not export `localeEncodingName' --- compiler/stack.yaml | 2 +- compiler/stack.yaml.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'compiler') diff --git a/compiler/stack.yaml b/compiler/stack.yaml index 67e823b..b75c56f 100644 --- a/compiler/stack.yaml +++ b/compiler/stack.yaml @@ -17,7 +17,7 @@ # # resolver: ./custom-snapshot.yaml # resolver: https://example.com/snapshots/2018-01-01.yaml -resolver: lts-16.19 +resolver: lts-19.30 # User packages to be built. diff --git a/compiler/stack.yaml.lock b/compiler/stack.yaml.lock index 93f79d9..dc48671 100644 --- a/compiler/stack.yaml.lock +++ b/compiler/stack.yaml.lock @@ -6,7 +6,7 @@ packages: [] snapshots: - completed: - size: 532177 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/19.yaml - sha256: d2b828ecf50386841d0c5700b58d38566992e10d63a062af497ab29ab031faa1 - original: lts-16.19 + sha256: 9a74d76d250a455d9cd11e74f157e087787fa9aa3c4264e69c94703d1e71aede + size: 619200 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/30.yaml + original: lts-19.30 -- cgit v1.2.3 From 736520e5e17eee490565c98cd037363fd3e34aed Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 31 Oct 2022 00:14:07 +0100 Subject: compiler,viewer: register EPUB item type --- compiler/src/ItemProcessors.hs | 5 ++++- compiler/src/Resource.hs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'compiler') 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 @@ -- ldgallery - A static generator which turns a collection of tagged -- pictures into a searchable web gallery. -- --- Copyright (C) 2019-2021 Pacien TRAN-GIRARD +-- Copyright (C) 2019-2022 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 @@ -38,6 +38,7 @@ data Format = | PlainTextFormat | MarkdownFormat | PortableDocumentFormat + | EPUBFormat | VideoFormat | AudioFormat | Unknown @@ -59,6 +60,7 @@ formatFromPath = ".txt" -> PlainTextFormat ".md" -> MarkdownFormat ".pdf" -> PortableDocumentFormat + ".epub" -> EPUBFormat ".wav" -> AudioFormat ".oga" -> AudioFormat ".ogg" -> AudioFormat @@ -103,6 +105,7 @@ itemFileProcessor maxResolution = processorFor PlainTextFormat _ = copyResource PlainText processorFor MarkdownFormat _ = copyResource Markdown processorFor PortableDocumentFormat _ = copyResource PDF + processorFor EPUBFormat _ = copyResource EPUB processorFor VideoFormat _ = copyResource Video processorFor AudioFormat _ = copyResource Audio processorFor Unknown _ = copyResource Other diff --git a/compiler/src/Resource.hs b/compiler/src/Resource.hs index 804c9a1..1868512 100644 --- a/compiler/src/Resource.hs +++ b/compiler/src/Resource.hs @@ -92,6 +92,7 @@ data GalleryItemProps = | PlainText { resource :: Resource } | Markdown { resource :: Resource } | PDF { resource :: Resource } + | EPUB { resource :: Resource } | Video { resource :: Resource } | Audio { resource :: Resource } | Other { resource :: Resource } -- cgit v1.2.3 From 63ff07fe7f4168ac6655df755c3f5f8c4c2be10e Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 1 Dec 2022 20:03:29 +0100 Subject: project: fix licence spdx identifier --- compiler/package.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compiler') diff --git a/compiler/package.yaml b/compiler/package.yaml index 0c07efe..04cafd4 100644 --- a/compiler/package.yaml +++ b/compiler/package.yaml @@ -2,7 +2,7 @@ name: ldgallery-compiler version: 2.1 homepage: https://ldgallery.pacien.org github: "pacien/ldgallery" -license: AGPL-3 +license: AGPL-3.0-only author: "Pacien TRAN-GIRARD, Guillaume FOUET" copyright: "2019-2022 Pacien TRAN-GIRARD, Guillaume FOUET" -- cgit v1.2.3 From 84560140ee006c8bff7e2c2d4b7140fe9b09c62d Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 1 Dec 2022 19:58:18 +0100 Subject: compiler/stack: update lts for ghc 9.2 --- compiler/stack.yaml | 2 +- compiler/stack.yaml.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'compiler') diff --git a/compiler/stack.yaml b/compiler/stack.yaml index b75c56f..213f184 100644 --- a/compiler/stack.yaml +++ b/compiler/stack.yaml @@ -17,7 +17,7 @@ # # resolver: ./custom-snapshot.yaml # resolver: https://example.com/snapshots/2018-01-01.yaml -resolver: lts-19.30 +resolver: lts-20.2 # User packages to be built. diff --git a/compiler/stack.yaml.lock b/compiler/stack.yaml.lock index dc48671..106b28c 100644 --- a/compiler/stack.yaml.lock +++ b/compiler/stack.yaml.lock @@ -6,7 +6,7 @@ packages: [] snapshots: - completed: - sha256: 9a74d76d250a455d9cd11e74f157e087787fa9aa3c4264e69c94703d1e71aede - size: 619200 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/30.yaml - original: lts-19.30 + sha256: fc39d8afc97531d53d87b10abdef593bce503c0c1e46c2e9a84ebcbc78bf8470 + size: 648432 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/2.yaml + original: lts-20.2 -- cgit v1.2.3 From 922481cfd39543128396dca05c7a83588bcd332e Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 1 Dec 2022 20:00:12 +0100 Subject: compiler: fix build for ghc 9.2 --- compiler/package.yaml | 2 ++ compiler/src/Input.hs | 6 ++---- compiler/src/Resource.hs | 15 ++++++--------- 3 files changed, 10 insertions(+), 13 deletions(-) (limited to 'compiler') diff --git a/compiler/package.yaml b/compiler/package.yaml index 04cafd4..539bf9d 100644 --- a/compiler/package.yaml +++ b/compiler/package.yaml @@ -33,6 +33,8 @@ dependencies: default-extensions: - DuplicateRecordFields +- DisambiguateRecordFields +- OverloadedRecordDot - DeriveGeneric - DeriveDataTypeable - DeriveAnyClass 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 @@ -- ldgallery - A static generator which turns a collection of tagged -- pictures into a searchable web gallery. -- --- Copyright (C) 2019-2021 Pacien TRAN-GIRARD +-- Copyright (C) 2019-2022 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 @@ -153,6 +153,4 @@ filterInputTree cond = filterNode filterNode :: InputTree -> InputTree filterNode inputFile@InputFile{} = inputFile filterNode inputDir@InputDir{items} = - filter cond items - & map filterNode - & \curatedItems -> inputDir { items = curatedItems } :: InputTree + inputDir { Input.items = filter cond items & map filterNode } diff --git a/compiler/src/Resource.hs b/compiler/src/Resource.hs index 1868512..e8ca58c 100644 --- a/compiler/src/Resource.hs +++ b/compiler/src/Resource.hs @@ -1,7 +1,7 @@ -- ldgallery - A static generator which turns a collection of tagged -- pictures into a searchable web gallery. -- --- Copyright (C) 2019-2021 Pacien TRAN-GIRARD +-- Copyright (C) 2019-2022 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 @@ -56,7 +56,7 @@ encodingOptions :: JSON.Options encodingOptions = JSON.defaultOptions { JSON.fieldLabelModifier = map toLower , JSON.constructorTagModifier = map toLower - , JSON.sumEncoding = JSON.defaultTaggedObject + , JSON.sumEncoding = JSON.TaggedObject { JSON.tagFieldName = "type" , JSON.contentsFieldName = "contents" } @@ -180,7 +180,7 @@ buildGalleryTree processItem processThumbnail tagsFromDirsConfig = & map (prefix tagsFromDirsConfig ++) aggregateTags :: [GalleryItem] -> [Tag] - aggregateTags = concatMap (\item -> tags (item::GalleryItem)) + aggregateTags = concatMap Resource.tags maybeThumbnail :: Path -> Maybe Path -> IO (Maybe Thumbnail) maybeThumbnail _ Nothing = return Nothing @@ -188,7 +188,7 @@ buildGalleryTree processItem processThumbnail tagsFromDirsConfig = mostRecentModTime :: [GalleryItem] -> Maybe ZonedTime mostRecentModTime = - maximumByMay comparingTime . map (datetime::(GalleryItem -> ZonedTime)) + maximumByMay comparingTime . map Resource.datetime comparingTime :: ZonedTime -> ZonedTime -> Ordering comparingTime l r = compare (zonedTimeToUTC l) (zonedTimeToUTC r) @@ -220,14 +220,11 @@ galleryOutputDiff resources ref = resPath :: GalleryItemProps -> Maybe Path resPath Directory{} = Nothing - resPath resourceProps = - Just - $ resourcePath - $ (resource :: (GalleryItemProps -> Resource)) resourceProps + resPath resourceProps = Just $ resourcePath $ resourceProps.resource thumbnailPaths :: [GalleryItem] -> [Path] thumbnailPaths = - map (resourcePath . (resource :: (Thumbnail -> Resource))) + map (\thumbnail -> resourcePath thumbnail.resource) . mapMaybe thumbnail (\\) :: [Path] -> [Path] -> [Path] -- cgit v1.2.3 From 828f033e80773b38842cca6c30c3c08f320f6e1f Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 27 Dec 2022 22:55:30 +0100 Subject: compiler: handle dimension flip internally ImageMagick's `-auto-rotate` flag prevents the use of `-ping`, forcing the whole files to be loaded just to read the adjusted width and height. This makes the compiler handle the dimension flipping internally while using `-ping`, which should be way faster. --- compiler/src/FileProcessors.hs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'compiler') diff --git a/compiler/src/FileProcessors.hs b/compiler/src/FileProcessors.hs index db5c9a1..78e7351 100644 --- a/compiler/src/FileProcessors.hs +++ b/compiler/src/FileProcessors.hs @@ -101,17 +101,34 @@ type FileDescriber a = getImageResolution :: FilePath -> IO Resolution getImageResolution fsPath = readProcess "magick" - ["identify", "-auto-orient", "-format", "%w %h", firstFrame] [] - >>= parseResolution . break (== ' ') + [ "identify" + , "-ping" + , "-format", "%[orientation] %w %h" + , firstFrame + ] [] + >>= parseOutput . words + where firstFrame :: FilePath firstFrame = fsPath ++ "[0]" + -- Flip the dimensions when necessary according to the metadata. + -- ImageMagick's `-auto-orient` flag does the same, but isn't compatible + -- with `-ping` and causes the whole image file to be loaded. + parseOutput :: [String] -> IO Resolution + parseOutput ["RightTop", w, h] = parseResolution (h, w) + parseOutput ["LeftBottom", w, h] = parseResolution (h, w) + parseOutput [_, w, h] = parseResolution (w, h) + parseOutput _ = throwIO failedRead + parseResolution :: (String, String) -> IO Resolution parseResolution (widthString, heightString) = case (readMaybe widthString, readMaybe heightString) of (Just w, Just h) -> return $ Resolution w h - _ -> throwIO $ ProcessingException fsPath "Unable to read image resolution." + _ -> throwIO failedRead + + failedRead :: ProcessingException + failedRead = ProcessingException fsPath "Unable to read image resolution." resourceAt :: FileDescriber Resource resourceAt resPath fsPath = Resource resPath <$> getModificationTime fsPath -- cgit v1.2.3 From d266ee66cf3e366fbeb6d92c03dedff3b7aa3f14 Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 16 Feb 2023 22:54:42 +0100 Subject: Revert "compiler: fix support for non-utf8 terminals" The reverted changeset fixed some crash due to character encoding mismatch in terminal emulators. Doing so, it made it possible for the compiler to complete without reporting any error, while outputting wrongly encoded files. It's better to revert that changeset until all the encoding issue are solved consistently. This reverts commit 0fddc74a3f9add47841124b4d77b097f4646d14f. --- compiler/app/Main.hs | 5 ++--- compiler/package.yaml | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'compiler') diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index a9630ce..3e6f254 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -1,7 +1,7 @@ -- ldgallery - A static generator which turns a collection of tagged -- pictures into a searchable web gallery. -- --- Copyright (C) 2019-2022 Pacien TRAN-GIRARD +-- Copyright (C) 2019-2021 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 @@ -28,7 +28,6 @@ import Data.Aeson (ToJSON) import System.FilePath (()) import System.Directory (canonicalizePath, listDirectory) import System.Console.CmdArgs -import Main.Utf8 (withUtf8) import Compiler import Files (readDirectory, copyTo, remove) @@ -104,7 +103,7 @@ options = Options main :: IO () main = - withUtf8 $ do + do opts <- cmdArgs options buildGallery opts deployViewer opts diff --git a/compiler/package.yaml b/compiler/package.yaml index 539bf9d..4b749e1 100644 --- a/compiler/package.yaml +++ b/compiler/package.yaml @@ -4,7 +4,7 @@ homepage: https://ldgallery.pacien.org github: "pacien/ldgallery" license: AGPL-3.0-only author: "Pacien TRAN-GIRARD, Guillaume FOUET" -copyright: "2019-2022 Pacien TRAN-GIRARD, Guillaume FOUET" +copyright: "2019-2021 Pacien TRAN-GIRARD, Guillaume FOUET" extra-source-files: - readme.md @@ -29,7 +29,6 @@ dependencies: - safe - time - process -- with-utf8 default-extensions: - DuplicateRecordFields -- cgit v1.2.3 From e939712a284dff9af6d81cc1fcd4e7f7ec9ad503 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 17 Feb 2023 22:52:05 +0100 Subject: project: release v2.2 --- compiler/ldgallery.1.md | 4 ++-- compiler/package.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'compiler') 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 @@ pagetitle: Compiler user manual - ldgallery title: LDGALLERY(1) ldgallery author: Pacien TRAN-GIRARD, Guillaume FOUET -date: 2022-09-04 (v2.1) +date: 2023-02-17 (v2.2) --- @@ -187,7 +187,7 @@ The ldgallery source code is available on . # LICENSE -Copyright (C) 2019-2022 Pacien TRAN-GIRARD and Guillaume FOUET. +Copyright (C) 2019-2023 Pacien TRAN-GIRARD and Guillaume FOUET. 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. diff --git a/compiler/package.yaml b/compiler/package.yaml index 4b749e1..d7c07e9 100644 --- a/compiler/package.yaml +++ b/compiler/package.yaml @@ -1,10 +1,10 @@ name: ldgallery-compiler -version: 2.1 +version: 2.2 homepage: https://ldgallery.pacien.org github: "pacien/ldgallery" license: AGPL-3.0-only author: "Pacien TRAN-GIRARD, Guillaume FOUET" -copyright: "2019-2021 Pacien TRAN-GIRARD, Guillaume FOUET" +copyright: "2019-2023 Pacien TRAN-GIRARD, Guillaume FOUET" extra-source-files: - readme.md -- cgit v1.2.3