diff --git a/make-pages/Info.hs b/make-pages/Info.hs index 7c00e50..db4f3d9 100644 --- a/make-pages/Info.hs +++ b/make-pages/Info.hs @@ -95,7 +95,7 @@ instance FromYAML Info where <*> m .:? "tags" .!= [] <*> m .:? "nsfw-tags" .!= [] <*> m .:? "description" - <*> m .: "images" + <*> (m .: "images" >>= imageList) <*> m .:? "background" <*> m .:? "thumb" <*> m .:? "links" .!= [] @@ -106,18 +106,26 @@ instance FromYAML Artist where withUrl = YAML.withMap "full info" \m -> Artist <$> m .: "name" <*> m .:? "url" +imageList :: YAML.Node YAML.Pos -> YAML.Parser [Image] +imageList y = pure <$> unlabelledImage y <|> parseYAML y + instance FromYAML Image where - parseYAML y = do - Pair label rest <- parseYAML y - asStr label rest <|> asObj label rest - where - asStr label = YAML.withStr "path" \(Text.unpack -> path) -> - pure $ Image {label, path, nsfw = False, warning = Nothing} - asObj label = YAML.withMap "image info" \m -> do - path <- m .: "path" - nsfw <- m .:? "nsfw" .!= False - warning <- m .:? "warning" - pure $ Image {label, path, nsfw, warning} + parseYAML y = unlabelledImage y <|> labelled y where + labelled y' = do + Pair label rest <- parseYAML y' + i <- unlabelledImage rest + pure $ i {label} + +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} + asObj = YAML.withMap "image info" \m -> do + path <- m .: "path" + nsfw <- m .:? "nsfw" .!= False + warning <- m .:? "warning" + pure $ Image {label = "", path, nsfw, warning} instance FromYAML Link where parseYAML y = do