Tag support completed.

Archive page still needs a bit of styling. Declare tags in a post. Tags
are displayed in the blog card and populate the archive.
This commit is contained in:
Etienne Werly 2023-06-23 14:51:52 +02:00
parent 2c06b5851d
commit 2c02500b72
8 changed files with 72 additions and 54 deletions

View file

@ -18,6 +18,11 @@ and this project adheres to the
* Add font subsetting (or svg icons support / fonts)
* Add images utils such as conversion to png, avif and other formats (see hip and JuicyPixels)
## 0.2.1.0 - 2023-06-23
* Added tags support for posts
* `runGHC` *will* be removed
## 0.2.0.0 - 2023-06-19
* Added sitemap.xml

View file

@ -17,16 +17,14 @@ import Routes
import Utils.FileTree
import Utils.Routes
import Kit.Organisms.TagsFields
import Kit.Templates.Archive ( archiveTemplate )
import Kit.Templates.Index ( indexTemplate )
import Kit.Templates.Archive
import Kit.Templates.Index
import Kit.Templates.Post ( postTemplate )
import Kit.Templates.Sitemap
resources :: Component ()
resources = do
mconcat [postTemplate, indexTemplate, archiveTemplate]
tagsField'
return ()
assets :: [FilePath]
@ -58,27 +56,12 @@ main = hakyll $ do
route idRoute
compile $ do
pages <- recentFirst =<< loadAllSnapshots "posts/*.md" "content"
let ctx = listField
"pages"
( teaserField "teaser" "content"
<> getBody tagsField' "tags" tags
<> defaultContext
)
(return pages)
makeItem "" >>= componentTemplate indexTemplate ctx
makeItem "" >>= componentTemplate indexTemplate (indexCtx tags pages)
create ["tags/index.html"] $ do
route idRoute
compile $ do
let archiveCtx = listField "tagList" tagsCtx getAllTags
getAllTags = pure . map mkItem $ tagsMap tags
where mkItem x = Item (tagsMakeId tags (fst x)) x
tagsCtx =
listFieldWith "posts" defaultContext getPosts
<> mapContext (drop 1) (titleField "title")
<> missingField
getPosts itm = mapM load (snd . itemBody $ itm)
makeItem "" >>= componentTemplate archiveTemplate archiveCtx
compile $ makeItem "" >>= componentTemplate archiveTemplate
(archiveCtx tags)
create [cssHash] $ do
route $ constRoute . tail . path $ DefaultStylesheet

View file

@ -35,6 +35,7 @@ library
Kit.Atoms.Image
Kit.Atoms.Link
Kit.Atoms.Section
Kit.Atoms.Separators
Kit.Atoms.Stylesheet
Kit.Atoms.Typography
Kit.Constants.Breakpoints
@ -52,7 +53,6 @@ library
Kit.Organisms.Card
Kit.Organisms.Head
Kit.Organisms.ProfileHeader
Kit.Organisms.TagsFields
Kit.Templates.Archive
Kit.Templates.Index
Kit.Templates.Post

View file

@ -1,5 +1,5 @@
name: etienne-moqueur
version: 0.2.0.0
version: 0.2.1.0
license: BSD3
author: "etienne"
maintainer: "etienne@moqueur.chat"

View file

@ -0,0 +1,11 @@
module Kit.Atoms.Separators
( hr'
) where
import Clay as C
import Components
import Text.Blaze.Html5 as H
hr' :: Component Html
hr' = do
return H.hr

View file

@ -1,17 +0,0 @@
module Kit.Organisms.TagsFields
( tagsField'
) where
import Components
import Hakyll
import Kit.Molecules.Tag
import Routes
import Text.Blaze.Html
tagsField' :: Component (String -> Tags -> Context a)
tagsField' = do
tagSpan "" <*> pure "" -- temporary, remove when defining a tagSpanField
tagLink "" <*> pure ""
return $ tagsFieldWith getTags tagLinks mconcat
where
tagLinks tag _ = pure . getBody $ tagLink (Tag tag) <*> pure (toHtml tag)

View file

@ -1,24 +1,46 @@
module Kit.Templates.Archive
( archiveTemplate
( archiveCtx
, archiveTemplate
) where
import Clay as C
import Components
import Core.Render ( )
import Hakyll
import Kit.Atoms.Link
import Kit.Atoms.Section
import Kit.Atoms.Separators
import Kit.Molecules.Tag
import Kit.Organisms.TagsFields
import Kit.Organisms.Head
import Routes
import Text.Blaze.Html5 as H
import Text.Blaze.Html5.Attributes as A
archiveCtx :: Tags -> Context a
archiveCtx tags = listField "tagList" tagsCtx getAllTags
where
getAllTags = pure $ mkItem <$> tagsMap tags
mkItem x = Item (tagsMakeId tags (fst x)) x
tagsCtx = listFieldWith "posts" defaultContext getPosts
<> mapContext (drop 1) (titleField "tag")
getPosts itm = mapM load (snd . itemBody $ itm)
archiveTemplate :: Component Html
archiveTemplate = H.body <$> mconcat
[ pure "$for(tagList)$"
, tagSpan "$title$" <*> pure "$title$"
, pure H.ul <*> mconcat
[ pure "$for(posts)$"
, pure $ H.a H.! A.href "$url$" $ "$title$"
, pure "$endfor$"
]
, pure "$endfor$"
archiveTemplate = mconcat
[ docTypeHtml <$> defaultHead "Archive"
, H.body
<$> (section' <*> mconcat
[ pure $ h1 "Post archive"
, pure "$for(tagList)$"
, tagLink "#$tag$" <*> pure "$tag$"
, pure "$endfor$"
, hr'
, pure "$for(tagList)$"
, tagSpan "$tag$" <*> pure "$tag$"
, ul <$> mconcat
[ pure "$for(posts)$"
, li <$> (a' "$url$" <*> pure "$title$")
, pure "$endfor$"
]
, pure "$endfor$"
]
)
]

View file

@ -1,11 +1,14 @@
module Kit.Templates.Index
( indexTemplate
, indexCtx
) where
import Components
import Core.Render
import Hakyll
import Kit.Atoms.Section
import Kit.Molecules.Bricklayer
import Kit.Molecules.Tag
import Kit.Organisms.Card
import Kit.Organisms.Head
import Kit.Organisms.ProfileHeader
@ -29,6 +32,17 @@ indexBody =
[pure "$for(pages)$", blogCard dummy, pure "$endfor$"]
)
indexCtx :: Tags -> [Item String] -> Context String
indexCtx tags pages = listField
"pages"
( tagsFieldWith getTags tagLinks mconcat "tags" tags
<> teaserField "teaser" "content"
<> defaultContext
)
(return pages)
where
tagLinks tag _ = pure . getBody $ tagLink (Tag tag) <*> pure (toHtml tag)
indexTemplate :: Component Html
indexTemplate =
docTypeHtml <$> defaultHead "Very first try" <> (body <$> indexBody)