From e8543433174c5fd64ec380719cae508192cf4ff6 Mon Sep 17 00:00:00 2001 From: Zachary Juang Date: Tue, 28 Nov 2023 16:41:33 -0500 Subject: [PATCH] more better rss --- app/Lib/Rss/Attributes.hs | 15 +++++++++++++++ app/Main.hs | 6 ++++-- haskell-blog.cabal | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 app/Lib/Rss/Attributes.hs diff --git a/app/Lib/Rss/Attributes.hs b/app/Lib/Rss/Attributes.hs new file mode 100644 index 0000000..20f30b1 --- /dev/null +++ b/app/Lib/Rss/Attributes.hs @@ -0,0 +1,15 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Lib.Rss.Attributes ( + module Text.Blaze, + module Lib.Rss.Attributes, +) where + +import Text.Blaze +import Text.Blaze.Internal + +href :: AttributeValue -> Attribute +href = attribute "href" "href=\"" + +rel :: AttributeValue -> Attribute +rel = attribute "rel" "rel=\"" diff --git a/app/Main.hs b/app/Main.hs index 6110565..9f96e56 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -31,6 +31,7 @@ import Lib.Blaze import Lib.Database import Lib.Middleware import Lib.Rss +import Lib.Rss.Attributes qualified as RA import Lib.Types import Network.HTTP.Types import Network.Socket as S @@ -461,16 +462,17 @@ main = do rssXml $ do xmlHeader - rss $ do + rss . channel $ do title "ThoughtBank Blog" link "http://localhost:5173" + atomLink RA.! RA.href "http://localhost:5173/posts/feed" RA.! RA.rel "self" description "Thoughts and concerns from my programming journey." language "en-us" forM_ posts $ \p -> item $ do let l = toRss $ "http://localhost:5173/posts/" <> show (postId p) title . toRss $ postTitle p - pubDate . toRss . formatTime defaultTimeLocale "%a, %e %b %Y %R %z" $ postUpdated p + pubDate . toRss . formatTime defaultTimeLocale "%a, %d %b %Y %R %z" $ postUpdated p link l guid l description . cdata . mdToHtml $ postBody p diff --git a/haskell-blog.cabal b/haskell-blog.cabal index 14d8123..513e95f 100644 --- a/haskell-blog.cabal +++ b/haskell-blog.cabal @@ -64,6 +64,7 @@ executable haskell-blog other-modules: Lib.Blaze, Lib.Database, Lib.Rss, + Lib.Rss.Attributes, Lib.Middleware, Lib.Types