cleanup a little

This commit is contained in:
rhiannon morris 2024-08-18 06:35:06 +02:00
parent fa0b826c26
commit 47d0d6a2cb

View file

@ -10,6 +10,7 @@ import Data.Function (on)
import qualified Data.Text as Strict
import qualified Data.Text.Lazy as Lazy
import System.FilePath (takeDirectory)
import Control.Monad
make :: Strict.Text -- ^ website root e.g. @https://gallery.niss.website@
@ -47,9 +48,9 @@ make' root name ginfo@(GalleryInfo {title, desc, prefix}) output infos = [b|@0
Just o -> [b|<link href="$link/$o" rel="self" />|]
makeItem :: Strict.Text -> FilePath -> Bool -> FilePath -> Info -> Builder
makeItem root prefix nsfw path i@(Info {title, artist}) = [b|@4
makeItem root prefix nsfw path info@(Info {title}) = [b|@4
<item>
<title>$title$suf</title>
<title>$title$suffix</title>
<link>$link</link>
<guid>$link</guid>
$body
@ -57,46 +58,39 @@ makeItem root prefix nsfw path i@(Info {title, artist}) = [b|@4
</item>
|]
where
suf = let parts = catMaybes [o18, cnt, up] in
if null parts then ""
body = [b|@6
<description> <![CDATA[
$8.image
$8.artist
$8.desc
]]> </description>
|]
suffix = if null parts then ""
else " (" <> mconcat (intersperse ", " parts) <> ")"
up = if hasUpdatesFor nsfw i then Just "updated" else Nothing
o18 = if nsfw && anyNsfw i then Just "🔞" else Nothing
cnt = let len = maybe 0 length $ allImages <$> imagesFor nsfw i in
if len == 1 then Nothing else Just [b|$len images|]
parts = catMaybes [o18, cnt, up]
up = do guard $ hasUpdatesFor nsfw info; Just "updated"
o18 = do guard $ nsfw && anyNsfw info; Just "🔞"
cnt = do let len = maybe 0 length $ allImages <$> imagesFor nsfw info
guard $ len /= 1; Just [b|$len images|]
dir = takeDirectory path
link = [b|$root/$prefix/$dir|]
date = formatRSS $ latestDateFor nsfw i
artist' = ifJust artist \case
Artist {name, url = Nothing} -> [b|<p>by $name|]
Artist {name, url = Just url} -> [b|<p>by <a href="$url">$name</a>|]
desc = descFor nsfw i
desc' = makeDesc desc
date = formatRSS $ latestDateFor nsfw info
artist = ifJust info.artist \case
Artist name Nothing -> [b|<p>by $name|]
Artist name (Just url) -> [b|<p>by <a href="$url">$name</a>|]
desc = makeDesc $ descFor nsfw info
body = [b|@6
<description> <![CDATA[
$8.image
$8.artist'
$8.desc'
]]> </description>
|]
image = case previewImage i of
Just (PFull img) -> go $ pageFile img
Just (PThumb th) -> go $ thumbFile th
image = case previewImage info of
Just (PFull img) -> figure $ pageFile img
Just (PThumb th) -> figure $ thumbFile th
Nothing -> ""
where go p = [b|@0
<figure>
<a href="$link"><img src="$link/$p"></a>
</figure>
|]
figure p = [b|<figure> <a href="$link"><img src="$link/$p"></a> </figure>|]
makeDesc :: Desc -> Builder
makeDesc NoDesc = ""
makeDesc (TextDesc txt) = [b|$txt|]
makeDesc (LongDesc fs) = [b|<dl>$fields</dl>|]
where
fields = map makeField fs
makeField (DescField {name, text}) = [b|<dt>$name <dd>$text|]
where fields = map (\(DescField {name, text}) -> [b|<dt>$name <dd>$text|]) fs