From a15d27a324e4e07e951ac3a2ec736c572d60c26f Mon Sep 17 00:00:00 2001 From: Pagwin Date: Mon, 22 Jul 2024 17:17:23 -0400 Subject: [PATCH] just need to turn template application into application+write or do something else --- app/Main.hs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/app/Main.hs b/app/Main.hs index b930357..e1d37ab 100755 --- a/app/Main.hs +++ b/app/Main.hs @@ -9,13 +9,16 @@ module Main where +import Control.Monad (forM) +import Data.List (sortOn) import Data.Text (Text) import Data.Time (UTCTime, defaultTimeLocale, formatTime, parseTimeM) import Deriving.Aeson import Deriving.Aeson.Stock (PrefixedSnake) -import Development.Shake (Action, Rules, (|%>), (~>)) +import Development.Shake (Action, Rules, (|%>), (~>), (%>)) import Development.Shake.FilePath (()) import qualified Data.HashMap.Strict as HM +import qualified Data.Ord as Ord import qualified Data.Text as T import qualified Development.Shake as Shake import qualified Development.Shake.FilePath as Shake @@ -53,9 +56,11 @@ buildSite = do buildRules :: Rules () buildRules = do + home assets pages posts + rss -- make a rule of the pattern outputDir/asset_name which copes from outputDir/../pages assets :: Rules () @@ -97,6 +102,27 @@ posts = map indexHtmlOutputPath postGlobs |%> \target -> do applyTemplateAndWrite "default.html" page target Shake.putInfo $ "Built " <> target <> " from " <> src +home :: Rules () +home = outputDir "index.html" %> \target -> do + postPaths <- Shake.getDirectoryFiles "" postGlobs + posts <- take 3 + . sortOn (Ord.Down . postDate) + <$> forM postPaths readPost + html <- applyTemplate "home.html" $ HM.singleton "posts" posts + + let page = Page (T.pack "Home") html + applyTemplateAndWrite "default.html" page target + Shake.putInfo $ "Built " <> target + +rss :: Rules () +rss = outputDir "index.xml" %> \target -> do + postPaths <- Shake.getDirectoryFiles "" postGlobs + posts <- sortOn (Ord.Down . postDate) <$> forM postPaths readPost + -- figure out how to convert this into applyTemplateAndWrite + feed <- applyTemplate "feed.xml" $ HM.singleton "posts" posts + + Shake.putInfo $ "Built " <> target + readPost :: FilePath -> Action Post readPost postPath = do date <- parseTimeM False defaultTimeLocale "%Y-%-m-%-d"