# HG changeset patch # User Thierry Florac # Date 1561536020 -7200 # Node ID 249a631164759af34d5c5b759dfa446b4c0737e8 # Parent 48f08a49656d7bceaef2a34216a672946a23e33c Added checks against missing illustrations in OpenGraph adapters diff -r 48f08a49656d -r 249a63116475 src/pyams_default_theme/root/opengraph.py --- a/src/pyams_default_theme/root/opengraph.py Fri Jun 21 16:16:18 2019 +0200 +++ b/src/pyams_default_theme/root/opengraph.py Wed Jun 26 10:00:20 2019 +0200 @@ -64,19 +64,20 @@ illustration = registry.queryAdapter(context, IIllustration) if (illustration is not None) and illustration.has_data(): data = II18n(illustration).query_attribute('data', lang=lang, request=request) - thumbnail = IThumbnails(data).get_thumbnail('800x600') - yield PropertyMeta('og:image', absolute_url(thumbnail, request)) - if request.scheme == 'https': - yield PropertyMeta('og:image:secure_url', absolute_url(thumbnail, request)) - else: - yield PropertyMeta('og:image:url', absolute_url(thumbnail, request)) - yield PropertyMeta('og:image:type', thumbnail.content_type) - image_size = thumbnail.image_size - yield PropertyMeta('og:image:width', image_size[0]) - yield PropertyMeta('og:image:height', image_size[1]) - alt = II18n(illustration).query_attribute('alt_title', lang=lang, request=request) - if alt: - yield PropertyMeta('og:image:alt', alt) + if data: + thumbnail = IThumbnails(data).get_thumbnail('800x600') + yield PropertyMeta('og:image', absolute_url(thumbnail, request)) + if request.scheme == 'https': + yield PropertyMeta('og:image:secure_url', absolute_url(thumbnail, request)) + else: + yield PropertyMeta('og:image:url', absolute_url(thumbnail, request)) + yield PropertyMeta('og:image:type', thumbnail.content_type) + image_size = thumbnail.image_size + yield PropertyMeta('og:image:width', image_size[0]) + yield PropertyMeta('og:image:height', image_size[1]) + alt = II18n(illustration).query_attribute('alt_title', lang=lang, request=request) + if alt: + yield PropertyMeta('og:image:alt', alt) # locales properties yield PropertyMeta('og:locale', lang) diff -r 48f08a49656d -r 249a63116475 src/pyams_default_theme/shared/common/opengraph.py --- a/src/pyams_default_theme/shared/common/opengraph.py Fri Jun 21 16:16:18 2019 +0200 +++ b/src/pyams_default_theme/shared/common/opengraph.py Wed Jun 26 10:00:20 2019 +0200 @@ -97,19 +97,20 @@ target = get_parent(target, IIllustrationTarget, allow_context=False) if (target is not None) and (illustration is not None): data = II18n(illustration).query_attribute('data', lang=lang, request=request) - thumbnail = IThumbnails(data).get_thumbnail('800x600') - yield PropertyMeta('og:image', absolute_url(thumbnail, request)) - if request.scheme == 'https': - yield PropertyMeta('og:image:secure_url', absolute_url(thumbnail, request)) - else: - yield PropertyMeta('og:image:url', absolute_url(thumbnail, request)) - yield PropertyMeta('og:image:type', thumbnail.content_type) - image_size = thumbnail.image_size - yield PropertyMeta('og:image:width', image_size[0]) - yield PropertyMeta('og:image:height', image_size[1]) - alt = II18n(illustration).query_attribute('alt_title', lang=lang, request=request) - if alt: - yield PropertyMeta('og:image:alt', alt) + if data: + thumbnail = IThumbnails(data).get_thumbnail('800x600') + yield PropertyMeta('og:image', absolute_url(thumbnail, request)) + if request.scheme == 'https': + yield PropertyMeta('og:image:secure_url', absolute_url(thumbnail, request)) + else: + yield PropertyMeta('og:image:url', absolute_url(thumbnail, request)) + yield PropertyMeta('og:image:type', thumbnail.content_type) + image_size = thumbnail.image_size + yield PropertyMeta('og:image:width', image_size[0]) + yield PropertyMeta('og:image:height', image_size[1]) + alt = II18n(illustration).query_attribute('alt_title', lang=lang, request=request) + if alt: + yield PropertyMeta('og:image:alt', alt) # locales properties yield PropertyMeta('og:locale', lang)