diff --git a/src/gloss/defaults.gleam b/src/gloss/defaults.gleam index f7a5ba2..30f3a3d 100644 --- a/src/gloss/defaults.gleam +++ b/src/gloss/defaults.gleam @@ -1,3 +1,4 @@ +import gleam/uri import gloss/config.{type Configuration, Compiling, Configuration, Rendering} import gloss/rendering/views/single_post import gloss/rendering/views/base @@ -28,6 +29,8 @@ pub fn default_config( author: config.Author, copyright: String, ) -> Configuration { + let assert Ok(parsed_url) = uri.parse(blog_url) + Configuration( blog_name: blog_name, blog_url: blog_url, @@ -44,7 +47,7 @@ pub fn default_config( posts_per_page: 10, posts_in_feed: 20, ), - paths: paths.defaults, + paths: paths.PathConfiguration(..paths.defaults, root: parsed_url.path), parser: parser.default_parse, writer: writer.write, output_path: "./output", diff --git a/src/gloss/paths.gleam b/src/gloss/paths.gleam index f07418c..2cbc6f5 100644 --- a/src/gloss/paths.gleam +++ b/src/gloss/paths.gleam @@ -5,6 +5,8 @@ import gloss/models/page.{type Page} import gloss/paths/post as post_paths import gloss/utils/date.{type Month} +pub const default_root = "" + pub const default_index = "/index" pub const default_feed_file = "/feed.xml" @@ -13,6 +15,7 @@ pub const default_feed = default_feed_file pub type PathConfiguration { PathConfiguration( + root: String, index: String, single_post: fn(Post) -> String, page: fn(Page) -> String, @@ -27,6 +30,7 @@ pub type PathConfiguration { } pub const defaults = PathConfiguration( + root: default_root, index: default_index, single_post: default_single_post, page: default_page, diff --git a/src/gloss/rendering/views/base.gleam b/src/gloss/rendering/views/base.gleam index d313d04..8e36212 100644 --- a/src/gloss/rendering/views/base.gleam +++ b/src/gloss/rendering/views/base.gleam @@ -9,9 +9,7 @@ import lustre/element/html.{ a, body, footer, h1, head, header, html, li, link, main, meta, nav, p, section, title, ul, } -import lustre/attribute.{ - attribute, href, id, name, rel, role, style, type_, value, -} +import lustre/attribute.{attribute, href, id, name, rel, role, style, type_} import gloss/models/database.{type Database} import gloss/models/menu.{type MenuItem} import gloss/utils/ordered_tree @@ -60,16 +58,16 @@ 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(config.paths.root <> "/css/normalize.css"), rel("stylesheet")]), + link([href(config.paths.root <> "/css/magick.css"), rel("stylesheet")]), + link([href(config.paths.root <> "/css/custom.css"), rel("stylesheet")]), link([ - href(config.paths.feed), + href(config.paths.root <> config.paths.feed), rel("alternate"), type_("application/atom+xml"), ]), case config.author.url { - option.Some(url) -> link([rel("me"), value(url)]) + option.Some(url) -> link([rel("me"), href(url)]) _ -> element.none() }, ..extra_meta @@ -77,7 +75,7 @@ fn view( body([], [ header([id("title"), role("banner")], [ h1([], [ - a([href(config.paths.html(config.paths.index))], [ + a([href(config.paths.html(config.paths.root <> config.paths.index))], [ text(config.blog_name), ]), ]), @@ -147,7 +145,7 @@ fn tags(db: Database, config: Configuration) { li([], [ a( [ - href(config.paths.html(config.paths.tag(tag))), + href(config.paths.html(config.paths.root <> config.paths.tag(tag))), style([#("font-size", int.to_string(percentage) <> "%")]), ], [text(tag)], @@ -168,12 +166,10 @@ fn archives(db: Database, config: Configuration) { li([], [ a( [ - href( - config.paths.html(config.paths.list_page( - config.paths.year(year), - 1, - )), - ), + href(config.paths.html( + config.paths.root + <> config.paths.list_page(config.paths.year(year), 1), + )), ], [text(int.to_string(year))], ), @@ -185,12 +181,13 @@ fn archives(db: Database, config: Configuration) { li([], [ a( [ - href( - config.paths.html(config.paths.list_page( + href(config.paths.html( + config.paths.root + <> config.paths.list_page( config.paths.month(year, month), 1, - )), - ), + ), + )), ], [ text( diff --git a/src/gloss/rendering/views/nav.gleam b/src/gloss/rendering/views/nav.gleam index 3ddd654..21ce97e 100644 --- a/src/gloss/rendering/views/nav.gleam +++ b/src/gloss/rendering/views/nav.gleam @@ -39,7 +39,11 @@ pub fn view(list_info: ListInfo, root_path: String, config: Configuration) { li([], [ a( list.flatten([ - [href(config.paths.html(config.paths.list_page(root_path, page)))], + [ + href(config.paths.html( + config.paths.root <> config.paths.list_page(root_path, page), + )), + ], link_attributes, ]), [text(link_text)], @@ -73,7 +77,9 @@ fn nextprev_link( li([], [ a( [ - href(config.paths.html(config.paths.list_page(root_path, target))), + href(config.paths.html( + config.paths.root <> config.paths.list_page(root_path, target), + )), attribute("aria-label", label), ], [span([attribute("aria-hidden", "true")], [element.text(text)])], diff --git a/src/gloss/rendering/views/single_post.gleam b/src/gloss/rendering/views/single_post.gleam index 40e6b64..4ad63da 100644 --- a/src/gloss/rendering/views/single_post.gleam +++ b/src/gloss/rendering/views/single_post.gleam @@ -22,7 +22,8 @@ pub fn list_view(db: Database, config: Configuration) { } fn view(post: CompiledPost, is_full: Bool, _db: Database, config: Configuration) { - let post_url = config.paths.html(config.paths.single_post(post.orig)) + let post_url = + config.paths.html(config.paths.root <> config.paths.single_post(post.orig)) let content = case post.content.short, is_full { option.Some(content), False -> content @@ -42,7 +43,14 @@ fn view(post: CompiledPost, is_full: Bool, _db: Database, config: Configuration) [], list.map(post.orig.tags, fn(tag) { li([], [ - a([href(config.paths.html(config.paths.tag(tag)))], [text(tag)]), + a( + [ + href(config.paths.html( + config.paths.root <> config.paths.tag(tag), + )), + ], + [text(tag)], + ), ]) }), ),