aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpacien2020-01-06 10:28:27 +0100
committerpacien2020-01-06 10:28:27 +0100
commit03d39102ba55cda7cbe80fcdeb9b250caaa70bd0 (patch)
tree679a36e4b5eaa9c49bb62b715772d96bd9a26aaa
parent5f57fd4f21f7ecd4038ca6e66a4b89622cbcc9fc (diff)
downloadldgallery-03d39102ba55cda7cbe80fcdeb9b250caaa70bd0.tar.gz
compiler: properly reject invalid dates in sidecar files
GitHub: closes #31
-rw-r--r--compiler/package.yaml2
-rw-r--r--compiler/src/Input.hs3
-rw-r--r--compiler/src/Resource.hs6
-rw-r--r--compiler/stack.yaml6
-rw-r--r--compiler/stack.yaml.lock30
-rw-r--r--ldgallery.1.md2
6 files changed, 6 insertions, 43 deletions
diff --git a/compiler/package.yaml b/compiler/package.yaml
index fd44ccc..043985d 100644
--- a/compiler/package.yaml
+++ b/compiler/package.yaml
@@ -28,7 +28,7 @@ dependencies:
28- parallel-io 28- parallel-io
29- Glob 29- Glob
30- safe 30- safe
31- time >= 1.9.3 && < 1.10 31- time
32 32
33default-extensions: 33default-extensions:
34- DuplicateRecordFields 34- DuplicateRecordFields
diff --git a/compiler/src/Input.hs b/compiler/src/Input.hs
index 86d3ec8..85c802e 100644
--- a/compiler/src/Input.hs
+++ b/compiler/src/Input.hs
@@ -30,6 +30,7 @@ import Data.Function ((&))
30import Data.Maybe (catMaybes) 30import Data.Maybe (catMaybes)
31import Data.Bool (bool) 31import Data.Bool (bool)
32import Data.List (find) 32import Data.List (find)
33import Data.Time.LocalTime (ZonedTime)
33import Data.Yaml (ParseException, decodeFileEither) 34import Data.Yaml (ParseException, decodeFileEither)
34import Data.Aeson (FromJSON) 35import Data.Aeson (FromJSON)
35import System.FilePath (isExtensionOf, dropExtension) 36import System.FilePath (isExtensionOf, dropExtension)
@@ -60,7 +61,7 @@ data InputTree =
60 61
61data Sidecar = Sidecar 62data Sidecar = Sidecar
62 { title :: Maybe String 63 { title :: Maybe String
63 , date :: Maybe String 64 , date :: Maybe ZonedTime
64 , description :: Maybe String 65 , description :: Maybe String
65 , tags :: Maybe [String] 66 , tags :: Maybe [String]
66 } deriving (Generic, FromJSON, Show) 67 } deriving (Generic, FromJSON, Show)
diff --git a/compiler/src/Resource.hs b/compiler/src/Resource.hs
index 207239f..53d61ac 100644
--- a/compiler/src/Resource.hs
+++ b/compiler/src/Resource.hs
@@ -31,7 +31,6 @@ import Data.Maybe (mapMaybe, fromMaybe)
31import Data.Function ((&)) 31import Data.Function ((&))
32import qualified Data.Set as Set 32import qualified Data.Set as Set
33import Data.Time.LocalTime (ZonedTime, utc, utcToZonedTime, zonedTimeToUTC) 33import Data.Time.LocalTime (ZonedTime, utc, utcToZonedTime, zonedTimeToUTC)
34import Data.Time.Format.ISO8601 (iso8601ParseM)
35import System.Directory (getModificationTime) 34import System.Directory (getModificationTime)
36import Safe.Foldable (maximumByMay) 35import Safe.Foldable (maximumByMay)
37 36
@@ -110,7 +109,7 @@ buildGalleryTree processItem processThumbnail tagsFromDirectories galleryName in
110 fileModTime <- lastModTime path 109 fileModTime <- lastModTime path
111 return GalleryItem 110 return GalleryItem
112 { title = itemTitle 111 { title = itemTitle
113 , date = fromMaybe fileModTime itemDate 112 , date = fromMaybe fileModTime $ Input.date sidecar
114 , description = optMeta description "" 113 , description = optMeta description ""
115 , tags = (optMeta tags []) ++ implicitParentTags parents 114 , tags = (optMeta tags []) ++ implicitParentTags parents
116 , path = parents </ itemTitle 115 , path = parents </ itemTitle
@@ -120,9 +119,6 @@ buildGalleryTree processItem processThumbnail tagsFromDirectories galleryName in
120 itemTitle :: String 119 itemTitle :: String
121 itemTitle = optMeta title $ fromMaybe "" $ fileName path 120 itemTitle = optMeta title $ fromMaybe "" $ fileName path
122 121
123 itemDate :: Maybe ZonedTime
124 itemDate = Input.date sidecar >>= iso8601ParseM
125
126 optMeta :: (Sidecar -> Maybe a) -> a -> a 122 optMeta :: (Sidecar -> Maybe a) -> a -> a
127 optMeta get fallback = fromMaybe fallback $ get sidecar 123 optMeta get fallback = fromMaybe fallback $ get sidecar
128 124
diff --git a/compiler/stack.yaml b/compiler/stack.yaml
index 146f46b..29f8539 100644
--- a/compiler/stack.yaml
+++ b/compiler/stack.yaml
@@ -41,12 +41,6 @@ packages:
41# 41#
42# extra-deps: [] 42# extra-deps: []
43 43
44extra-deps:
45- time-1.9.3@sha256:8f1b5448722a12a952248b356c9eb366e351226543d9086a2da71270522d5f45,5679
46- directory-1.3.4.0@sha256:500019f04494324d1df16cf83eefeb3f809b2b20b32a32ccd755ee0439c18bfd,2829
47- process-1.6.7.0@sha256:305bcf44c42a96425e77af1748183f505a701648f68cc299d5ad8ac1b866a6a1,2468
48- unix-2.7.2.2@sha256:e69269a17b9fa26cb77f3f55e86c39d0a4940ccfa0c4bc20826919d2572076ad,3496
49
50# Override default flag values for local packages and extra-deps 44# Override default flag values for local packages and extra-deps
51# flags: {} 45# flags: {}
52 46
diff --git a/compiler/stack.yaml.lock b/compiler/stack.yaml.lock
index 8e833c5..fc538c1 100644
--- a/compiler/stack.yaml.lock
+++ b/compiler/stack.yaml.lock
@@ -3,35 +3,7 @@
3# For more information, please see the documentation at: 3# For more information, please see the documentation at:
4# https://docs.haskellstack.org/en/stable/lock_files 4# https://docs.haskellstack.org/en/stable/lock_files
5 5
6packages: 6packages: []
7- completed:
8 hackage: time-1.9.3@sha256:8f1b5448722a12a952248b356c9eb366e351226543d9086a2da71270522d5f45,5679
9 pantry-tree:
10 size: 6558
11 sha256: a1043c1719491764f0fa37a1fd70d9451080548a41632fee88d8e1b8db4942d6
12 original:
13 hackage: time-1.9.3@sha256:8f1b5448722a12a952248b356c9eb366e351226543d9086a2da71270522d5f45,5679
14- completed:
15 hackage: directory-1.3.4.0@sha256:500019f04494324d1df16cf83eefeb3f809b2b20b32a32ccd755ee0439c18bfd,2829
16 pantry-tree:
17 size: 3365
18 sha256: 00c09e0c014d29ebfb921b64c1459e61a0ad6f10e70128d795246a47c06394b0
19 original:
20 hackage: directory-1.3.4.0@sha256:500019f04494324d1df16cf83eefeb3f809b2b20b32a32ccd755ee0439c18bfd,2829
21- completed:
22 hackage: process-1.6.7.0@sha256:305bcf44c42a96425e77af1748183f505a701648f68cc299d5ad8ac1b866a6a1,2468
23 pantry-tree:
24 size: 1211
25 sha256: 49c3e531d2473fe455c1cde655f074a320fa4ec8569d650262bf382f9c5796fb
26 original:
27 hackage: process-1.6.7.0@sha256:305bcf44c42a96425e77af1748183f505a701648f68cc299d5ad8ac1b866a6a1,2468
28- completed:
29 hackage: unix-2.7.2.2@sha256:e69269a17b9fa26cb77f3f55e86c39d0a4940ccfa0c4bc20826919d2572076ad,3496
30 pantry-tree:
31 size: 3536
32 sha256: c355f7924ce67e5bf8f20767462af18f09b8c0d1f7161117221cbb94c15deee3
33 original:
34 hackage: unix-2.7.2.2@sha256:e69269a17b9fa26cb77f3f55e86c39d0a4940ccfa0c4bc20826919d2572076ad,3496
35snapshots: 7snapshots:
36- completed: 8- completed:
37 size: 524799 9 size: 524799
diff --git a/ldgallery.1.md b/ldgallery.1.md
index cfe24d7..7163c8e 100644
--- a/ldgallery.1.md
+++ b/ldgallery.1.md
@@ -74,7 +74,7 @@ title
74: Title of the item. Defaults to the name of the file. 74: Title of the item. Defaults to the name of the file.
75 75
76date 76date
77: ISO 8601-formatted date and time. Defaults to the last modification time of the file. 77: ISO 8601 zoned date and time. Defaults to the last modification time of the file.
78 78
79description 79description
80: Description for the item. 80: Description for the item.