From 769e4e9996c2615aee573c50e52dbcfe10d87084 Mon Sep 17 00:00:00 2001 From: Justin Reardon Date: Wed, 22 Jul 2026 22:01:52 -0400 Subject: [PATCH 1/2] Show latest blog posts on the home page - update the blog post directive to allow an optional # of posts - show the latest 3 posts on the main page --- build.scala | 29 ++++++++++++++++------------- src/templates/home.template.html | 31 ++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/build.scala b/build.scala index d2df3c58..8f254c84 100644 --- a/build.scala +++ b/build.scala @@ -253,22 +253,25 @@ object LaikaCustomizations { TemplateDirectives.eval("forBlogPosts") { import TemplateDirectives.dsl.* - (cursor, parsedBody, source).mapN { (c, b, s) => - def contentScope(value: ConfigValue) = - TemplateScope(TemplateSpanSequence(b), value, s) + val count = attribute(0).as[Int].optional - val posts = c.parent.allDocuments.flatMap { d => - d.config.get[OffsetDateTime]("date").toList.tupleLeft(d) - } + (count, cursor, parsedBody, source).mapN { (count, c, b, s) => + def contentScope(value: ConfigValue) = + TemplateScope(TemplateSpanSequence(b), value, s) - posts - .sortBy(_._2)(using summon[Ordering[OffsetDateTime]].reverse) - .traverse { (d, _) => - d.config.get[ConfigValue]("").map(contentScope(_)) + val posts = c.parent.allDocuments.flatMap { d => + d.config.get[OffsetDateTime]("date").toList.tupleLeft(d) } - .leftMap(_.message) - .map(TemplateSpanSequence(_)) - } + + posts + .sortBy(_._2)(using summon[Ordering[OffsetDateTime]].reverse) + .take(count.getOrElse(Int.MaxValue)) + .traverse { (d, _) => + d.config.get[ConfigValue]("").map(contentScope(_)) + } + .leftMap(_.message) + .map(TemplateSpanSequence(_)) + } }, TemplateDirectives.create("svg") { import TemplateDirectives.dsl.* diff --git a/src/templates/home.template.html b/src/templates/home.template.html index 4453921c..0df81910 100644 --- a/src/templates/home.template.html +++ b/src/templates/home.template.html @@ -20,11 +20,40 @@

- Typelevel is an ecosystem of Scala-based projects and a community of people united to foster an inclusive, welcoming, and safe + Typelevel is an ecosystem of Scala-based projects and a community of people united to foster an inclusive, + welcoming, and safe environment around functional programming.

+
+

+ Latest Blog Posts + @:svg(fa-square-rss) +

+ +
@:for(sponsors) From af7c17e1146f606345e5df078431f639f7e2f326 Mon Sep 17 00:00:00 2001 From: Justin Reardon Date: Wed, 22 Jul 2026 22:25:11 -0400 Subject: [PATCH 2/2] fix formatting --- build.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build.scala b/build.scala index 8f254c84..6124ce22 100644 --- a/build.scala +++ b/build.scala @@ -253,9 +253,8 @@ object LaikaCustomizations { TemplateDirectives.eval("forBlogPosts") { import TemplateDirectives.dsl.* - val count = attribute(0).as[Int].optional - - (count, cursor, parsedBody, source).mapN { (count, c, b, s) => + (attribute(0).as[Int].optional, cursor, parsedBody, source) + .mapN { (count, c, b, s) => def contentScope(value: ConfigValue) = TemplateScope(TemplateSpanSequence(b), value, s)