⭐ Moe-Counter Compatible Website Hit Counter Written in Gleam mayu.due.moe
hit-counter svg moe

feat(request): padding query parameter

fuwn.net 4c3f0bc8 b5099408

verified
+26 -12
+3 -1
README.md
··· 20 20 21 21 ## Usage 22 22 23 - Mayu currently has seven available themes selectable using the `theme` query parameter of any `get` operation. 23 + Mayu currently has nine available themes selectable using the `theme` query parameter of any `get` operation. 24 24 25 25 E.g., [counter.due.moe/get/@demo?theme=urushi](https://counter.due.moe/get/@demo?theme=urushi) 26 26 ··· 33 33 - `urushi` 34 34 - `lain` 35 35 - `garukura` 36 + 37 + 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. 36 38 37 39 ### Local 38 40
+1 -1
gleam.toml
··· 2 2 # https://gleam.run/writing-gleam/gleam-toml/. 3 3 4 4 name = "mayu" 5 - version = "0.1.11" 5 + version = "0.1.12" 6 6 gleam = ">= 1.2.0" 7 7 description = "Moe-Counter Compatible Website Hit Counter" 8 8 licenses = ["GPL-3.0-only"]
+1 -1
index.html
··· 292 292 themeValue = themeSelect.value; 293 293 } 294 294 295 - image.src = `https://mayu.due.moe/get/@${inputValue}?theme=${themeValue}`; 295 + image.src = `https://mayu.due.moe/get/@${inputValue}?theme=${themeValue}&padding=6`; 296 296 297 297 setCopyCodes(); 298 298 };
+19 -7
src/request.gleam
··· 1 1 import database 2 2 import envoy 3 + import gleam/int 3 4 import gleam/json 5 + import gleam/list 4 6 import gleam/string 5 7 import gleam/string_builder 6 8 import simplifile ··· 44 46 Ok(counter) -> { 45 47 wisp.ok() 46 48 |> wisp.set_header("Content-Type", "image/svg+xml") 47 - |> wisp.string_body(svg.xml( 48 - case wisp.get_query(request) { 49 - [#("theme", theme)] -> theme 50 - _ -> "asoul" 51 - }, 52 - counter.num, 53 - )) 49 + |> wisp.string_body( 50 + svg.xml( 51 + case list.key_find(wisp.get_query(request), "theme") { 52 + Ok(theme) -> theme 53 + _ -> "asoul" 54 + }, 55 + counter.num, 56 + case list.key_find(wisp.get_query(request), "padding") { 57 + Ok(padding) -> 58 + case int.parse(padding) { 59 + Ok(n) -> n 60 + Error(_) -> 6 61 + } 62 + _ -> 6 63 + }, 64 + ), 65 + ) 54 66 } 55 67 Error(_) -> wisp.unprocessable_entity() 56 68 }
+2 -2
src/svg.gleam
··· 55 55 } 56 56 } 57 57 58 - pub fn xml(theme, number) { 58 + pub fn xml(theme, number, padding) { 59 59 let xml = 60 60 images( 61 61 theme, 62 62 { 63 63 let assert Ok(digits) = int.digits(number, 10) 64 - let digits_padding = 5 - list.length(digits) 64 + let digits_padding = padding - list.length(digits) 65 65 66 66 case digits_padding { 67 67 n if n > 0 -> list.concat([list.repeat(0, digits_padding), digits])