Skip to content

Commit 769e4e9

Browse files
committed
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
1 parent 07bfeca commit 769e4e9

2 files changed

Lines changed: 46 additions & 14 deletions

File tree

build.scala

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,22 +253,25 @@ object LaikaCustomizations {
253253
TemplateDirectives.eval("forBlogPosts") {
254254
import TemplateDirectives.dsl.*
255255

256-
(cursor, parsedBody, source).mapN { (c, b, s) =>
257-
def contentScope(value: ConfigValue) =
258-
TemplateScope(TemplateSpanSequence(b), value, s)
256+
val count = attribute(0).as[Int].optional
259257

260-
val posts = c.parent.allDocuments.flatMap { d =>
261-
d.config.get[OffsetDateTime]("date").toList.tupleLeft(d)
262-
}
258+
(count, cursor, parsedBody, source).mapN { (count, c, b, s) =>
259+
def contentScope(value: ConfigValue) =
260+
TemplateScope(TemplateSpanSequence(b), value, s)
263261

264-
posts
265-
.sortBy(_._2)(using summon[Ordering[OffsetDateTime]].reverse)
266-
.traverse { (d, _) =>
267-
d.config.get[ConfigValue]("").map(contentScope(_))
262+
val posts = c.parent.allDocuments.flatMap { d =>
263+
d.config.get[OffsetDateTime]("date").toList.tupleLeft(d)
268264
}
269-
.leftMap(_.message)
270-
.map(TemplateSpanSequence(_))
271-
}
265+
266+
posts
267+
.sortBy(_._2)(using summon[Ordering[OffsetDateTime]].reverse)
268+
.take(count.getOrElse(Int.MaxValue))
269+
.traverse { (d, _) =>
270+
d.config.get[ConfigValue]("").map(contentScope(_))
271+
}
272+
.leftMap(_.message)
273+
.map(TemplateSpanSequence(_))
274+
}
272275
},
273276
TemplateDirectives.create("svg") {
274277
import TemplateDirectives.dsl.*

src/templates/home.template.html

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,40 @@ <h2 class="bulma-subtitle bulma-is-3 bulma-is-size-4-mobile">
2020
<section class="bulma-hero bulma-is-primary bulma-has-text-light">
2121
<div class="bulma-hero-body">
2222
<p class="bulma-is-size-4 bulma-has-text-weight-medium">
23-
Typelevel is an ecosystem of Scala-based projects and a community of people united to foster an inclusive, welcoming, and safe
23+
Typelevel is an ecosystem of Scala-based projects and a community of people united to foster an inclusive,
24+
welcoming, and safe
2425
environment around functional programming.
2526
</p>
2627
</div>
2728
</section>
29+
<section class="bulma-section bulma-has-background-light bulma-has-text-light">
30+
<h2 class="bulma-title bulma-is-4 bulma-icon-text">
31+
Latest Blog Posts <a class="bulma-icon bulma-has-text-current" href="@:target(/blog/feed.rss)">
32+
@:svg(fa-square-rss)
33+
</a></h2>
34+
<div class="bulma-columns bulma-is-align-content-stretch bulma-is-flex-wrap-wrap">
35+
@:forBlogPosts(3)
36+
<a href="@:target(_.cursor.currentDocument.sourcePath)"
37+
class="bulma-column bulma-is-one-third bulma-is-flex bulma-is-flex-direction-column">
38+
<p class="bulma-is-6 bulma-has-text-grey">@:date(_.date, "MMMM d, yyyy")</p>
39+
<h3 class="bulma-title bulma-is-5">${_.cursor.currentDocument.title}</h3>
40+
<p class="blog-post-byline bulma-subtitle bulma-is-6 bulma-has-text-grey bulma-is-flex-grow-1">
41+
@:for(_.author)
42+
${_.name}<span class="delimiter">,</span><span class="last-delimiter"> &</span>
43+
@:@
44+
@:for(_.event-date)
45+
${_.event-date} at ${_.event-location}
46+
@:@
47+
</p>
48+
<p>
49+
@:for(_.tags)
50+
<span class="bulma-tag bulma-is-dark">${_}</span>
51+
@:@
52+
</p>
53+
</a>
54+
@:@
55+
</div>
56+
</section>
2857
<div class="bulma-section">
2958
<div class="bulma-columns bulma-is-vcentered bulma-is-flex-wrap-wrap bulma-is-justify-content-space-evenly">
3059
@:for(sponsors)

0 commit comments

Comments
 (0)