From e09e56d5dfb38b2d2757c04ba6953c8b737e7c9d Mon Sep 17 00:00:00 2001 From: Rhiannon Morris Date: Wed, 22 Jul 2020 01:48:29 +0200 Subject: [PATCH] add download field for svgs etc --- make-pages/Depend.hs | 5 +++-- make-pages/Info.hs | 21 ++++++++++++--------- make-pages/SinglePage.hs | 4 +++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/make-pages/Depend.hs b/make-pages/Depend.hs index dfbe87d..0e6b483 100644 --- a/make-pages/Depend.hs +++ b/make-pages/Depend.hs @@ -7,7 +7,7 @@ where import BuilderQQ import Info hiding (Text) -import Data.Maybe (fromMaybe) +import Data.Maybe (fromMaybe, mapMaybe) import Data.Text.Lazy (Text) import System.FilePath @@ -26,8 +26,9 @@ dependSingle' yamlDir info prefix build nsfw = let dir = build prefix yamlDir images = if nsfw then #images info else #sfwImages info paths = map #path images + dls = mapMaybe #download images index = dir "index.html" - deps = thumbFile (thumbnail info) : map pageFile paths ++ paths + deps = thumbFile (thumbnail info) : map pageFile paths ++ paths ++ dls deps' = unwords $ map (dir ) deps in [b|$@index: $@deps' $$(MAKEPAGES)|] diff --git a/make-pages/Info.hs b/make-pages/Info.hs index 6eea489..06cb07b 100644 --- a/make-pages/Info.hs +++ b/make-pages/Info.hs @@ -48,10 +48,11 @@ data Artist = data Image = Image { - label :: !Text, - path :: !FilePath, - nsfw :: !Bool, - warning :: !(Maybe Text) + label :: !Text, + path :: !FilePath, + download :: !(Maybe FilePath), + nsfw :: !Bool, + warning :: !(Maybe Text) } deriving (Eq, Show) @@ -123,12 +124,14 @@ unlabelledImage :: YAML.Node YAML.Pos -> YAML.Parser Image unlabelledImage y = asStr y <|> asObj y where asStr = YAML.withStr "path" \(Text.unpack -> path) -> - pure $ Image {label = "", path, nsfw = False, warning = Nothing} + pure $ Image {label = "", path, download = Nothing, + nsfw = False, warning = Nothing} asObj = YAML.withMap "image info" \m -> do - path <- m .: "path" - nsfw <- m .:? "nsfw" .!= False - warning <- m .:? "warning" - pure $ Image {label = "", path, nsfw, warning} + path <- m .: "path" + download <- m .:? "download" + nsfw <- m .:? "nsfw" .!= False + warning <- m .:? "warning" + pure $ Image {label = "", path, download, nsfw, warning} instance FromYAML Link where parseYAML y = do diff --git a/make-pages/SinglePage.hs b/make-pages/SinglePage.hs index 3194174..0dbb7dc 100644 --- a/make-pages/SinglePage.hs +++ b/make-pages/SinglePage.hs @@ -6,6 +6,7 @@ import BuilderQQ import Records () import Control.Exception +import Data.Maybe (fromMaybe) import qualified Data.Text as Strict import qualified Data.Text.Lazy as Lazy import Data.Time (formatTime, defaultTimeLocale) @@ -51,7 +52,7 @@ make' nsfw dir (Info {date, title, artist, tags, nsfwTags,
$warning' - +
@@ -79,6 +80,7 @@ make' nsfw dir (Info {date, title, artist, tags, nsfwTags, buttonBar = makeButtonBar title nsfw images image0 = head images path0 = #path image0 + download0 = fromMaybe path0 (#download image0) path0' = pageFile path0 descSection = ifJust description makeDesc