refactor makeButtonBar

This commit is contained in:
Rhiannon Morris 2020-07-25 13:58:53 +02:00
parent 97c2bc4cd3
commit b5973a60d5
1 changed files with 8 additions and 8 deletions

View File

@ -31,7 +31,7 @@ make nsfw dir = toLazyText . make' nsfw dir
make' :: Bool -> FilePath -> Info -> Builder
make' nsfw dir (Info {date, title, artist, tags, nsfwTags,
desc, nsfwDesc, images, links}) = [b|@0
desc, nsfwDesc, images = allImages, links}) = [b|@0
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
@ -76,9 +76,12 @@ make' nsfw dir (Info {date, title, artist, tags, nsfwTags,
where
artistTag = ifJust artist makeArtist
images | nsfw = allImages
| otherwise = filter #sfw allImages
formattedDate = formatDate date
buttonBar = makeButtonBar title nsfw images
buttonBar = makeButtonBar title images
image0 = head images
path0 = #path image0
download0 = fromMaybe path0 (#download image0)
@ -121,8 +124,8 @@ formatDate :: Day -> Builder
formatDate d =
let str = formatTime defaultTimeLocale "%e %#B %Y" d in [b|$@str|]
makeButtonBar :: Strict.Text -> Bool -> [Image] -> Builder
makeButtonBar title nsfw allImages =
makeButtonBar :: Strict.Text -> [Image] -> Builder
makeButtonBar title images =
case length images of
0 -> throw $ NoEligibleImages title
1 -> ""
@ -133,10 +136,7 @@ makeButtonBar title nsfw allImages =
</ul>
</nav>
|]
where
images | nsfw = allImages
| otherwise = filter #sfw allImages
alts = map (uncurry altButton) $ zip [0..] images
where alts = map (uncurry altButton) $ zip [0..] images
altButton :: Int -> Image -> Builder
altButton i (Image {label, path, nsfw, warning}) = [b|@6