Added suuport for responsive images; added initial support for SVG

Signed-off-by: Duncan Lock <duncan.lock@gmail.com>
This commit is contained in:
Duncan Lock
2013-04-24 20:38:20 -07:00
parent ec7384fb4e
commit c99a2102f8

View File

@@ -11,7 +11,6 @@ TODO: Need to add a test.py for this plugin.
"""
import types
import os
from pelican import signals
@@ -22,23 +21,31 @@ from PIL import Image
def content_object_init(instance):
def _get_content(self):
content = self._content
return content
instance._get_content = types.MethodType(_get_content, instance)
if instance._content is not None:
content = instance._content
soup = BeautifulSoup(content)
# if '<object type="image/svg+xml"' in content:
# for obj in soup('object'):
# extra_style = 'max-width: 100%;'
# fig = obj.find_parent('div', 'figure')
# if fig:
# if obj.get('style'):
# obj['style'] += extra_style
# else:
# obj['style'] = extra_style
if 'img' in content:
for img in soup('img'):
# TODO: Pretty sure this isn't the right way to do this, too hard coded.
# There must be a setting that I should be using?
src = instance.settings['PATH'] + '/images/' + os.path.split(img['src'])[1]
im = Image.open(src)
extra_style = 'width: {}px; height: auto;'.format(im.size[0])
if instance.settings['RESPONSIVE_IMAGES']:
extra_style = 'max-width: 100%;'
else:
# TODO: Pretty sure this isn't the right way to do this, too hard coded.
# There must be a setting that I should be using?
src = instance.settings['PATH'] + '/images/' + os.path.split(img['src'])[1]
im = Image.open(src)
extra_style = 'width: {}px; height: auto;'.format(im.size[0])
if img.get('style'):
img['style'] += extra_style
else: