Properly link off to posts in Atom feed; include post content in feed
This commit is contained in:
		| @ -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 | ||||
|  | ||||
| @ -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) | ||||
|   } | ||||
|  | ||||
| @ -67,10 +67,12 @@ feed postNames = do | ||||
|       makePost :: String -> FilePath -> IO (Post) | ||||
|       makePost baseUrl postName = do  | ||||
|         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 | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
		Reference in New Issue
	
	Block a user