From 8a39a5a46b9c8108a98e349d585fd62083f1d835 Mon Sep 17 00:00:00 2001 From: Rhiannon Morris Date: Sat, 1 Aug 2020 03:02:49 +0200 Subject: [PATCH] make default image label from filename --- make-pages/Info.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/make-pages/Info.hs b/make-pages/Info.hs index 01a5af6..63a1ef7 100644 --- a/make-pages/Info.hs +++ b/make-pages/Info.hs @@ -22,6 +22,7 @@ import qualified Data.Text as Text import Data.Time.Calendar (Day (..), toGregorian) import Data.YAML (FromYAML (..), (.:), (.:?), (.!=)) import qualified Data.YAML as YAML +import System.FilePath (takeBaseName) import Text.Read (readMaybe) @@ -126,14 +127,16 @@ 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, download = Nothing, + pure $ Image {label = pathToLabel path, path, download = Nothing, nsfw = False, warning = Nothing} asObj = YAML.withMap "image info" \m -> do path <- m .: "path" download <- m .:? "download" nsfw <- m .:? "nsfw" .!= False warning <- m .:? "warning" - pure $ Image {label = "", path, download, nsfw, warning} + pure $ Image {label = pathToLabel path, path, download, nsfw, warning} + pathToLabel = Text.pack . dashToSpace . takeBaseName + dashToSpace = map \case '-' -> ' '; c -> c instance FromYAML Link where parseYAML y = do