Properly link off to posts in Atom feed; include post content in feed

This commit is contained in:
James Eversole 2024-02-28 12:33:11 -06:00
parent 676aea2a99
commit 3d5e4db7d8
4 changed files with 15 additions and 3 deletions

View File

@ -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

View File

@ -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)
}

View File

@ -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

View File

@ -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