My personal website, in gleam+lustre!
0
fork

Configure Feed

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

Other thing


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

+89 -124
+86 -121
dev/homepage/prepare.gleam
··· 1 1 //// Most of this file was borrowed from the project that was replaced by this: 2 2 //// https://forge.strawmelonjuice.com/CynthiaWebsiteEngine/ByYou/src/branch/main/by-you/src/byyou/cli.gleam 3 3 4 - import gleam/function 5 - 6 4 const address = "https://strawmelonjuice.com" 7 5 8 6 const minimal_hydration = True ··· 10 8 import argv 11 9 import gleam/bool 12 10 import gleam/erlang/application 11 + import gleam/function 13 12 import gleam/int 14 13 import gleam/io 15 14 import gleam/json ··· 58 57 case prepopulation_mode { 59 58 True if prod_mode -> { 60 59 // Writing pre-filled versions of index.html to each sitemapped location, allowing for meta data and faster content loads. 61 - case prepopulate_html() { 62 - Ok(_) -> Nil 63 - Error(msg) -> panic as msg 64 - } 60 + prepopulate_html() 65 61 } 66 62 True -> { 67 63 panic as "Pregeneration mode is only available for production builds." 68 64 } 69 65 False -> { 70 66 // Prepare script's "usual" bussiness. 71 - case embed_data(prod_mode) { 72 - Ok(_) -> Nil 73 - Error(msg) -> panic as msg 74 - } 75 - case generate_sitemap() { 76 - Ok(_) -> Nil 77 - Error(msg) -> panic as msg 78 - } 79 - case generate_atom() { 80 - Ok(_) -> Nil 81 - Error(msg) -> panic as msg 82 - } 83 - case generate_rss() { 84 - Ok(_) -> Nil 85 - Error(msg) -> panic as msg 86 - } 67 + embed_data(prod_mode) 68 + generate_sitemap() 69 + let assert Ok(_) = generate_rss() 70 + Nil 87 71 } 88 72 } 89 73 } 90 74 75 + @deprecated("Why not just assert instead babe") 91 76 fn try_annot( 92 77 result: Result(a, e), 93 78 otherwise msg: String, ··· 118 103 } 119 104 } 120 105 121 - fn prepopulate_html() { 122 - use main_index_html: String <- try_annot( 123 - simplifile.read("./dist/index.html"), 124 - "Prepopulation mode expects that the site already be built, but could not load ./dist/index.html", 125 - ) 126 - use _ <- try_annot( 127 - simplifile.write(to: "./dist/unpopulated.html", contents: main_index_html), 128 - "Could not write html to ./dist/unpopulated.html", 129 - ) 106 + fn prepopulate_html() -> Nil { 107 + let assert Ok(main_index_html) = simplifile.read("./dist/index.html") 108 + as "Prepopulation mode expects that the site already be built, but could not load ./dist/index.html" 109 + let assert Ok(_) = 110 + simplifile.write(to: "./dist/unpopulated.html", contents: main_index_html) 111 + as "Could not write html to ./dist/unpopulated.html" 112 + 130 113 io.println("✅\tWrote: `./dist/unpopulated.html`") 131 114 let main_model: Model = homepage.init() 132 - let map_entries = fn(cb: fn(Entry) -> Result(Nil, String)) -> Result( 133 - Nil, 134 - String, 135 - ) { 136 - list.map(homepage.sitemap(), cb) |> result.all |> result.replace(Nil) 115 + let map_entries = fn(cb: fn(Entry) -> Nil) -> Nil { 116 + list.map(homepage.sitemap(), cb) 117 + Nil 137 118 } 138 119 use entry: Entry <- map_entries() 139 120 let html_file_path = "./dist" <> homepage.to_url(entry.route) <> "/index.html" ··· 147 128 let title = 148 129 homepage.to_title(entry.route) 149 130 |> glentities.encode(glentities.Hex) 150 - use html <- try_annot( 131 + let assert Ok(html) = 151 132 string_insert_after(main_index_html, "<div id=\"app\">", pregenerated_html) 152 - |> result.map(string_insert_after(_, "<head>", meta_description_tag)) 153 - |> result.flatten() 154 - |> result.map(string_insert_after(_, meta_description_tag, link_canonical)) 155 - |> result.flatten() 156 - |> result.map(string.replace( 133 + |> result.map(string_insert_after(_, "<head>", meta_description_tag)) 134 + |> result.flatten() 135 + |> result.map(string_insert_after(_, meta_description_tag, link_canonical)) 136 + |> result.flatten() 137 + |> result.map(string.replace( 138 + _, 139 + each: "<title>Mar&#39;s site</title>", 140 + with: "<title>" <> title <> "</title>", 141 + )) 142 + |> result.map(case minimal_hydration, entry.route { 143 + True, stuff.PostById(..) -> string.replace( 157 144 _, 158 - each: "<title>Mar&#39;s site</title>", 159 - with: "<title>" <> title <> "</title>", 160 - )) 161 - |> result.map(case minimal_hydration, entry.route { 162 - True, stuff.PostById(..) -> string.replace( 163 - _, 164 - "<script src=\"/homepage.js\" type=\"module\">", 165 - "<script src=\"/chilp-only.js\" type=\"module\">", 166 - ) 167 - True, _ -> string.replace( 168 - _, 169 - "<script src=\"/homepage.js\" type=\"module\">", 170 - "", 171 - ) 172 - False, _ -> function.identity 173 - }), 174 - "Failed to generate html for " <> html_file_path, 175 - ) 176 - use _ <- try_annot( 145 + "<script src=\"/homepage.js\" type=\"module\">", 146 + "<script src=\"/chilp-only.js\" type=\"module\">", 147 + ) 148 + True, _ -> string.replace( 149 + _, 150 + "<script src=\"/homepage.js\" type=\"module\">", 151 + "", 152 + ) 153 + False, _ -> function.identity 154 + }) 155 + as { "Failed to generate html for " <> html_file_path } 156 + let assert Ok(_) = 177 157 simplifile.create_directory_all( 178 158 html_file_path |> string.replace("index.html", ""), 179 - ), 180 - "Could not create parent folder for " <> html_file_path, 181 - ) 159 + ) 160 + as { "Could not create parent folder for " <> html_file_path } 182 161 183 - use _ <- try_annot( 184 - simplifile.write(to: html_file_path, contents: html), 185 - "Could not write html to " <> html_file_path, 186 - ) 187 - Ok(io.println("✅\tWrote: `" <> html_file_path <> "`")) 162 + let assert Ok(_) = simplifile.write(to: html_file_path, contents: html) 163 + as { "Could not write html to " <> html_file_path } 164 + 165 + io.println("✅\tWrote: `" <> html_file_path <> "`") 188 166 } 189 167 190 168 fn to_canonical(route: Route) { ··· 231 209 ), 232 210 ] 233 211 |> rss.to_string() 234 - use _ <- try_annot( 235 - simplifile.write("./assets/rss.xml", contents:), 236 - "❌\tSomething went wrong writing `./assets/rss.xml`.", 237 - ) 212 + let assert Ok(_) = simplifile.write("./assets/rss.xml", contents:) 213 + as "❌\tSomething went wrong writing `./assets/rss.xml`." 214 + 238 215 io.println("✅\tWrote: `./assets/rss.xml`") 239 216 240 - use _ <- try_annot( 241 - simplifile.write("./assets/feed.xml", contents:), 242 - "❌\tSomething went wrong writing `./assets/feed.xml`.", 243 - ) 217 + let assert Ok(_) = simplifile.write("./assets/feed.xml", contents:) 218 + as "❌\tSomething went wrong writing `./assets/feed.xml`." 219 + 244 220 io.println("✅\tWrote: `./assets/feed.xml`") 245 221 Ok(Nil) 246 222 } ··· 317 293 }, 318 294 ).0 319 295 320 - use _ <- try_annot( 321 - simplifile.write("./assets/atom.xml", contents:), 322 - "❌\tSomething went wrong writing `./assets/atom.xml`.", 323 - ) 296 + let assert Ok(_) = simplifile.write("./assets/atom.xml", contents:) 297 + as "❌\tSomething went wrong writing `./assets/atom.xml`." 298 + 324 299 io.println("✅\tWrote: `./assets/atom.xml`") 325 300 |> Ok 326 301 } ··· 343 318 </url>" }) 344 319 |> string.join("\n") <> "</urlset>" 345 320 346 - use _ <- try_annot( 347 - simplifile.write("./assets/sitemap.xml", contents:), 348 - "❌\tSomething went wrong writing `./assets/sitemap.xml`.", 349 - ) 321 + let assert Ok(_) = simplifile.write("./assets/sitemap.xml", contents:) 322 + as "❌\tSomething went wrong writing `./assets/sitemap.xml`." 323 + 350 324 io.println("✅\tWrote: `./assets/sitemap.xml`") 351 - |> Ok 352 325 } 353 326 354 - fn embed_data(prod_mode: Bool) { 355 - use files <- result.try(list_files()) 327 + fn embed_data(prod_mode: Bool) -> Nil { 328 + let assert Ok(files) = list_files() 329 + let assert Ok(exists) = 330 + simplifile.is_directory("./src/homepage/from_prebuild/") 331 + |> result.replace_error( 332 + "❌\tCouldn't check for the existence of directory `src/homepage/from_prebuild/`.", 333 + ) 334 + 335 + let assert Ok(_) = case exists { 336 + False -> { 337 + simplifile.create_directory_all("./src/homepage/from_prebuild/") 338 + |> result.replace_error( 339 + "❌\tSomething went wrong creating directory `src/homepage/from_prebuild/`.", 340 + ) 341 + |> result.replace("✅\tCreated: `src/homepage/from_prebuild/`") 342 + } 343 + True -> { 344 + Ok("🆗\tAlready exists: `src/homepage/from_prebuild/`") 345 + } 346 + } 356 347 357 - use dir <- result.try( 358 - result.map( 359 - simplifile.is_directory("./src/homepage/from_prebuild/") 360 - |> result.replace_error( 361 - "❌\tCouldn't check for the existence of directory `src/homepage/from_prebuild/`.", 362 - ), 363 - fn(exists) { 364 - case exists { 365 - False -> { 366 - simplifile.create_directory_all("./src/homepage/from_prebuild/") 367 - |> result.replace_error( 368 - "❌\tSomething went wrong creating directory `src/homepage/from_prebuild/`.", 369 - ) 370 - |> result.replace("✅\tCreated: `src/homepage/from_prebuild/`") 371 - } 372 - True -> { 373 - Ok("🆗\tAlready exists: `src/homepage/from_prebuild/`") 374 - } 375 - } 376 - }, 377 - ) 378 - |> result.flatten, 379 - ) 380 - io.println(dir) 381 - use _ <- try_annot( 348 + let assert Ok(_) = 382 349 simplifile.write( 383 350 "./src/homepage/from_prebuild/data.gleam", 384 351 assertive_priv_file_read("codegen-templates/data.gleam") ··· 391 358 "pub const address = \"https://strawmelonjuice.com/\"", 392 359 "pub const address = \"" <> address <> "/\"", 393 360 ), 394 - ), 395 - "❌\tSomething went wrong writing `src/homepage/from_prebuild/data.gleam`.", 396 - ) 361 + ) 362 + as "❌\tSomething went wrong writing `src/homepage/from_prebuild/data.gleam`." 363 + 397 364 io.println("✅\tWrote: `src/homepage/from_prebuild/data.gleam`") 398 - |> Ok 399 365 } 400 366 401 367 fn list_files() { ··· 431 397 ) 432 398 433 399 list.try_map(files, fn(file) { 434 - use contents <- try_annot( 435 - simplifile.read(file), 436 - "❌\tSomething went wrong reading file `" <> file <> "`.", 437 - ) 400 + let assert Ok(contents) = simplifile.read(file) 401 + as { "❌\tSomething went wrong reading file `" <> file <> "`." } 402 + 438 403 Ok( 439 404 "#(" 440 405 <> json.to_string(json.string(file))
+1 -1
gleam.toml
··· 6 6 lustre = ">= 5.6.0 and < 6.0.0" 7 7 modem = ">= 2.1.2 and < 3.0.0" 8 8 jot = ">= 10.1.1 and < 11.0.0" 9 - chilp = ">= 2.0.1-pre and < 3.0.0" 9 + chilp = ">= 2.0.1-rc and < 3.0.0" 10 10 # chilp = { git = "https://tangled.org/strawmelonjuice.com/chilp", ref = "main" } 11 11 # chilp = { path = "../../../tangled.sh/strawmelonjuice.com/chilp/" } 12 12 gleam_time = ">= 1.7.0 and < 2.0.0"
+2 -2
manifest.toml
··· 4 4 packages = [ 5 5 { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, 6 6 { name = "booklet", version = "1.1.0", build_tools = ["gleam"], requirements = [], otp_app = "booklet", source = "hex", outer_checksum = "08E0FDB78DC4D8A5D3C80295B021505C7D2A2E7B6C6D5EAB7286C36F4A53C851" }, 7 - { name = "chilp", version = "2.0.1-pre", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib", "gleam_time", "html_parser", "lustre", "rsvp"], otp_app = "chilp", source = "hex", outer_checksum = "BCD7D945DE9C0549E42306DE243A13CB8E9F4E51E12AB22AA8EC8C8E861BB7C7" }, 7 + { name = "chilp", version = "2.0.1-rc", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib", "gleam_time", "html_parser", "lustre", "rsvp"], otp_app = "chilp", source = "hex", outer_checksum = "42D6A3D9765FA0E1E44436B7E951E725959E385B31B7CB677514837B22FDBDA6" }, 8 8 { name = "directories", version = "1.2.0", build_tools = ["gleam"], requirements = ["envoy", "gleam_stdlib", "platform", "simplifile"], otp_app = "directories", source = "hex", outer_checksum = "D13090CFCDF6759B87217E8DDD73A75903A700148A82C1D33799F333E249BF9E" }, 9 9 { name = "envoy", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "envoy", source = "hex", outer_checksum = "9C6FBB6BFA02A52798BEEC5977A738CAD6E4A057F4B67FD0C8061AD2502C191A" }, 10 10 { name = "exception", version = "2.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "exception", source = "hex", outer_checksum = "329D269D5C2A314F7364BD2711372B6F2C58FA6F39981572E5CA68624D291F8C" }, ··· 53 53 54 54 [requirements] 55 55 argv = { version = ">= 1.0.2 and < 2.0.0" } 56 - chilp = { version = ">= 2.0.1-pre and < 3.0.0" } 56 + chilp = { version = ">= 2.0.1-rc and < 3.0.0" } 57 57 gleam_erlang = { version = ">= 1.3.0 and < 2.0.0" } 58 58 gleam_json = { version = ">= 3.1.0 and < 4.0.0" } 59 59 gleam_regexp = { version = ">= 1.1.1 and < 2.0.0" }