Properly link off to posts in Atom feed; include post content in feed
This commit is contained in:
parent
676aea2a99
commit
3d5e4db7d8
@ -1,6 +1,6 @@
|
|||||||
cabal-version: 3.0
|
cabal-version: 3.0
|
||||||
name: sampu
|
name: sampu
|
||||||
version: 0.7.0
|
version: 0.8.0
|
||||||
license: ISC
|
license: ISC
|
||||||
author: James Eversole
|
author: James Eversole
|
||||||
maintainer: james@eversole.co
|
maintainer: james@eversole.co
|
||||||
|
@ -11,6 +11,7 @@ import Text.XML (def, rsPretty)
|
|||||||
|
|
||||||
data Post = Post { _date :: Text
|
data Post = Post { _date :: Text
|
||||||
, _url :: Text
|
, _url :: Text
|
||||||
|
, _title :: Text
|
||||||
, _content :: Text
|
, _content :: Text
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,4 +25,7 @@ renderFeed = fromJust . Export.textFeedWith def{rsPretty = True} . AtomFeed
|
|||||||
|
|
||||||
-- Convert a Post to an Atom Entry
|
-- Convert a Post to an Atom Entry
|
||||||
toEntry :: Post -> 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)
|
||||||
|
}
|
||||||
|
@ -67,10 +67,12 @@ feed postNames = do
|
|||||||
makePost :: String -> FilePath -> IO (Post)
|
makePost :: String -> FilePath -> IO (Post)
|
||||||
makePost baseUrl postName = do
|
makePost baseUrl postName = do
|
||||||
date <- getModificationTime $ "./data/posts/" ++ postName ++ ".md"
|
date <- getModificationTime $ "./data/posts/" ++ postName ++ ".md"
|
||||||
|
postContent <- mdFileToText $ "./data/posts/" ++ postName ++ ".md"
|
||||||
return $ Post
|
return $ Post
|
||||||
(pack $ (timeFormat date) ++ " UTC")
|
(pack $ (timeFormat date) ++ " UTC")
|
||||||
(pack $ baseUrl ++ "/posts/" ++ postName)
|
(pack $ baseUrl ++ "/posts/" ++ postName)
|
||||||
(pack $ show postName)
|
(pack $ show postName)
|
||||||
|
(postContent)
|
||||||
|
|
||||||
-- YYYY-MM-DD HH:MM | 2024-02-24 16:36
|
-- YYYY-MM-DD HH:MM | 2024-02-24 16:36
|
||||||
timeFormat :: UTCTime -> String
|
timeFormat :: UTCTime -> String
|
||||||
|
@ -5,6 +5,7 @@ import Data.ByteString.Lazy (ByteString)
|
|||||||
import qualified Data.ByteString as B
|
import qualified Data.ByteString as B
|
||||||
import Data.Text
|
import Data.Text
|
||||||
import Data.Text.Encoding (decodeUtf8)
|
import Data.Text.Encoding (decodeUtf8)
|
||||||
|
import Data.Text.Lazy (toStrict)
|
||||||
import qualified Lucid as LU
|
import qualified Lucid as LU
|
||||||
import System.IO ()
|
import System.IO ()
|
||||||
|
|
||||||
@ -18,3 +19,8 @@ mdToLucid cmtextinput = case (commonmark "" cmtextinput) of
|
|||||||
|
|
||||||
mdFileToLucid :: FilePath -> IO (LU.Html ())
|
mdFileToLucid :: FilePath -> IO (LU.Html ())
|
||||||
mdFileToLucid path = fmap (mdToLucid . decodeUtf8) (B.readFile path)
|
mdFileToLucid path = fmap (mdToLucid . decodeUtf8) (B.readFile path)
|
||||||
|
|
||||||
|
mdFileToText :: FilePath -> IO (Text)
|
||||||
|
mdFileToText path = do
|
||||||
|
htmlContent <- mdFileToLucid path
|
||||||
|
return $ toStrict $ LU.renderText htmlContent
|
||||||
|
Loading…
x
Reference in New Issue
Block a user