diff --git a/layouts/_partials/human_file_size.html b/layouts/_partials/human_file_size.html new file mode 100644 index 0000000..bf1c0d9 --- /dev/null +++ b/layouts/_partials/human_file_size.html @@ -0,0 +1,7 @@ +{{/* Call this with a resource's content e.g., partial "human_file_size" .Content */}} +{{- $bytes := len . -}} +{{- $kb := div $bytes 1024 -}} +{{- $mb := div $kb 1024 -}} +{{- if ge $mb 1 -}}{{- $mb -}} MB +{{- else if ge $kb 1 -}}{{- $kb -}} KB +{{- else -}}{{- $bytes -}} B{{- end -}}