From 3d5e4db7d8954fc300b2dca6c1ad07cebee3d870 Mon Sep 17 00:00:00 2001 From: James Eversole Date: Wed, 28 Feb 2024 12:33:11 -0600 Subject: [PATCH] Properly link off to posts in Atom feed; include post content in feed --- sampu.cabal | 2 +- src/Core/Feed.hs | 6 +++++- src/Core/Handlers.hs | 4 +++- src/Core/Rendering.hs | 6 ++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/sampu.cabal b/sampu.cabal index 6d8fa8e..55896fc 100644 --- a/sampu.cabal +++ b/sampu.cabal @@ -1,6 +1,6 @@ cabal-version: 3.0 name: sampu -version: 0.7.0 +version: 0.8.0 license: ISC author: James Eversole maintainer: james@eversole.co diff --git a/src/Core/Feed.hs b/src/Core/Feed.hs index afac4f0..5a0c085 100644 --- a/src/Core/Feed.hs +++ b/src/Core/Feed.hs @@ -11,6 +11,7 @@ import Text.XML (def, rsPretty) data Post = Post { _date :: Text , _url :: Text + , _title :: Text , _content :: Text } @@ -24,4 +25,7 @@ renderFeed = fromJust . Export.textFeedWith def{rsPretty = True} . AtomFeed -- Convert a Post to an Atom Entry toEntry :: Post -> Atom.Entry -toEntry (Post date url content) = (Atom.nullEntry url (Atom.TextString content) date) +toEntry (Post date url title content) = (Atom.nullEntry url (Atom.TextString title) date) + { Atom.entryLinks = [Atom.nullLink url] + , Atom.entryContent = Just (Atom.HTMLContent content) + } diff --git a/src/Core/Handlers.hs b/src/Core/Handlers.hs index d4f2dac..9b589a5 100644 --- a/src/Core/Handlers.hs +++ b/src/Core/Handlers.hs @@ -66,11 +66,13 @@ feed postNames = do -- Create an Atom Post for each markdown post present makePost :: String -> FilePath -> IO (Post) makePost baseUrl postName = do - date <- getModificationTime $ "./data/posts/" ++ postName ++ ".md" + date <- getModificationTime $ "./data/posts/" ++ postName ++ ".md" + postContent <- mdFileToText $ "./data/posts/" ++ postName ++ ".md" return $ Post (pack $ (timeFormat date) ++ " UTC") (pack $ baseUrl ++ "/posts/" ++ postName) (pack $ show postName) + (postContent) -- YYYY-MM-DD HH:MM | 2024-02-24 16:36 timeFormat :: UTCTime -> String diff --git a/src/Core/Rendering.hs b/src/Core/Rendering.hs index 85141b6..cc4ff54 100644 --- a/src/Core/Rendering.hs +++ b/src/Core/Rendering.hs @@ -5,6 +5,7 @@ import Data.ByteString.Lazy (ByteString) import qualified Data.ByteString as B import Data.Text import Data.Text.Encoding (decodeUtf8) +import Data.Text.Lazy (toStrict) import qualified Lucid as LU import System.IO () @@ -18,3 +19,8 @@ mdToLucid cmtextinput = case (commonmark "" cmtextinput) of mdFileToLucid :: FilePath -> IO (LU.Html ()) mdFileToLucid path = fmap (mdToLucid . decodeUtf8) (B.readFile path) + +mdFileToText :: FilePath -> IO (Text) +mdFileToText path = do + htmlContent <- mdFileToLucid path + return $ toStrict $ LU.renderText htmlContent