diff options
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | gleam.toml | 2 | ||||
| -rw-r--r-- | index.html | 2 | ||||
| -rw-r--r-- | src/request.gleam | 26 | ||||
| -rw-r--r-- | src/svg.gleam | 4 |
5 files changed, 26 insertions, 12 deletions
@@ -20,7 +20,7 @@ easy it is to understand! It's all contained in under 300 (294) liberally newlin ## Usage -Mayu currently has seven available themes selectable using the `theme` query parameter of any `get` operation. +Mayu currently has nine available themes selectable using the `theme` query parameter of any `get` operation. E.g., [counter.due.moe/get/@demo?theme=urushi](https://counter.due.moe/get/@demo?theme=urushi) @@ -34,6 +34,8 @@ E.g., [counter.due.moe/get/@demo?theme=urushi](https://counter.due.moe/get/@demo - `lain` - `garukura` +Mayu will pad the counter number with zeroes until it reaches a length of 6 characters. You can modify this behavior by changing the `padding` query parameter of any `get` operation. + ### Local ```bash @@ -2,7 +2,7 @@ # https://gleam.run/writing-gleam/gleam-toml/. name = "mayu" -version = "0.1.11" +version = "0.1.12" gleam = ">= 1.2.0" description = "Moe-Counter Compatible Website Hit Counter" licenses = ["GPL-3.0-only"] @@ -292,7 +292,7 @@ themeValue = themeSelect.value; } - image.src = `https://mayu.due.moe/get/@${inputValue}?theme=${themeValue}`; + image.src = `https://mayu.due.moe/get/@${inputValue}?theme=${themeValue}&padding=6`; setCopyCodes(); }; diff --git a/src/request.gleam b/src/request.gleam index 6e23caf..62abf1f 100644 --- a/src/request.gleam +++ b/src/request.gleam @@ -1,6 +1,8 @@ import database import envoy +import gleam/int import gleam/json +import gleam/list import gleam/string import gleam/string_builder import simplifile @@ -44,13 +46,23 @@ pub fn handle(request, connection) { Ok(counter) -> { wisp.ok() |> wisp.set_header("Content-Type", "image/svg+xml") - |> wisp.string_body(svg.xml( - case wisp.get_query(request) { - [#("theme", theme)] -> theme - _ -> "asoul" - }, - counter.num, - )) + |> wisp.string_body( + svg.xml( + case list.key_find(wisp.get_query(request), "theme") { + Ok(theme) -> theme + _ -> "asoul" + }, + counter.num, + case list.key_find(wisp.get_query(request), "padding") { + Ok(padding) -> + case int.parse(padding) { + Ok(n) -> n + Error(_) -> 6 + } + _ -> 6 + }, + ), + ) } Error(_) -> wisp.unprocessable_entity() } diff --git a/src/svg.gleam b/src/svg.gleam index 1efadaa..d9de64f 100644 --- a/src/svg.gleam +++ b/src/svg.gleam @@ -55,13 +55,13 @@ fn images(theme, digits, width, height, svgs) { } } -pub fn xml(theme, number) { +pub fn xml(theme, number, padding) { let xml = images( theme, { let assert Ok(digits) = int.digits(number, 10) - let digits_padding = 5 - list.length(digits) + let digits_padding = padding - list.length(digits) case digits_padding { n if n > 0 -> list.concat([list.repeat(0, digits_padding), digits]) |