From 9e967b1eea05350e76d53aba073112ad657af9e4 Mon Sep 17 00:00:00 2001 From: Mikko Ahlroth Date: Sat, 6 Apr 2024 16:01:24 +0300 Subject: [PATCH] Change route format --- gleam.toml | 2 +- manifest.toml | 6 +++--- src/gloss/paths.gleam | 12 +++++------- src/gloss/paths/post.gleam | 2 +- src/gloss/rendering/templates/base.gleam | 6 +++--- src/gloss/writer.gleam | 8 ++++++-- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/gleam.toml b/gleam.toml index df355a8..00e4411 100644 --- a/gleam.toml +++ b/gleam.toml @@ -16,7 +16,7 @@ target = "javascript" [dependencies] gleam_stdlib = "~> 0.36 or ~> 1.0" lustre = "~> 4.1" -lustre_ssg = { path = "../ssg" } +lustre_ssg = "~> 0.5.0" gleam_javascript = "~> 0.8" ranged_int = "~> 1.0" bigi = "~> 2.1" diff --git a/manifest.toml b/manifest.toml index c823023..0b1a0ae 100644 --- a/manifest.toml +++ b/manifest.toml @@ -12,9 +12,9 @@ packages = [ { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, { name = "jot", version = "0.3.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "jot", source = "hex", outer_checksum = "574A2DACA106E9B4826C9F3F2D3911844C7826D554C08E404696CC16F85E0392" }, { name = "lustre", version = "4.1.5", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_json", "gleam_otp", "gleam_stdlib"], otp_app = "lustre", source = "hex", outer_checksum = "C90B3DC868D346C49E98C8A62F2E594AE559D5FF25A46269D60FAA5939FCE827" }, - { name = "lustre_ssg", version = "0.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "jot", "lustre", "simplifile", "tom"], source = "local", path = "../ssg" }, + { name = "lustre_ssg", version = "0.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "jot", "lustre", "simplifile", "tom"], otp_app = "lustre_ssg", source = "hex", outer_checksum = "F208FC79C25AE70976AEA2BA4262760BCC5C807E637742FEF66F0692150039C6" }, { name = "ranged_int", version = "1.0.0", build_tools = ["gleam"], requirements = ["bigi", "gleam_stdlib"], otp_app = "ranged_int", source = "hex", outer_checksum = "8AACD49213E87BC6E7CE5F80038C1989966CF8187382760B6168E5EA9F364B09" }, - { name = "simplifile", version = "1.6.1", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "B75D3C64E526D9D7EDEED5F3BA31DAAF5F2B4D80A4183FE17FDB02ED526E4E96" }, + { name = "simplifile", version = "1.7.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "1D5DFA3A2F9319EC85825F6ED88B8E449F381B0D55A62F5E61424E748E7DDEB0" }, { name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" }, { name = "tom", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "tom", source = "hex", outer_checksum = "0831C73E45405A2153091226BF98FB485ED16376988602CC01A5FD086B82D577" }, ] @@ -25,5 +25,5 @@ gleam_javascript = { version = "~> 0.8" } gleam_stdlib = { version = "~> 0.36 or ~> 1.0" } gleeunit = { version = "~> 1.0" } lustre = { version = "~> 4.1" } -lustre_ssg = { path = "../ssg" } +lustre_ssg = { version = "~> 0.5.0" } ranged_int = { version = "~> 1.0" } diff --git a/src/gloss/paths.gleam b/src/gloss/paths.gleam index ccdeaca..da6a983 100644 --- a/src/gloss/paths.gleam +++ b/src/gloss/paths.gleam @@ -6,8 +6,6 @@ import gloss/utils/date.{type Month} pub const default_index = "/index" -const archive_prefix = "/archive" - pub type PathConfiguration { PathConfiguration( index: String, @@ -35,20 +33,20 @@ pub fn conf(index, single_post, tag) -> PathConfiguration { pub fn default_single_post(post: Post) { let post_path = post_paths.post_to_path(post) - "/" <> post_path.date_path <> "--" <> post_path.slug + "/" <> post_path.date_path <> "/" <> post_path.slug } pub fn default_tag(tag: String) { - "/tag--" <> tag + "/tag/" <> tag } pub fn year_archive(year: Int) { - archive_prefix <> "--" <> int.to_string(year) + "/archive" <> "/" <> int.to_string(year) } pub fn month_archive(year: Int, month: Month) { year_archive(year) - <> "-" + <> "/" <> string.pad_left(int.to_string(date.month_to_int(month)), 2, "0") } @@ -58,7 +56,7 @@ pub fn month_archive(year: Int, month: Month) { pub fn list_page(path: String, page: Int) { case page { 1 -> path - other -> path <> "--" <> int.to_string(other) + other -> path <> "/" <> int.to_string(other) } } diff --git a/src/gloss/paths/post.gleam b/src/gloss/paths/post.gleam index d33b9f1..abb8a89 100644 --- a/src/gloss/paths/post.gleam +++ b/src/gloss/paths/post.gleam @@ -21,7 +21,7 @@ pub fn post_to_path(post: Post) -> PostPath { pad_int, ) - PostPath(date_path: string.join(date_parts, "-"), slug: post.slug) + PostPath(date_path: string.join(date_parts, "/"), slug: post.slug) } fn pad_int(number: Int) -> String { diff --git a/src/gloss/rendering/templates/base.gleam b/src/gloss/rendering/templates/base.gleam index e0355eb..ed18c65 100644 --- a/src/gloss/rendering/templates/base.gleam +++ b/src/gloss/rendering/templates/base.gleam @@ -56,9 +56,9 @@ fn view( attribute("content", "width=device-width, initial-scale=1"), ]), title([], title_text), - link([href("./css/normalize.css"), rel("stylesheet")]), - link([href("./css/magick.css"), rel("stylesheet")]), - link([href("./css/custom.css"), rel("stylesheet")]), + link([href("/css/normalize.css"), rel("stylesheet")]), + link([href("/css/magick.css"), rel("stylesheet")]), + link([href("/css/custom.css"), rel("stylesheet")]), case config.author.url { option.Some(url) -> link([rel("me"), value(url)]) _ -> element.none() diff --git a/src/gloss/writer.gleam b/src/gloss/writer.gleam index de3a7b3..23adad4 100644 --- a/src/gloss/writer.gleam +++ b/src/gloss/writer.gleam @@ -32,7 +32,6 @@ pub fn write(db: Database, path_conf: PathConfiguration) { let path = path_conf.single_post(post.orig) #(path, post.content) }) - |> dict.from_list() let assert [index, ..rest] = db.index_pages @@ -76,8 +75,13 @@ pub fn write(db: Database, path_conf: PathConfiguration) { element.to_string(xml.declaration()) <> element.to_string(db.feed), ) + let site = + list.fold(single_posts, site, fn(acc, item) { + let #(path, post) = item + ssg.add_static_route(acc, path, post) + }) + site - |> ssg.add_dynamic_route("/", single_posts, fn(c) { c }) |> ssg.build() |> result.map_error(WriteError) }