add more details (and the image‼) to rss
This commit is contained in:
parent
969cdc938d
commit
fa0b826c26
5 changed files with 69 additions and 45 deletions
|
@ -4,8 +4,8 @@ import Date
|
|||
import Info
|
||||
import BuilderQQ
|
||||
|
||||
import Data.List (sortBy)
|
||||
import Data.Maybe (isJust)
|
||||
import Data.List (sortBy, intersperse)
|
||||
import Data.Maybe (catMaybes)
|
||||
import Data.Function (on)
|
||||
import qualified Data.Text as Strict
|
||||
import qualified Data.Text.Lazy as Lazy
|
||||
|
@ -13,20 +13,21 @@ import System.FilePath (takeDirectory)
|
|||
|
||||
|
||||
make :: Strict.Text -- ^ website root e.g. @https://gallery.niss.website@
|
||||
-> Strict.Text -- ^ website name e.g. @nissart@
|
||||
-> GalleryInfo
|
||||
-> Maybe FilePath -- ^ output filename for self link
|
||||
-> [(FilePath, Info)]
|
||||
-> Lazy.Text
|
||||
make root ginfo output infos =
|
||||
toLazyText $ make' root ginfo output infos
|
||||
make root name ginfo output infos =
|
||||
toLazyText $ make' root name ginfo output infos
|
||||
|
||||
make' :: Strict.Text -> GalleryInfo
|
||||
make' :: Strict.Text -> Strict.Text -> GalleryInfo
|
||||
-> Maybe FilePath -> [(FilePath, Info)] -> Builder
|
||||
make' root ginfo@(GalleryInfo {title, desc, prefix}) output infos = [b|@0
|
||||
make' root name ginfo@(GalleryInfo {title, desc, prefix}) output infos = [b|@0
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>$title</title>
|
||||
<title>$name—$title</title>
|
||||
<link>$link</link>
|
||||
<description>$desc</description>
|
||||
$selflink
|
||||
|
@ -43,37 +44,54 @@ make' root ginfo@(GalleryInfo {title, desc, prefix}) output infos = [b|@0
|
|||
filter (not . (.unlisted) . snd) infos
|
||||
selflink = case output of
|
||||
Nothing -> ""
|
||||
Just o -> [b|<atom:link href="$link/$o" rel="self" />|]
|
||||
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
|
||||
<item>
|
||||
<title>$title$up</title>
|
||||
<title>$title$suf</title>
|
||||
<link>$link</link>
|
||||
<guid>$link</guid>
|
||||
$descArtist'
|
||||
$body
|
||||
<pubDate>$date</pubDate>
|
||||
</item>
|
||||
|]
|
||||
where
|
||||
up = if hasUpdatesFor nsfw i then [b| (updated)|] else ""
|
||||
suf = let parts = catMaybes [o18, cnt, up] in
|
||||
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|]
|
||||
|
||||
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>|]
|
||||
Artist {name, url = Just url} -> [b|<p>by <a href="$url">$name</a>|]
|
||||
desc = descFor nsfw i
|
||||
desc' = makeDesc desc
|
||||
descArtist' = if desc.exists || isJust artist then [b|@6
|
||||
<description>
|
||||
<![CDATA[
|
||||
$10.artist'
|
||||
$10.desc'
|
||||
]]>
|
||||
</description>
|
||||
|
||||
body = [b|@6
|
||||
<description> <![CDATA[
|
||||
$8.image
|
||||
$8.artist'
|
||||
$8.desc'
|
||||
]]> </description>
|
||||
|]
|
||||
else ""
|
||||
date = formatRSS $ latestDateFor nsfw i
|
||||
|
||||
image = case previewImage i of
|
||||
Just (PFull img) -> go $ pageFile img
|
||||
Just (PThumb th) -> go $ thumbFile th
|
||||
Nothing -> ""
|
||||
where go p = [b|@0
|
||||
<figure>
|
||||
<a href="$link"><img src="$link/$p"></a>
|
||||
</figure>
|
||||
|]
|
||||
|
||||
makeDesc :: Desc -> Builder
|
||||
makeDesc NoDesc = ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue