馃捇 My personal website
blog.kacaii.dev/
blog
gleam
lustre
1import argv
2import blog
3import blog/post
4import filepath as path
5import gleam/list
6import gleam/string
7import simplifile
8
9pub fn main() -> Nil {
10 let assert Ok(priv) = blog.priv_directory()
11 let posts_path = path.join(priv, "posts")
12
13 case argv.load().arguments {
14 ["update_titles"] -> update_posts_titles(posts_path)
15 _ -> Nil
16 }
17}
18
19fn update_posts_titles(posts_path: String) -> Nil {
20 let assert Ok(entries) = simplifile.read_directory(posts_path)
21 as "Read posts directory"
22
23 use file_name <- list.each(entries)
24 let file_path = path.join(posts_path, file_name)
25 let assert Ok(post) = post.from_string(path: file_path) as "Parse post"
26
27 let new_file_name = post.meta.slug <> ".md"
28 let new_file_path =
29 string.replace(in: file_path, each: file_name, with: new_file_name)
30
31 let assert Ok(_) = simplifile.rename(at: file_path, to: new_file_path)
32 as "Rename post"
33}