refactor makeButtonBar

This commit is contained in:
Rhiannon Morris 2020-07-25 13:58:53 +02:00
parent 97c2bc4cd3
commit b5973a60d5

View file

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