module RSS (make, make') where import Date import Info import BuilderQQ import Records () import Data.List (sortOn) import Data.Maybe (isJust) import Data.Ord (Down (..)) import qualified Data.Text as Strict import qualified Data.Text.Lazy as Lazy import System.FilePath (takeDirectory) make :: Strict.Text -- ^ website root e.g. @https://gallery.niss.website@ -> GalleryInfo -> Maybe FilePath -- ^ output filename for self link -> [(FilePath, Info)] -> Lazy.Text make root ginfo output infos = toLazyText $ make' root ginfo output infos make' :: Strict.Text -> GalleryInfo -> Maybe FilePath -> [(FilePath, Info)] -> Builder make' root (GalleryInfo {title, desc, prefix}) output infos = [b|@0 $title $link $desc $selflink $4.items |] where link = [b|$root/$prefix|] items = map (uncurry $ makeItem root prefix) $ sortOn (Down . #second) infos selflink = case output of Nothing -> "" Just o -> [b||] makeItem :: Strict.Text -> FilePath -> FilePath -> Info -> Builder makeItem root prefix path (Info {title, desc, date, artist}) = [b|@4 $title $link $link $descArtist' $date' |] where dir = takeDirectory path link = [b|$root/$prefix/$dir|] artist' = ifJust artist \case Artist {name, url = Nothing} -> [b|

by $name|] Artist {name, url = Just url} -> [b|

by $name|] desc' = ifJust desc \d -> [b|$10.d|] descArtist' = if isJust desc || isJust artist then [b|@6 |] else "" date' = formatRSS date