embed_image_blob: retire reload of image blob
Historically, the 'blob' view was unconditionally handed cooked (utf8-encoded) blob content, so embed_image_blob(), which requires raw blob content, has been forced to reload the blob in raw form, which is ugly and expensive. However, now that the Blob returned by Repo.blob() is able to vend raw or cooked content, it is no longer necessary for embed_image_blob() to reload the blob to gain access to the raw content. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
This commit is contained in:
parent
1d79988228
commit
50c004f8a5
10
utils.py
10
utils.py
@ -98,14 +98,8 @@ def colorize_blob(fname, s):
|
||||
def markdown_blob(s):
|
||||
return markdown.markdown(s)
|
||||
|
||||
def embed_image_blob(repo, dirname, fname):
|
||||
def embed_image_blob(fname, image_data):
|
||||
mimetype = mimetypes.guess_type(fname)[0]
|
||||
|
||||
# Unfortunately, bottle seems to require utf-8 encoded data.
|
||||
# We have to refetch the blob as raw data, because the utf-8 encoded
|
||||
# version of the blob available in the bottle template discards binary data.
|
||||
raw_blob = repo.blob(dirname + fname)
|
||||
|
||||
return '<img style="max-width:100%;" src="data:{0};base64,{1}" />'.format( \
|
||||
mimetype, base64.b64encode(raw_blob.raw_content))
|
||||
mimetype, base64.b64encode(image_data))
|
||||
|
||||
|
@ -40,7 +40,7 @@
|
||||
</h3>
|
||||
|
||||
% if can_embed_image(repo, fname.unicode):
|
||||
{{!embed_image_blob(repo, dirname.raw, fname.raw)}}
|
||||
{{!embed_image_blob(fname.raw, blob.raw_content)}}
|
||||
% elif can_markdown(repo, fname.unicode):
|
||||
{{!markdown_blob(blob.utf8_content)}}
|
||||
% elif can_colorize(blob.utf8_content):
|
||||
|
Loading…
Reference in New Issue
Block a user