Refactor Twitter cards support
Remove the TWITTER_HANDLE variable and use the 'twitter' value from SOCIAL. This eliminates duplicate settings! Remove closing slash for meta tags, not required by HTML5, see http://stackoverflow.com/a/21898502 In article.html Twitter images were specified twice - once as relative URL and once as full site URL. Now only a single full URL is used instead. Also stripped HTML tags from description. The default card type is summary_large_image which better displays with high-res images and the default header images. ``twitter_image`` article metadata is now supported, similar to ``og_image``. Documentation is updated.
This commit is contained in:
@ -26,34 +26,33 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block twitter_card %}
|
||||
{% if TWITTER_HANDLE %}
|
||||
{% if article.header_cover %}
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta name="twitter:image" content="{{ article.header_cover }}">
|
||||
{% elif HEADER_COVER %}
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<meta name="twitter:image" content="{{ HEADER_COVER }}">
|
||||
{% else %}
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<meta name="twitter:image" content="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/images/post-bg.jpg">
|
||||
{% endif %}
|
||||
<meta name="twitter:site" content="@{{ TWITTER_HANDLE }}" />
|
||||
<meta name="twitter:title" content="{{ article.title }}" />
|
||||
{% if description %}
|
||||
<meta name="twitter:description" content="{{ description }}" />
|
||||
{% elif article.headline %}
|
||||
<meta name="twitter:description" content="{{ article.headline }}" />
|
||||
{% else %}
|
||||
<meta name="twitter:description" content="{{ article.summary }}" />
|
||||
{% endif %}
|
||||
{% if article.header_cover %}
|
||||
{% for name,link in SOCIAL if name in ['twitter'] %}
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@{{ link|replace('http://', 'https://')|replace('https://twitter.com/', '') }}">
|
||||
<meta name="twitter:title" content="{{ article.title }}">
|
||||
|
||||
{% if article.twitter_image %}
|
||||
{% if article.twitter_image|lower|truncate(4, True, '') == "http" %}
|
||||
<meta property="twitter:image" content="{{ article.twitter_image }}">
|
||||
{% else %}
|
||||
<meta property="twitter:image" content="{{ SITEURL }}/{{ article.twitter_image }}">
|
||||
{% endif %}
|
||||
{% elif article.header_cover %}
|
||||
<meta name="twitter:image" content="{{ SITEURL }}/{{ article.header_cover }}">
|
||||
{% elif HEADER_COVER %}
|
||||
<meta name="twitter:image" content="{{ SITEURL }}/{{ HEADER_COVER }}">
|
||||
{% else %}
|
||||
<meta name="twitter:image" content="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/images/post-bg.jpg">
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if description %}
|
||||
<meta name="twitter:description" content="{{ description }}">
|
||||
{% elif article.headline %}
|
||||
<meta name="twitter:description" content="{{ article.headline }}">
|
||||
{% else %}
|
||||
<meta name="twitter:description" content="{{ article.summary|striptags|truncate(140) }}">
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
{% block opengraph %}
|
||||
{{ super() }}
|
||||
|
@ -81,21 +81,17 @@
|
||||
<meta property="og:site_name" content="{{ SITENAME }}">
|
||||
{% endblock opengraph %}
|
||||
{% block twitter_card %}
|
||||
{% if TWITTER_HANDLE %}
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<meta name="twitter:site" content="@{{ TWITTER_HANDLE }}" />
|
||||
<meta name="twitter:title" content="{{ SITENAME }}" />
|
||||
{% if SITESUBTITLE %}
|
||||
<meta name="twitter:description" content="{{ SITESUBTITLE }}" />
|
||||
{% else %}
|
||||
<meta name="twitter:description" content="View the blog." />
|
||||
{% endif %}
|
||||
{% for name,link in SOCIAL if name in ['twitter'] %}
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@{{ link|replace('http://', 'https://')|replace('https://twitter.com/', '') }}">
|
||||
<meta name="twitter:title" content="{{ SITENAME }}">
|
||||
<meta name="twitter:description" content="{{ SITESUBTITLE|default('View the blog.') }}">
|
||||
{% if HEADER_COVER %}
|
||||
<meta name="twitter:image" content="{{ SITEURL }}/{{ HEADER_COVER }}">
|
||||
{% else %}
|
||||
<meta name="twitter:image" content="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/images/post-bg.jpg">
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endblock twitter_card %}
|
||||
</head>
|
||||
|
||||
|
Reference in New Issue
Block a user