Change route format

This commit is contained in:
Mikko Ahlroth 2024-04-06 16:01:24 +03:00
parent bc92b53483
commit 9e967b1eea
6 changed files with 19 additions and 17 deletions

View file

@ -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"

View file

@ -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" }

View file

@ -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)
}
}

View file

@ -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 {

View file

@ -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()

View file

@ -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)
}