Explorar o código

Add support for og:image and twitter:image for site's home page. Also let user set a default image for the purpose

Update #15
Talha Mansoor %!s(int64=11) %!d(string=hai) anos
pai
achega
a351129115

+ 8 - 0
templates/_includes/_defaults.html

@@ -68,3 +68,11 @@
 {% set GOOGLE_PLUS_PROFILE_URL = GOOGLE_PLUS_PROFILE_URL %}
 {% endif %}
 
+{# Thumbnail image to show when homepage is shared on social media. It also
+serves as the default image for posts whose social_media_image is not set. #}
+{% if not SOCIAL_MEDIA_IMAGE %}
+{% set SOCIAL_MEDIA_IMAGE = '' %}
+{% else %}
+{% set SOCIAL_MEDIA_IMAGE = SOCIAL_MEDIA_IMAGE %}
+{% endif %}
+

+ 6 - 0
templates/_includes/seo_metadata.html

@@ -21,6 +21,12 @@
 {% if article.social_media_image %}
 <meta property="og:image" content="{{article.social_media_image}}" />
 <meta name="twitter:image" content="{{article.social_media_image}}" >
+{% else %}
+{% from '_includes/_defaults.html' import SOCIAL_MEDIA_IMAGE with context %}
+    {% if SOCIAL_MEDIA_IMAGE %}
+<meta property="og:image" content="{{SOCIAL_MEDIA_IMAGE}}" />
+<meta name="twitter:image" content="{{SOCIAL_MEDIA_IMAGE}}" >
+    {% endif %}
 {% endif %}
 {% endmacro %}
 

+ 5 - 0
templates/index.html

@@ -26,6 +26,11 @@
 {%if TWITTER_USERNAME %}
 <meta name="twitter:creator" content="@{{TWITTER_USERNAME}}">
 {% endif %}
+{% from '_includes/_defaults.html' import SOCIAL_MEDIA_IMAGE with context %}
+{% if SOCIAL_MEDIA_IMAGE %}
+<meta property="og:image" content="{{SOCIAL_MEDIA_IMAGE}}" />
+<meta name="twitter:image" content="{{SOCIAL_MEDIA_IMAGE}}" >
+{% endif %}
 {% endblock meta_tags_in_head %}
 
 {% block content %}