tangled
alpha
login
or
join now
kacaii.dev
/
blog
0
fork
atom
💻 My personal website
blog.kacaii.dev/
blog
gleam
lustre
0
fork
atom
overview
issues
pulls
pipelines
:recycle: sort posts by date
kacaii.dev
2 months ago
5aecf6e4
bf585843
0/0
Waiting for spindle ...
+31
-8
4 changed files
expand all
collapse all
unified
split
src
blog
page
posts.gleam
recent_posts.gleam
post.gleam
blog.gleam
+11
-4
src/blog.gleam
···
2
2
import filepath as path
3
3
import gleam/erlang/process
4
4
import gleam/list
5
5
+
import gleam/result
5
6
import simplifile
6
7
import supervision_tree
7
8
import web
···
25
26
let assert Ok(entries) = simplifile.read_directory(posts_path)
26
27
as "Read posts directory"
27
28
28
28
-
use file_name <- list.try_map(entries)
29
29
-
posts_path
30
30
-
|> path.join(file_name)
31
31
-
|> post.parse
29
29
+
use posts <- result.map({
30
30
+
use file_name <- list.try_map(entries)
31
31
+
32
32
+
posts_path
33
33
+
|> path.join(file_name)
34
34
+
|> post.parse
35
35
+
})
36
36
+
37
37
+
list.sort(posts, post.compare)
38
38
+
|> list.reverse
32
39
}
33
40
34
41
pub fn priv_directory() -> Result(String, Nil) {
+3
-3
src/blog/page/posts.gleam
···
13
13
import wisp
14
14
15
15
pub fn handle_request(ctx: web.Context) -> wisp.Response {
16
16
-
let ul_styles = class("grid-cols-1 gap-4 mx-auto max-w-lg")
16
16
+
let ul_styles = class("grid grid-cols-1 gap-4 mx-auto max-w-lg")
17
17
18
18
let content = [
19
19
navbar.view(),
···
39
39
}
40
40
41
41
let li_styles =
42
42
-
class("flex-col p-4 mx-auto rounded-lg shadow-sm bg-ctp-mantle")
42
42
+
class("flex-col p-4 mx-auto w-full rounded-lg shadow-sm bg-ctp-mantle")
43
43
44
44
html.li([li_styles], [
45
45
html.a([attr.href("/posts/" <> post.to_uri_path(post))], [
···
55
55
}
56
56
57
57
fn tag_to_li(tag: String) -> element.Element(_) {
58
58
-
html.li([class(" py-0.5 px-2.5 rounded-md bg-ctp-surface0")], [html.text(tag)])
58
58
+
html.li([class("py-0.5 px-2.5 rounded-md bg-ctp-surface0")], [html.text(tag)])
59
59
}
+1
-1
src/blog/page/recent_posts.gleam
···
12
12
|> list.take(2)
13
13
|> list.map(post_to_li)
14
14
15
15
-
let articles_section = html.ul([], previews)
15
15
+
let articles_section = html.ul([class("grid grid-cols-1 gap-2")], previews)
16
16
let section_title = html.h3([class("text-lg")], [html.text("Recent posts")])
17
17
let more_style = class("underline text-md underline-offset-2")
18
18
let more = html.a([attr.href("/posts"), more_style], [html.text("More")])
+16
src/blog/post.gleam
···
1
1
import contour
2
2
import frontmatter
3
3
+
import gleam/int
3
4
import gleam/list
4
5
import gleam/option
6
6
+
import gleam/order
5
7
import gleam/result
6
8
import gleam/string
7
9
import gleam/time/calendar
···
111
113
other -> other
112
114
}
113
115
}
116
116
+
117
117
+
pub fn compare(a: Post, b: Post) -> order.Order {
118
118
+
let a_day = a.meta.date.day
119
119
+
let a_month = calendar.month_to_int(a.meta.date.month)
120
120
+
let a_year = a.meta.date.year
121
121
+
122
122
+
let b_day = b.meta.date.day
123
123
+
let b_month = calendar.month_to_int(b.meta.date.month)
124
124
+
let b_year = b.meta.date.year
125
125
+
126
126
+
use <- order.lazy_break_tie(int.compare(a_year, b_year))
127
127
+
use <- order.lazy_break_tie(int.compare(a_month, b_month))
128
128
+
int.compare(a_day, b_day)
129
129
+
}