Tinkered with templates compiling, no need for runGHC.
Issue created #20 to address the feature.
This commit is contained in:
parent
60097556ef
commit
c3d2bdad2e
4 changed files with 51 additions and 9 deletions
26
app/Main.hs
26
app/Main.hs
|
@ -11,9 +11,11 @@ import Text.Blaze.Html
|
|||
import Components
|
||||
import Core.Compilers
|
||||
import Core.Render ( )
|
||||
import Core.Routers
|
||||
import Core.Rules
|
||||
import Routes
|
||||
import Utils.FileTree
|
||||
import Utils.Routes
|
||||
|
||||
import Kit.Templates.Index ( indexTemplate )
|
||||
import Kit.Templates.Post ( postTemplate )
|
||||
|
@ -41,21 +43,27 @@ main = hakyll $ do
|
|||
>>= compileTemplateItem
|
||||
>>= makeItem
|
||||
|
||||
match' (Post "*.md") $ do
|
||||
match (patrn $ Post "*.md") $ do
|
||||
route $ setExtension "html"
|
||||
compile
|
||||
$ pandocCompiler
|
||||
>>= saveSnapshot "content"
|
||||
>>= loadAndApplyTemplate "src/Kit/Templates/Post.hs" defaultContext
|
||||
. fmap demoteHeaders
|
||||
compile $ do
|
||||
pandocCompiler
|
||||
>>= saveSnapshot "content"
|
||||
>>= componentTemplate postTemplate defaultContext
|
||||
. fmap demoteHeaders
|
||||
|
||||
tags <- buildTags (patrn $ Post "*.md") (fromCapture . patrn $ Tag "*")
|
||||
|
||||
create ["index.html"] $ do
|
||||
route idRoute
|
||||
compile $ do
|
||||
pages <- recentFirst =<< loadAllSnapshots "posts/*.md" "content"
|
||||
let ctx = listField "pages"
|
||||
(defaultContext <> teaserField "teaser" "content")
|
||||
(return pages)
|
||||
let ctx = listField
|
||||
"pages"
|
||||
( teaserField "teaser" "content"
|
||||
<> tagsField "tags" tags
|
||||
<> defaultContext
|
||||
)
|
||||
(return pages)
|
||||
makeItem "" >>= loadAndApplyTemplate "src/Kit/Templates/Index.hs" ctx
|
||||
|
||||
create [cssHash] $ do
|
||||
|
|
|
@ -3,6 +3,7 @@ title: Atomic design in Haskell using Hakyll, Blaze and Clay
|
|||
tags: web, haskell, hakyll, atomic-design
|
||||
description: An overview of the framework I use to make this site.
|
||||
date: 2023-06-20
|
||||
updated: 2023-06-21
|
||||
---
|
||||
|
||||
This post presents an overview of the mechanics I use to develop a pure Haskell framework that is atomic design compliant. I intend to write no `html` file, no `css` file and no `js` file, only `hs`. It uses [Hakyll](https://hackage.haskell.org/package/hakyll) to compile the site, [Blaze](https://hackage.haskell.org/package/blaze-html) to generate HTML and [Clay](https://hackage.haskell.org/package/clay) to generate CSS.
|
||||
|
@ -119,6 +120,20 @@ main = hakyll $ do
|
|||
compile $ compileHs
|
||||
```
|
||||
|
||||
**EDIT**: (2023-06-21) Actually, no need to make those main functions. Something like
|
||||
|
||||
```haskell
|
||||
import Text.Blaze.Html.Renderer.Pretty
|
||||
import Hakyll
|
||||
|
||||
main :: IO ()
|
||||
main = hakyll $ do
|
||||
create ["myUl.html"] $ do
|
||||
route idRoute
|
||||
compile $ makeItem (renderHtml someHtml) -- someHtml :: Html
|
||||
```
|
||||
will work just fine.
|
||||
|
||||
# Creating components suited for atomic design
|
||||
|
||||
## Overview of the problem
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
module Core.Compilers
|
||||
( runGHC
|
||||
, componentTemplate
|
||||
) where
|
||||
|
||||
import Components
|
||||
import Core.Render ( )
|
||||
import Hakyll
|
||||
import Text.Blaze.Html
|
||||
|
||||
-- Redundant... Those default extensions should be kept in sync with package.yaml, but `stack runghc` won't take those in account.
|
||||
defaultExtensions :: [String]
|
||||
|
@ -12,3 +16,9 @@ defaultExtensions =
|
|||
runGHC :: Compiler (Item String)
|
||||
runGHC = getResourceString
|
||||
>>= withItemBody (unixFilter "stack" $ "runghc" : defaultExtensions)
|
||||
|
||||
componentTemplate
|
||||
:: Component Html -> Context a -> Item a -> Compiler (Item String)
|
||||
componentTemplate comp ctx itm = do
|
||||
tpl <- compileTemplateItem =<< makeItem (show . getHtml $ comp)
|
||||
applyTemplate tpl ctx itm
|
||||
|
|
9
src/Utils/Routes.hs
Normal file
9
src/Utils/Routes.hs
Normal file
|
@ -0,0 +1,9 @@
|
|||
module Utils.Routes
|
||||
( patrn
|
||||
) where
|
||||
|
||||
import Hakyll
|
||||
import Routes
|
||||
|
||||
patrn :: Route -> Pattern
|
||||
patrn = fromGlob . tail . path
|
Loading…
Reference in a new issue