Merge pull request #26 from pajowu/twitter-cards

added support for twitter cards
This commit is contained in:
Gilson Filho 2016-02-21 21:37:08 -03:00
commit 835de7e7e2
3 changed files with 54 additions and 0 deletions

View File

@ -93,6 +93,13 @@ Accept many analytics:
- Gauges: ``GAUGES`` - Gauges: ``GAUGES``
- Piwik: ``PIWIK_URL`` and ``PIWIK_SITE_ID``. - 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 ### Other configuration
- If ``ADDTHIS_PUBID`` is defined sharing buttons from AddThis will appear - If ``ADDTHIS_PUBID`` is defined sharing buttons from AddThis will appear

View File

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

View File

@ -78,6 +78,23 @@
{% endfor %} {% endfor %}
<meta property="og:site_name" content="{{ SITENAME }}"> <meta property="og:site_name" content="{{ SITENAME }}">
{% endblock opengraph %} {% 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 %}
{% 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> </head>
<body> <body>