extra rss items for big updates

This commit is contained in:
rhiannon morris 2024-10-22 00:08:30 +02:00
parent 7328346502
commit 9ee9b17526
2 changed files with 21 additions and 10 deletions

View file

@ -7,7 +7,7 @@ module Info
allImages, sfwImages, nsfwImages,
thumb, latestDateFor, latestYearFor,
sfwLinks, nsfwLinks, sfwUpdates, nsfwUpdates,
updatesFor, hasUpdatesFor, lastUpdateFor,
updatesFor, bigUpdatesFor, hasUpdatesFor, lastUpdateFor,
tagsFor, descFor, imagesFor, linksFor,
CompareKey (..), compareKeyFor, compareFor, sortFor,
@ -182,6 +182,9 @@ updatesWith p i = mapMaybe (traverse $ filterNE p) i.updates
updatesFor :: Bool -> Info -> [(Date, NonEmpty Update)]
updatesFor nsfw = updatesWith \u -> nsfw || u.sfw
bigUpdatesFor :: Bool -> Info -> [(Date, NonEmpty Update)]
bigUpdatesFor nsfw = updatesWith \u -> not u.ignoreSort && (nsfw || u.sfw)
sfwUpdates, nsfwUpdates :: Info -> [(Date, NonEmpty Update)]
sfwUpdates = updatesWith (.sfw)
nsfwUpdates = updatesWith (.nsfw)

View file

@ -5,7 +5,7 @@ import Info
import BuilderQQ
import Data.List (sortBy, intersperse)
import Data.Maybe (catMaybes)
import Data.Maybe (catMaybes, fromMaybe)
import Data.Function (on)
import qualified Data.Text as Strict
import qualified Data.Text.Lazy as Lazy
@ -41,21 +41,28 @@ make' root name ginfo@(GalleryInfo {title, desc, prefix}) output infos = [b|
where
link = [b|$root/$prefix|]
nsfw = ginfo.nsfw
items = map (uncurry $ makeItem root prefix nsfw) $
items = concatMap (uncurry $ makeItems root prefix nsfw) $
sortBy (flip (compareFor nsfw `on` snd)) $
filter (not . (.unlisted) . snd) infos
selflink = case output of
Nothing -> ""
Just o -> [b|<atom:link href="$link/$o" rel="self" />|]
makeItem :: Strict.Text -> FilePath -> Bool -> FilePath -> Info -> Builder
makeItem root prefix nsfw path info@(Info {title}) = [b|
makeItems :: Strict.Text -> FilePath -> Bool -> FilePath -> Info -> [Builder]
makeItems root prefix nsfw path info =
makeItem root prefix nsfw path info Nothing :
map (makeItem root prefix nsfw path info . Just . fst)
(bigUpdatesFor nsfw info)
makeItem :: Strict.Text -> FilePath -> Bool -> FilePath ->
Info -> Maybe Date -> Builder
makeItem root prefix nsfw path info@(Info {title}) date = [b|
<item>
<title><![CDATA[$title$suffix]]></title>
<link>$link</link>
<guid>$link</guid>
<guid>$link$guidSuffix</guid>
<dc:creator><![CDATA[$creator]]></dc:creator>
<pubDate>$date</pubDate>
<pubDate>$dateStr</pubDate>
$body
</item>
|]
@ -70,8 +77,9 @@ makeItem root prefix nsfw path info@(Info {title}) = [b|
suffix = if null parts then ""
else " (" <> mconcat (intersperse ", " parts) <> ")"
guidSuffix = maybe "" (("?" <>) . show) date
parts = catMaybes [o18, cnt, up]
up = do guard $ hasUpdatesFor nsfw info; Just "updated"
up = "updated" <$ date
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|]
@ -81,7 +89,7 @@ makeItem root prefix nsfw path info@(Info {title}) = [b|
creator = maybe "niss" (.name) info.artist
date = formatRSS $ latestDateFor nsfw info
dateStr = formatRSS $ fromMaybe info.date date
artist = ifJust info.artist \case
Artist name Nothing -> [b|<p>by $name|]
Artist name (Just url) -> [b|<p>by <a href="$url">$name</a>|]