Browse Source

Add SEO metadata to article and page

Update #15
Talha Mansoor 11 years ago
parent
commit
8014096380
3 changed files with 28 additions and 0 deletions
  1. 22 0
      templates/_includes/seo_metadata.html
  2. 3 0
      templates/article.html
  3. 3 0
      templates/page.html

+ 22 - 0
templates/_includes/seo_metadata.html

@@ -0,0 +1,22 @@
+{% macro seo_metadata(article) %}
+<meta property="og:title" content="{{ article.title|striptags }} {%if article.subtitle %} - {{ article.subtitle }} {% endif %}"/>
+<meta property="og:type" content="article" />
+<meta property="og:url" content="{{ SITEURL }}/{{ article.url }}" />
+<meta property="og:description" content="{{article.summary|striptags}}" />
+<meta property="og:site_name" content="{{ SITENAME|striptags }}" />
+<meta property="og:article:author" content="{{ article.author }}" />
+{% if article.date %}
+<meta property="og:article:published_time" content="{{ article.date.isoformat() }}" />
+{% endif %}
+{% if article.locale_modified and article.modified %}
+<meta property="" content="{{ article.modified.isoformat() }}" />
+{% endif %}
+<meta name="twitter:card" content="summary">
+{% from '_includes/_defaults.html' import TWITTER_USERNAME with context %}
+{%if TWITTER_USERNAME %}
+<meta name="twitter:creator" content="@{{TWITTER_USERNAME}}">
+{% endif %}
+<meta name="twitter:title" content="{{ article.title|striptags }} {%if article.subtitle %} - {{ article.subtitle }} {% endif %}">
+<meta name="twitter:description" content="{{article.summary|striptags}}">
+{% endmacro %}
+

+ 3 - 0
templates/article.html

@@ -15,6 +15,9 @@
 {% if article.tags or article.category or article.keywords %}
 <meta name="keywords" content="{{ [article.tags|join(', '), article.category, article.keywords]|join(', ') }}" />
 {% endif %}
+
+{% from '_includes/seo_metadata.html' import seo_metadata with context %}
+{{ seo_metadata(article) }}
 {% endblock meta_tags_in_head %}
 
 {% block content %}

+ 3 - 0
templates/page.html

@@ -15,6 +15,9 @@
 {% if page.keywords %}
 <meta name="keywords" content="{{ page.keywords }}" />
 {% endif %}
+
+{% from '_includes/seo_metadata.html' import seo_metadata with context %}
+{{ seo_metadata(article) }}
 {% endblock meta_tags_in_head %}
 
 {% block content %}