Skip to content

Commit e18ccd5

Browse files
Link to blog posts from home page
1 parent 15b6a45 commit e18ccd5

File tree

3 files changed

+38
-41
lines changed

3 files changed

+38
-41
lines changed

src/build.gleam

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import gleam/list
33
import lustre/element
44
import lustre/ssg
55
import website/data/blog
6-
import website/page/blog_home
76
import website/page/blog_post
87
import website/page/index
98

@@ -12,9 +11,8 @@ pub fn main() {
1211

1312
let build =
1413
ssg.new("./priv")
15-
|> ssg.add_static_route("/", index.view())
14+
|> ssg.add_static_route("/", index.view(posts))
1615
|> ssg.add_static_dir("./static")
17-
|> ssg.add_static_route("/blog/index", blog_home.view(posts))
1816
|> add_dynamic_routes(
1917
"/blog",
2018
posts,

src/website/page/blog_home.gleam

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/website/page/index.gleam

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import lustre/attribute
33
import lustre/element.{type Element}
44
import lustre/element/html
55
import website/component
6+
import website/data/blog
67

78
fn index() {
89
component.text_page("Hello and welcome to my website!", [
@@ -55,20 +56,45 @@ fn index() {
5556
])
5657
}
5758

58-
pub fn view() -> Element(a) {
59-
component.page("Home", [index(), my_stuff()])
59+
pub fn view(posts: List(blog.Post(_))) -> Element(_) {
60+
component.page("Home", [index(), my_stuff(posts)])
6061
}
6162

62-
pub fn my_stuff() {
63-
component.text_page("My Stuff", [
64-
html.h2([attribute.class("text-2xl font-bold leading-tight my-2")], [
65-
element.text("Links"),
66-
]),
67-
html.p([], list.map(socials, social)),
68-
html.h2([attribute.class("text-2xl font-bold leading-tight my-2")], [
69-
element.text("Talks"),
63+
pub fn my_stuff(posts: List(blog.Post(_))) -> component.Section(_) {
64+
component.text_page(
65+
"My Stuff",
66+
list.flatten([
67+
[
68+
html.h2([attribute.class("text-2xl font-bold leading-tight my-2")], [
69+
element.text("Links"),
70+
]),
71+
html.p([], list.map(socials, social)),
72+
html.h2([attribute.class("text-2xl font-bold leading-tight my-2")], [
73+
element.text("Posts"),
74+
]),
75+
],
76+
list.map(posts, post),
77+
[
78+
html.h2([attribute.class("text-2xl font-bold leading-tight my-2")], [
79+
element.text("Talks"),
80+
]),
81+
],
82+
list.map(talks, talk),
7083
]),
71-
..list.map(talks, talk)
84+
)
85+
}
86+
87+
fn post(post: blog.Post(_)) -> element.Element(_) {
88+
html.div([attribute.class("")], [
89+
html.a(
90+
[
91+
attribute.href("/blog/" <> post.slug),
92+
attribute.class("text-xl font-bold hover:underline"),
93+
],
94+
[html.text(post.title)],
95+
),
96+
html.p([attribute.class("text-sm m-0")], [element.text(post.date)]),
97+
html.p([attribute.class("text-md my-0.5")], [element.text(post.description)]),
7298
])
7399
}
74100

0 commit comments

Comments
 (0)