added support for twitter cards

This commit is contained in:
pajowu 2016-02-06 19:14:41 +02:00
parent f26dd2b92f
commit d6618f16b2
3 changed files with 50 additions and 0 deletions

View File

@ -86,6 +86,13 @@ Accept many analytics:
- Gauges: ``GAUGES``
- Piwik: ``PIWIK_URL`` and ``PIWIK_SITE_ID``.
### Twitter cards
Twitter cards are automatically generated if TWITTER_HANDLE is set:
```python
TWITTER_HANDLE = "myprofile"
```
### Other configuration
- If ``ADDTHIS_PUBID`` is defined sharing buttons from AddThis will appear

View File

@ -18,6 +18,36 @@
{% 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 %}
<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 %}
{% endblock %}
{% block opengraph %}
{{ super() }}
<meta property="og:type" content="article">

View File

@ -77,6 +77,19 @@
{% endfor %}
<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 }}" />
<meta name="twitter:description" content="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 %}
{% endblock twitter_card %}
</head>
<body>