iso dates
This commit is contained in:
parent
a99f4aee1f
commit
3cb14be999
3 changed files with 12 additions and 16 deletions
|
@ -138,8 +138,8 @@ home =
|
|||
take 3
|
||||
. sortOn (Ord.Down . postDate)
|
||||
<$> forM postPaths readPost
|
||||
html <- applyTemplate "home.html" $ HM.singleton "posts" posts
|
||||
|
||||
let posts' = map fromPost posts
|
||||
html <- applyTemplate "home.html" $ HM.singleton "posts" posts'
|
||||
let page = Page (T.pack "Home") html
|
||||
applyTemplateAndWrite "default.html" page target
|
||||
Shake.putInfo $ "Built " <> target
|
||||
|
@ -149,7 +149,8 @@ postList =
|
|||
outputDir </> "posts/index.html" %> \target -> do
|
||||
postPaths <- getPublishedPosts
|
||||
posts <- sortOn (Ord.Down . postDate) <$> forM postPaths readPost
|
||||
html <- applyTemplate "posts.html" $ HM.singleton "posts" posts
|
||||
let posts' = map fromPost posts
|
||||
html <- applyTemplate "posts.html" $ HM.singleton "posts" posts'
|
||||
let page = Page (T.pack "Blog Posts") html
|
||||
applyTemplateAndWrite "default.html" page target
|
||||
Shake.putInfo $ "Built " <> target
|
||||
|
|
|
@ -11,10 +11,12 @@ import GHC.Stack (HasCallStack)
|
|||
import qualified Text.Mustache as Mus
|
||||
import qualified Text.Mustache.Compile as Mus
|
||||
import Types (Post (postAuthor, postContent, postDate, postLink, postTags, postTitle), RenderedPost (RenderedPost, rPostAuthor, rPostContent, rPostDate, rPostHasTags, rPostIsoDate, rPostLink, rPostTags, rPostTitle))
|
||||
import Utilities
|
||||
|
||||
applyTemplate :: (HasCallStack, (ToJSON a)) => String -> a -> Action Text
|
||||
applyTemplate templateName context = do
|
||||
tmpl <- readTemplate $ "templates" </> templateName
|
||||
-- liftIO $ print $ A.toJSON context
|
||||
case Mus.checkedSubstitute tmpl (A.toJSON context) of
|
||||
([], text) -> return text
|
||||
(errs, _) ->
|
||||
|
@ -51,7 +53,7 @@ fromPost post =
|
|||
rPostTags = postTags post,
|
||||
rPostHasTags = not . null . postTags $ post,
|
||||
rPostDate = postDate post,
|
||||
rPostIsoDate = postDate post,
|
||||
rPostIsoDate = postDate post >>= parseDate,
|
||||
rPostContent = postContent post,
|
||||
rPostLink = postLink post
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import Control.Monad (filterM)
|
|||
import Data.Aeson (Result (Error, Success))
|
||||
import qualified Data.Aeson as A
|
||||
import Data.List (find)
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Data.Time
|
||||
|
@ -133,17 +132,6 @@ yamlToPost path = do
|
|||
post <- decodeFileThrow path
|
||||
-- let post' = dateTransform post
|
||||
return post
|
||||
where
|
||||
dateTransform post@(Post {postDate}) = do
|
||||
postDate' <- postDate
|
||||
let postDate'' = dateStrTransform $ T.unpack postDate'
|
||||
Just
|
||||
post
|
||||
{ postDate = postDate''
|
||||
}
|
||||
dateStrTransform date = do
|
||||
date' <- parseTimeM False defaultTimeLocale "%Y-%-m-%-d" date
|
||||
Just $ T.pack $ formatTime @UTCTime defaultTimeLocale "%b %e, %Y" date'
|
||||
|
||||
isTypstPost :: FilePath -> Bool
|
||||
isTypstPost path = FP.takeExtension path == ".typ"
|
||||
|
@ -169,3 +157,8 @@ getPublishedPosts :: Action [FilePath]
|
|||
getPublishedPosts = do
|
||||
postPaths <- Shake.getDirectoryFiles "" postGlobs
|
||||
filterM (fmap not . isDraft) postPaths
|
||||
|
||||
parseDate :: Text -> Maybe Text
|
||||
parseDate str = do
|
||||
date <- parseTimeM False defaultTimeLocale "%Y-%-m-%-d" $ T.unpack str
|
||||
return $ T.pack $ formatTime @UTCTime defaultTimeLocale "%Y-%m-%d" date
|
||||
|
|
Loading…
Reference in a new issue