improve currency shortcodes
parent
bca12c8e11
commit
d58f82a840
|
@ -1,14 +1,11 @@
|
||||||
|
{{- $units := slice "" "k" "M" -}}
|
||||||
{{- $from := .Get "from" -}}
|
{{- $from := .Get "from" -}}
|
||||||
{{- $to := default "CNY" (.Get "to") -}}
|
{{- $to := default "CNY" (.Get "to") -}}
|
||||||
{{- $value := float (.Get "value") -}}
|
{{- $value := float (.Get "value") -}}
|
||||||
{{- with getJSON (printf "https://api.exchangerate-api.com/v4/latest/%s" $from) -}}
|
{{- $unit := math.Floor (div (math.Log $value) (math.Log 1000)) | int -}}
|
||||||
<a
|
{{- $base := math.Pow 1000 $unit -}}
|
||||||
class="currency"
|
{{- $formatted := printf "%g%s" (div $value $base) (index $units $unit) -}}
|
||||||
role="tooltip"
|
{{- $qs := querify "Amount" $value "From" $from "To" $to -}}
|
||||||
aria-label="≈ {{ lang.FormatCurrency 2 $to (mul $value (index .rates $to)) }}"
|
<a class="currency" href="https://www.xe.com/currencyconverter/convert/?{{ $qs | safeURL }}">
|
||||||
data-microtip-position="right"
|
{{- $formatted }} {{ $from -}}
|
||||||
href="https://google.com/search?q={{ $value }} {{ $from }} {{ $to }}"
|
|
||||||
>
|
|
||||||
{{- lang.FormatCurrency 2 $from $value -}}
|
|
||||||
</a>
|
</a>
|
||||||
{{- end -}}
|
|
Loading…
Reference in New Issue