Merge pull request #28 from MrSenko/og_image

Update meta tags and add support for og:image
This commit is contained in:
Gilson Filho 2016-02-19 23:04:08 -02:00
commit cbc55d881b
3 changed files with 43 additions and 11 deletions

View File

@ -105,7 +105,11 @@ Accept many analytics:
### Articles ### Articles
To customize header cover to articles, insert the metadata ``header_cover``: To customize header cover to articles, insert the metadata ``header_cover``.
To customize OpenGraph images, insert the metadata ``og_image``, otherwise
``header_cover``, ``HEADER_COVER`` or a default image is used. You can also
use absolute URLs for ``og_image``. Example:
- To RST - To RST
```rst ```rst
@ -120,6 +124,7 @@ My super title
:authors: Alexis Metaireau, Conan Doyle :authors: Alexis Metaireau, Conan Doyle
:summary: Short version for index and feeds :summary: Short version for index and feeds
:header_cover: /images/posts/super-title/cover.png :header_cover: /images/posts/super-title/cover.png
:og_image: /images/posts/super-title/facebook_cover.png
``` ```
- To Markdown - To Markdown
@ -133,6 +138,7 @@ Slug: my-super-post
Authors: Alexis Metaireau, Conan Doyle Authors: Alexis Metaireau, Conan Doyle
Summary: Short version for index and feeds Summary: Short version for index and feeds
Header_Cover: /images/posts/super-title/cover.png Header_Cover: /images/posts/super-title/cover.png
Og_Image: http://example.com/facebook_cover.png
This is the content of my super blog post. This is the content of my super blog post.
``` ```

View File

@ -5,28 +5,56 @@
{{ super() }} {{ super() }}
{% for keyword in article.keywords %} {% for keyword in article.keywords %}
<meta name="keywords" contents="{{keyword}}" /> <meta name="keywords" content="{{keyword}}" >
{% endfor %} {% endfor %}
{% for description in article.description %} {% if description %}
<meta name="description" contents="{{description}}" /> <meta name="description" content="{{ description }}">
{% elif article.headline %}
<meta name="description" content="{{ article.headline }}">
{% elif article.summary %}
<meta name="description" content="{{ article.summary|striptags|truncate(140) }}">
{% endif %}
{% for author in article.authors %}
<meta name="author" content="{{ author }}">
{% endfor %} {% endfor %}
{% for tag in article.tags %} {% for tag in article.tags %}
<meta name="tags" contents="{{tag}}" /> <meta name="tags" content="{{tag}}">
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}
{% block opengraph %} {% block opengraph %}
{{ super() }} {{ super() }}
<meta property="og:type" content="article"> <meta property="og:type" content="article">
<meta property="article:author" content="{{ author }}"> {% for author in article.authors %}
<meta property="article:author" content="{{ author }}" >
{% endfor %}
<meta property="og:url" content="{{ SITEURL }}/{{ article.url }}"> <meta property="og:url" content="{{ SITEURL }}/{{ article.url }}">
<meta property="og:title" content="{{ article.title }}"> <meta property="og:title" content="{{ article.title }}">
<meta property="og:description" content="{{ article.headline }}">
<meta property="og:image" content="{{ SITEURL }}/{{ article.header_cover }}">
<meta property="article:published_time" content="{{ article.date }}"> <meta property="article:published_time" content="{{ article.date }}">
{% if description %}
<meta property="og:description" content="{{ description }}">
{% elif article.headline %}
<meta property="og:description" content="{{ article.headline }}">
{% elif article.summary %}
<meta property="og:description" content="{{ article.summary|striptags|truncate(140) }}">
{% endif %}
{% if article.og_image %}
{% if article.og_image|lower|truncate(4, True, '') == "http" %}
<meta property="og:image" content="{{ article.og_image }}">
{% else %}
<meta property="og:image" content="{{ SITEURL }}/{{ article.og_image }}">
{% endif %}
{% elif article.header_cover %}
<meta property="og:image" content="{{ SITEURL }}/{{ article.header_cover }}">
{% elif HEADER_COVER %}
<meta property="og:image" content="{{ SITEURL }}/{{ HEADER_COVER }}">
{% else %}
<meta property="og:image" content="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/images/post-bg.jpg">
{% endif %}
{% endblock %} {% endblock %}
{% block header %} {% block header %}

View File

@ -6,8 +6,6 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
{% if GOOGLE_SITE_VERIFICATION %} {% if GOOGLE_SITE_VERIFICATION %}
<meta name="google-site-verification" content="{{ GOOGLE_SITE_VERIFICATION }}"> <meta name="google-site-verification" content="{{ GOOGLE_SITE_VERIFICATION }}">