My personal website, in gleam+lustre!
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Work on the represenation and support of LiveBlogs


Signed-off-by: MLC Bloeiman <mar@strawmelonjuice.com>

+54 -17
+11 -4
src/homepage.gleam
··· 873 873 874 874 [pages, posts_as_entries, categories_and_tags] 875 875 |> list.flatten() 876 - |> stuff.unique_entry() 876 + |> stuff.unique_entry(posts) 877 877 } 878 878 879 879 fn view_sitemap() -> List(Element(Msg)) { ··· 1066 1066 Msg, 1067 1067 ) { 1068 1068 [ 1069 - html.span([attribute.class("text-sm float-right")], [ 1070 - element.text(date), 1071 - ]), 1069 + html.a( 1070 + [ 1071 + attribute.class("text-sm float-right"), 1072 + attribute.id(int.to_string(takes.id)), 1073 + attribute.href("#" <> int.to_string(takes.id)), 1074 + ], 1075 + [ 1076 + element.text(date), 1077 + ], 1078 + ), 1072 1079 subtitle(label), 1073 1080 html.div( 1074 1081 [
+43 -13
src/homepage/stuff.gleam
··· 1 1 // Imports 2 + import gleam/bool 2 3 import gleam/dict.{type Dict} 3 4 import gleam/int 4 5 import gleam/list 5 6 import gleam/option.{type Option} 6 7 import gleam/result 8 + import gleam/string 7 9 import gleam/time/calendar 8 10 import gleam/uri 9 11 import lustre/attribute.{type Attribute} ··· 134 136 } 135 137 136 138 /// Removes all doubles from a list of entries, keeping only the latest items 137 - pub fn unique_entry(from: List(Entry)) { 139 + pub fn unique_entry(from: List(Entry), posts: List(Post)) { 138 140 // Weed out the obvious ones 139 - let from = list.unique(from) 140 - unique_entry_loop([], from:) 141 + list.unique(from) 142 + // Weed out the less obvious ones 143 + |> list.filter(fn(item) -> Bool { 144 + let url = to_url(item.route, posts:) 145 + bool.and(string.starts_with(url, "/post"), string.contains(url, "#")) 146 + |> bool.negate() 147 + }) 148 + |> unique_entry_loop([], from: _) 141 149 } 142 150 143 151 fn unique_entry_loop(accumulated: List(Entry), from rest: List(Entry)) { ··· 169 177 attribute.href(to_url(route, posts)) 170 178 } 171 179 172 - pub fn to_url(route: Route, posts: List(Post)) -> String { 180 + pub fn to_url(route: Route, posts posts: List(Post)) -> String { 173 181 case route { 174 182 Index -> "/" 175 183 Me -> "/me" 176 184 Posts -> "/posts" 177 185 PostById(post_id) -> { 178 - let slug = { 179 - let m = list.find(posts, fn(p) { p.id == post_id }) 180 - case m { 181 - Error(Nil) -> int.to_string(post_id) 182 - Ok(p) -> { 183 - case p.aliases { 184 - [] -> int.to_string(post_id) 185 - [alias, ..] -> alias 186 + let slug = 187 + { 188 + use post <- result.try(list.find(posts, fn(p) { p.id == post_id })) 189 + let in_liveblog = 190 + posts 191 + |> list.find(fn(maybe_parent) { 192 + case maybe_parent.body { 193 + LiveBlog(items) -> { 194 + list.any(items, fn(references) { references.0 == post_id }) 195 + } 196 + _ -> False 197 + } 198 + }) 199 + 200 + case in_liveblog { 201 + // Part of a liveblog :0 202 + Ok(liveblog) -> { 203 + to_url(PostById(liveblog.id), posts) 204 + |> string.drop_start(string.length("/post/")) 205 + <> "#" 206 + <> int.to_string(post_id) 207 + } 208 + // Normal post! 209 + Error(_) -> { 210 + // Then check if this is an alias 211 + case post.aliases { 212 + [] -> int.to_string(post_id) 213 + [alias, ..] -> alias 214 + } 186 215 } 187 216 } 217 + |> Ok 188 218 } 189 - } 219 + |> result.unwrap(int.to_string(post_id)) 190 220 "/post/" <> slug 191 221 } 192 222 Portfolio -> "/me/portfolio"