diff options
| author | Fuwn <[email protected]> | 2024-06-23 10:32:33 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-06-23 10:33:10 +0000 |
| commit | d73e8b5f50dd62ff38f65b82809d54d6e53509d7 (patch) | |
| tree | 8f86b2cb1fceb2af5a47545bab1c64d577d801a5 /src | |
| parent | feat(gemini): support netcat-style single newline client message (diff) | |
| download | momoka-d73e8b5f50dd62ff38f65b82809d54d6e53509d7.tar.xz momoka-d73e8b5f50dd62ff38f65b82809d54d6e53509d7.zip | |
refactor(gopher): line ending trimmer as function
Diffstat (limited to 'src')
| -rw-r--r-- | src/gemini.gleam | 7 | ||||
| -rw-r--r-- | src/gopher.gleam | 4 |
2 files changed, 7 insertions, 4 deletions
diff --git a/src/gemini.gleam b/src/gemini.gleam index 9c07391..ad04079 100644 --- a/src/gemini.gleam +++ b/src/gemini.gleam @@ -4,7 +4,6 @@ import gleam/bit_array import gleam/bytes_builder import gleam/http/request import gleam/httpc -import gleam/string import gopher pub fn get_gemtext_from_capsule(message) { @@ -28,15 +27,15 @@ pub fn get_gemtext_from_capsule(message) { case path { "/\r\n" | "\r\n" | "\n" -> request.to(gemini_proxy <> root_capsule) "/proxy/" <> route -> - request.to(gemini_proxy <> string.replace(route, "\r\n", "")) + request.to(gemini_proxy <> gopher.trim_gopher_line_ending(route)) "/" <> path -> request.to( gemini_proxy <> root_capsule <> "/" - <> string.replace(path, "\r\n", ""), + <> gopher.trim_gopher_line_ending(path), ) - _ -> request.to(root_capsule <> string.replace(path, "\r\n", "")) + _ -> request.to(root_capsule <> gopher.trim_gopher_line_ending(path)) } } _ -> request.to(root_capsule) diff --git a/src/gopher.gleam b/src/gopher.gleam index 044ee40..01ecc9a 100644 --- a/src/gopher.gleam +++ b/src/gopher.gleam @@ -3,6 +3,10 @@ import gleam/list import gleam/option.{None, Some} import gleam/string +pub fn trim_gopher_line_ending(line) { + string.replace(line, "\r", "") |> string.replace("\n", "") +} + pub fn gemtext_to_gopher(gemtext: List(Gemtext)) -> String { gemtext |> list.map(fn(line) { |