From dabd156c426885d616b8fb16b0cfc450c68c5b68 Mon Sep 17 00:00:00 2001 From: G-J van Rooyen Date: Sun, 28 Apr 2024 19:20:02 +0200 Subject: [PATCH] Strip trailing slash from the blog URL --- src/scriptorium/defaults.gleam | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/scriptorium/defaults.gleam b/src/scriptorium/defaults.gleam index d4b9a39..3ad4060 100644 --- a/src/scriptorium/defaults.gleam +++ b/src/scriptorium/defaults.gleam @@ -2,6 +2,7 @@ //// blog quickly. import gleam/uri +import gleam/string import scriptorium/compiler import scriptorium/config.{type Configuration, Compiling, Configuration, Rendering} import scriptorium/parser @@ -34,6 +35,14 @@ pub fn default_config( author: config.Author, copyright: String, ) -> Configuration { + + // Drop any trailing slash from the blog URL, otherwise a `blog_url` like + // "https://my.blog.example/" will end up having a root path of "/" instead + // of "". + let blog_url = case string.ends_with(blog_url, "/") { + True -> string.drop_right(blog_url, 1) + False -> blog_url + } let assert Ok(parsed_url) = uri.parse(blog_url) Configuration(