diff --git a/CHANGELOG.md b/CHANGELOG.md index 27ab5e6..d8bc342 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app/Main.hs b/app/Main.hs index 8695b53..1c79bb5 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -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 diff --git a/etienne-moqueur.cabal b/etienne-moqueur.cabal index dd95228..ce892ce 100644 --- a/etienne-moqueur.cabal +++ b/etienne-moqueur.cabal @@ -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 diff --git a/package.yaml b/package.yaml index 641e86e..f1cf28e 100644 --- a/package.yaml +++ b/package.yaml @@ -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" diff --git a/src/Kit/Atoms/Separators.hs b/src/Kit/Atoms/Separators.hs new file mode 100644 index 0000000..cb5b7de --- /dev/null +++ b/src/Kit/Atoms/Separators.hs @@ -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 diff --git a/src/Kit/Organisms/TagsFields.hs b/src/Kit/Organisms/TagsFields.hs deleted file mode 100644 index 0079990..0000000 --- a/src/Kit/Organisms/TagsFields.hs +++ /dev/null @@ -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) diff --git a/src/Kit/Templates/Archive.hs b/src/Kit/Templates/Archive.hs index 5e21a94..c8a4440 100644 --- a/src/Kit/Templates/Archive.hs +++ b/src/Kit/Templates/Archive.hs @@ -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$" + ] + ) ] diff --git a/src/Kit/Templates/Index.hs b/src/Kit/Templates/Index.hs index 20d5304..46ed492 100644 --- a/src/Kit/Templates/Index.hs +++ b/src/Kit/Templates/Index.hs @@ -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)