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