diff options
author | Cãtãlin Mariş <alrraa@gmail.com> | 2012-08-07 09:51:29 +0200 |
---|---|---|
committer | Mathias Bynens <mathias@qiwi.be> | 2012-08-07 09:54:38 +0200 |
commit | 5d76fc286fe921cddf9a73c404ada924c856df24 (patch) | |
tree | f56b0f3bc59682d23f89f6771c1353f61f279a99 | |
parent | 3a7ae53e188f16cd51dbae6056439587ce56174e (diff) | |
download | dotfiles-5d76fc286fe921cddf9a73c404ada924c856df24.tar.gz dotfiles-5d76fc286fe921cddf9a73c404ada924c856df24.tar.bz2 dotfiles-5d76fc286fe921cddf9a73c404ada924c856df24.zip |
.functions: Make `dataurl` more generic
-rw-r--r-- | .functions | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -11,9 +11,13 @@ if [ $? -eq 0 ]; then } fi -# Create a data URL from an image (works for other file types too, if you tweak the Content-Type afterwards) -dataurl() { - echo "data:image/${1##*.};base64,$(openssl base64 -in "$1")" | tr -d '\n' +# Create a data URL from a file +function dataurl() { + local mimeType=$(file --mime-type "$1" | cut -d ' ' -f2) + if [[ $mimeType == text/* ]]; then + mimeType="${mimeType};charset=utf-8" + fi + echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')" } # Start an HTTP server from a directory, optionally specifying the port |