module Site.Feed where import Data.Default (def) import Data.List qualified as List import Data.Map.Strict qualified as Map import Data.Time qualified as Time import PyF import Relude import Text.Atom.Feed qualified as Atom import Text.Blaze.Html5 ((!)) import Text.Blaze.Html5 qualified as H import Text.Pandoc (runPure) import Text.Pandoc.Writers (writeHtml5String) import Prelude () import Site.Filter import Site.Lang import Site.Model import Site.Page import Site.Tag import Utils.Html mkFeed :: Model -> Filter -> Atom.Feed mkFeed model filt@Filter{..} = ( Atom.nullFeed (absoluteLink model (Left "")) --(absoluteLink model (Right (RouteFilterAtom filt))) (Atom.TextString [fmt|{orgName} - {feedTitle filt}|]) (atomTime . List.maximum . mapMaybe (metaUpdated . pageMeta) . Map.elems $ modelPosts model) ) { Atom.feedAuthors = one Atom.nullPerson { Atom.personName = orgName , Atom.personEmail = Just [fmt|contact@{domainName}|] } , --, Atom.feedIcon = Just $ absoluteLink model (Left "static/img/feedIcon.png") Atom.feedEntries = [ feedEntry post | post@(_slug, Page{..}) <- filterPosts model filt , isJust $ metaUpdated pageMeta ] , Atom.feedLinks = one $ Atom.nullLink [fmt|https://{domainName}|] , Atom.feedCategories = Atom.newCategory . unTag <$> maybeToList filterTag } where atomTime = toText . Time.formatTime Time.defaultTimeLocale "%Y-%m-%d" feedEntry (pageName, Page{..}) = ( Atom.nullEntry pageLink (Atom.TextString $ metaTitle pageMeta) (atomTime (fromMaybe (error "Pages without date") $ metaUpdated pageMeta)) ) { Atom.entryCategories = Atom.newCategory . unTag <$> metaTags pageMeta , Atom.entryLinks = one $ Atom.nullLink pageLink , Atom.entrySummary = Atom.TextString . markdownText <$> metaSummary pageMeta , Atom.entryContent = Just $ Atom.HTMLContent $ either (error . show) id $ runPure $ writeHtml5String def pageDoc } where pageLink = absoluteLink model $ Right $ RoutePage pageName feedList :: Model -> H.Html feedList model = do H.h2 ! classes ["text-blue-800", "text-xl"] $ "Feed of all posts" H.table ! classes ["my-2", "table-fixed", "w-full"] $ H.tr $ do icell "" forM_ (Nothing : (Just <$> [minBound ..])) $ \lang -> cell $ mkLink lang Nothing H.h2 ! classes ["text-blue-800", "text-xl"] $ "Feeds by tag" H.table ! classes ["my-2", "table-fixed", "w-full"] $ do forM_ (allTags model) $ \tag -> H.tr $ do icell (renderTag model True tag) forM_ (Nothing : (Just <$> [minBound ..])) $ \lang -> cell $ mkLink lang (Just tag) where mkLink lang tag = H.a ! classes [ "bg-gray-100" , "hover:underline" , "px-1" , "text-blue-800" ] ! hrefRoute model (RouteFilterAtom (Filter lang tag)) $ maybe "Any" langText lang cell = H.td ! classes ["text-right", "w-1/4"] icell = H.td ! classes ["text-left", "w-1/4"]