From d372300575e02ff75a37521adfdc1937c696c26f Mon Sep 17 00:00:00 2001 From: graphiteisaac Date: Tue, 27 May 2025 13:09:47 +1000 Subject: [PATCH] update to latest gleam package versions and add several weeks lol --- bun.lockb | Bin 64840 -> 64824 bytes gleam.toml | 13 +++++---- manifest.toml | 43 +++++++++++++--------------- package.json | 6 ++-- priv/posts/flight.md | 39 ++++++++++++++++++++++++++ priv/posts/obsession.md | 23 +++++++++++++++ priv/posts/secret-garden.md | 2 +- priv/posts/souvenir.md | 38 +++++++++++++++++++++++++ priv/posts/susceptible.md | 51 ++++++++++++++++++++++++++++++++++ priv/posts/violence.md | 39 ++++++++++++++++++++++++++ priv/posts/voyage.md | 34 +++++++++++++++++++++++ src/promptbox/devserver.gleam | 4 +-- src/promptbox/parser.gleam | 28 +++++++++++++++---- src/promptbox/web.gleam | 15 ++++++---- test/promptbox_test.gleam | 37 ++++++++++++------------ 15 files changed, 308 insertions(+), 64 deletions(-) create mode 100644 priv/posts/flight.md create mode 100644 priv/posts/obsession.md create mode 100644 priv/posts/souvenir.md create mode 100644 priv/posts/susceptible.md create mode 100644 priv/posts/violence.md create mode 100644 priv/posts/voyage.md diff --git a/bun.lockb b/bun.lockb index 2facdd243125bb56371209747efaa5b1dd4a8c84..95304eff1c45a85e673a58d3623544f1a48356d2 100755 GIT binary patch delta 973 zcmXxiYes2f;H}E;6P&3HrIL0NI~JEmXvg#(duA7$Gg7F9ToZ3v~*c{%dfHe z@!U&ahsQnL#*dp+%?{aAsB}`RJzg#Hf0NT8@><9-U%U{t(wKd*?JSw7DzFf9P>-dU zi^mXg1LE5}JcS55W;^ywRb(=;2hqz1eGold5bJ!=3$cTnpcW)kl02I!-kL7T21OU5 zMCx>Cq|c7fgl68Z;3_WTA{x+$b7;bP#32?c_(-vB0k%_QCs7P5%&?#wWjKywD8UJo zq6U=^gAijogE~|}46GWbQ2~D}#|lWefMje%3Z(#N#?Bn_z1RaIvTy|ZaRAxa2R#fp zh(pMO37N>nVPr^!&S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atter = frontmatter |> string.split("\n") @@ -27,7 +28,8 @@ pub fn parse_post(slug: String, content: String) -> Post { False -> Error(Nil) True -> { let assert [key, value] = - string.split(entry, ":") |> list.map(string.trim) + string.split(entry, ":") + |> list.map(string.trim) Ok(#(key, value)) } @@ -49,9 +51,25 @@ pub fn parse_post(slug: String, content: String) -> Post { |> result.try(int.parse) |> result.unwrap(-1), date: dict.get(frontmatter, "date") - |> result.try(birl.parse) - |> result.unwrap(birl.now()), + |> result.try(parse_date) + |> result.unwrap(calendar.Date(1970, calendar.January, 1)), post_p:, post_j:, ) } + +fn parse_date(time_str: String) -> Result(calendar.Date, Nil) { + case + time_str + |> string.split("-") + |> list.filter_map(int.parse) + { + [year, month, date] + if year > 2000 && month > 0 && month < 13 && date > 0 && date < 31 + -> { + let assert Ok(month) = calendar.month_from_int(month) + Ok(calendar.Date(year, month, date)) + } + _ -> Error(Nil) + } +} diff --git a/src/promptbox/web.gleam b/src/promptbox/web.gleam index 6eaeebc..3c08908 100644 --- a/src/promptbox/web.gleam +++ b/src/promptbox/web.gleam @@ -1,6 +1,7 @@ import gleam/int import gleam/list import lustre/attribute.{attribute, class} +import lustre/element import lustre/element/html import promptbox/parser @@ -30,20 +31,24 @@ pub fn home(posts: List(parser.Post)) { } pub fn individual(post: parser.Post) { - html.div([class("container px-4 mx-auto")], [prompt_element(post)]) + html.div([class("container px-4 mx-auto")], [prompt_element(post)]) } fn prompt_element(post: parser.Post) { html.article([class("post py-8"), attribute.id(post.slug)], [ - html.h2([class("prompt_title text-center text-4xl font-bold italic mb-1")], [html.text(post.title)]), - html.h5([class("prompt_week text-center italic text-slate-700 mb-5")], [html.text("Week " <> int.to_string(post.week))]), + html.h2([class("prompt_title text-center text-4xl font-bold italic mb-1")], [ + html.a([attribute.href("/prompts/" <> post.slug)], [html.text(post.title)]), + ]), + html.h5([class("prompt_week text-center italic text-slate-700 mb-5")], [ + html.text("Week " <> int.to_string(post.week)), + ]), html.div([class("flex flex-col")], [ html.article([class("prose text-left")], [ - html.div([attribute("dangerous-unescaped-html", post.post_p)], []), + element.unsafe_raw_html("", "div", [], post.post_p), html.cite([class("text-slate-800")], [html.text("~ P")]), ]), html.article([class("prose text-right self-end")], [ - html.div([attribute("dangerous-unescaped-html", post.post_j)], []), + element.unsafe_raw_html("", "div", [], post.post_j), html.cite([class("text-slate-800")], [html.text("~ J")]), ]), ]), diff --git a/test/promptbox_test.gleam b/test/promptbox_test.gleam index 67ac9d1..6c464a0 100644 --- a/test/promptbox_test.gleam +++ b/test/promptbox_test.gleam @@ -1,6 +1,4 @@ -import birl -import gleam/io -import gleam/result +import gleam/time/calendar import gleeunit import gleeunit/should import lustre/element @@ -13,21 +11,24 @@ pub fn main() { gleeunit.main() } -// gleeunit test functions end in `_test` -pub fn hello_world_test() { - let post = - simplifile.read("./priv/posts/ebb_and_flow.md") - |> result.unwrap("") - |> parser.parse_post("ebb_and_flow") - |> io.debug - - io.debug(birl.to_date_string(post.date)) - - files.read_all_posts() - |> io.debug - - 1 - |> should.equal(1) +pub fn parse_basic_post_test() { + "--- +title: a title +week: 1 +date: 2025-01-01 +--- +Post content 1 ++++ +Post content 2" + |> parser.parse_post("a-title", _) + |> should.equal(parser.Post( + slug: "a-title", + title: "a title", + week: 1, + date: calendar.Date(2025, calendar.January, 1), + post_p: "

Post content 1

\n", + post_j: "

Post content 2

\n", + )) } pub fn generate_test() {