added a function for future convenience with mustache

This commit is contained in:
Pagwin 2025-12-30 00:45:42 -05:00
parent 27e08cbc7a
commit 8bc5c481c1
No known key found for this signature in database
GPG key ID: 81137023740CA260
2 changed files with 6 additions and 0 deletions

View file

@ -3,6 +3,7 @@
- https://github.com/wereHamster/haskell-css-syntax - https://github.com/wereHamster/haskell-css-syntax
- JS - JS
- Doing our own tokenizer lol - Doing our own tokenizer lol
- [ ] swap from using `draft` to using `date` for determing draft status, lack of date = draft
- [ ] setup fingerprinting in file names for css and js - [ ] setup fingerprinting in file names for css and js
- setup lambdas via: https://hackage-content.haskell.org/package/mustache-2.4.3.1/docs/Text-Mustache.html#v:overText - setup lambdas via: https://hackage-content.haskell.org/package/mustache-2.4.3.1/docs/Text-Mustache.html#v:overText
- This may require a refactor of how we handle templates to use `object` instead of just using aeson integration from the mustache crate - This may require a refactor of how we handle templates to use `object` instead of just using aeson integration from the mustache crate

View file

@ -2,6 +2,7 @@ module Templates where
import Data.Aeson (ToJSON) import Data.Aeson (ToJSON)
import qualified Data.Aeson as A import qualified Data.Aeson as A
import Data.HashMap.Strict (insert)
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as T import qualified Data.Text as T
import Development.Shake import Development.Shake
@ -11,9 +12,13 @@ import GHC.Stack (HasCallStack)
import Text.Mustache (ToMustache) import Text.Mustache (ToMustache)
import qualified Text.Mustache as Mus import qualified Text.Mustache as Mus
import qualified Text.Mustache.Compile as Mus import qualified Text.Mustache.Compile as Mus
import qualified Text.Mustache.Types as Mus
import Types (Post (postAuthor, postContent, postDate, postDescription, postLink, postTags, postTitle), RenderedPost (RenderedPost, rPostAuthor, rPostContent, rPostDate, rPostHasTags, rPostId, rPostIsoDate, rPostLink, rPostSummary, rPostTags, rPostTitle)) import Types (Post (postAuthor, postContent, postDate, postDescription, postLink, postTags, postTitle), RenderedPost (RenderedPost, rPostAuthor, rPostContent, rPostDate, rPostHasTags, rPostId, rPostIsoDate, rPostLink, rPostSummary, rPostTags, rPostTitle))
import Utilities import Utilities
extend_with_lambda :: Mus.Object -> (Text, (Text -> Text)) -> Mus.Value
extend_with_lambda obj (key, val) = Mus.Object $ insert key (Mus.overText val) obj
applyTemplate :: (HasCallStack, (ToMustache a)) => String -> a -> Action Text applyTemplate :: (HasCallStack, (ToMustache a)) => String -> a -> Action Text
applyTemplate templateName context = do applyTemplate templateName context = do
tmpl <- readTemplate $ "templates" </> templateName tmpl <- readTemplate $ "templates" </> templateName