My personal website

Add option to unlist posts

fruno.win 07a9e1b6 46b547eb

verified
+35 -10
+9 -2
posts/2026-01-03-initial-commit.djot
··· 1 1 --- 2 - title = "Initial Commit" 2 + title = "making a blog for dummies" 3 + listed = false 3 4 --- 4 5 5 - # initial commit 6 + # this is an exampe for a draft! 6 7 7 8 This post is gonna detail how I made this site, but for now it's just a placeholder. 9 + Here's some `inline code` for ya. 8 10 9 11 ```css 10 12 main { 11 13 font-family: Myna; 12 14 } 13 15 ``` 16 + 17 + ```gleam 18 + fn wibble() -> Wobble { 19 + todo as "wibble!" 20 + }
+26 -8
src/blog.gleam
··· 1 1 import component 2 2 import gleam/list 3 + import gleam/result 3 4 import gleam/string 4 5 import lustre/attribute 5 6 import lustre/element.{type Element} ··· 9 10 import tom 10 11 11 12 pub type Post { 12 - Post(slug: String, title: String, content: String) 13 + Post(slug: String, title: String, content: String, listed: Bool) 13 14 } 14 15 15 16 const posts_dir = "./posts" ··· 31 32 as "Failed to read file" 32 33 let assert Ok(meta) = djot.metadata(content) as "Failed to read post metadata" 33 34 let assert Ok(title) = tom.get_string(meta, ["title"]) as "Missing post title" 35 + let listed = result.unwrap(tom.get_bool(meta, ["listed"]), True) 34 36 35 - Post(slug, title, content) 37 + Post(slug:, title:, content:, listed:) 36 38 } 37 39 38 40 pub fn list_posts(posts: List(Post)) -> List(Element(msg)) { 39 41 [ 40 42 component.header(1, "blog", [], [html.text("blog")]), 41 - html.ul([], list.map(posts, post_list_item)), 43 + html.ul([], post_list_items(posts, [])), 42 44 ] 43 45 } 44 46 45 - fn post_list_item(post: Post) -> Element(msg) { 46 - html.a([attribute.href("/blog/" <> post.slug)], [ 47 - html.text(post.slug), 48 - html.text(".djot"), 49 - ]) 47 + fn post_list_items( 48 + posts: List(Post), 49 + items: List(Element(msg)), 50 + ) -> List(Element(msg)) { 51 + case posts { 52 + [] -> list.reverse(items) 53 + [post, ..posts] -> 54 + case post.listed { 55 + True -> { 56 + let item = 57 + html.li([], [ 58 + html.a([attribute.href("/blog/" <> post.slug)], [ 59 + html.text(post.slug), 60 + html.text(".djot"), 61 + ]), 62 + ]) 63 + post_list_items(posts, [item, ..items]) 64 + } 65 + False -> post_list_items(posts, items) 66 + } 67 + } 50 68 }