- head_ style
- body_ content
-
- where
- style = link_ [Attribute "rel" "stylesheet", Attribute "href" "style.css"]
-
-render :: String -> ActionM (Html ())
-render post = do
- let name = "posts" </> post <.> ".md"
- markdown <- T.toStrict <$> liftIO (T.readFile name)
- case M.parse name markdown of
- Left e -> return "shit"
- Right doc -> return $ M.render (M.useExtensions extensions doc)
+ head_ $ style >> title_ "Post"
+ body_ $ do
+ p_ $ a_ [href_ "/"] "Home"
+ content
+
+style = link_ [Attribute "rel" "stylesheet", Attribute "href" "/style.css"]
+
+data Post = Post
+ { markdown :: T.Text
+ , title :: T.Text
+ , date :: UTCTime
+ , author :: T.Text
+ } deriving (Read, Show)
+
+load :: String -> IO (Maybe Post)
+load name = do
+ let file = "posts" </> name
+ guard =<< doesFileExist file
+ readMaybe <$> readFile file
+
+render :: Post -> Maybe (Html ())
+render p@(Post markdown title date author) =
+ case M.parse (pathToPost p) (T.toStrict markdown) of
+ Left e -> Nothing
+ Right doc -> Just $
+ with div_ [id_ (T.toStrict title)] $ do
+ with a_ [href_ (T.toStrict $ linkToPost p)] $
+ h1_ $ toHtml title
+ i_ $ toHtml $ "By " <> author <> ", " <> dateStr
+ br_ []
+ M.render (M.useExtensions extensions doc)