Add OpenGraph etc meta tags
This commit is contained in:
parent
42559f20cc
commit
73db3f277d
10 changed files with 120 additions and 19 deletions
|
@ -58,8 +58,8 @@ FEED_ATOM = 'feed.atom'
|
|||
FEED_DOMAIN = SITEURL
|
||||
|
||||
# Setup plugins
|
||||
PLUGIN_PATHS = ["pelican_plugins"]
|
||||
PLUGINS = ["sitemap", "filetime_from_git", "pelican-jinja2content"]
|
||||
PLUGIN_PATHS = ["pelican_plugins", "plugins"]
|
||||
PLUGINS = ["sitemap", "filetime_from_git", "pelican-jinja2content", "open_graph"]
|
||||
|
||||
SITEMAP = {
|
||||
"format": "xml"
|
||||
|
|
58
plugins/open_graph.py
Normal file
58
plugins/open_graph.py
Normal file
|
@ -0,0 +1,58 @@
|
|||
import os.path
|
||||
|
||||
from pelican import signals
|
||||
|
||||
|
||||
def map_og_tag(instance, prop, og_tag, default=''):
|
||||
data = instance.metadata.get(prop, default)
|
||||
if data:
|
||||
instance.ogtags.append((og_tag, data))
|
||||
return instance
|
||||
|
||||
|
||||
def get_content_type(instance):
|
||||
return type(instance).__name__
|
||||
|
||||
|
||||
def tag_item(instance):
|
||||
instance_type = get_content_type(instance)
|
||||
|
||||
if instance_type not in ['Article', 'Page', 'Draft']:
|
||||
return
|
||||
|
||||
instance.ogtags = [
|
||||
('og:type', instance_type),
|
||||
('og:url', os.path.join(instance.settings.get('SITEURL', ''), instance.url)),
|
||||
('twitter:url', os.path.join(instance.settings.get('SITEURL', ''), instance.url)),
|
||||
('twitter:card', 'summary'),
|
||||
('og:site_name', instance.settings.get('SITENAME', '')),
|
||||
]
|
||||
|
||||
instance = map_og_tag(instance, 'title', 'og:title')
|
||||
instance = map_og_tag(instance, 'image', 'og:image')
|
||||
instance = map_og_tag(instance, 'summary', 'og:description')
|
||||
instance = map_og_tag(instance, 'author', 'article:author', instance.settings.get('AUTHOR'))
|
||||
instance = map_og_tag(instance, 'modified', 'article:modified_time')
|
||||
instance = map_og_tag(instance, 'date', 'article:published_time')
|
||||
|
||||
instance = map_og_tag(instance, 'image', 'twitter:image')
|
||||
instance = map_og_tag(instance, 'title', 'twitter:title')
|
||||
instance = map_og_tag(instance, 'summary', 'twitter:description')
|
||||
|
||||
if hasattr(instance, 'category'):
|
||||
instance.ogtags.append(('article:section', instance.category.name))
|
||||
|
||||
if hasattr(instance, 'tags'):
|
||||
for tag in instance.tags:
|
||||
instance.ogtags.append(('article:tag', tag.name))
|
||||
|
||||
instance.ogtags.append(('og:locale', instance.metadata.get('locale', 'en_GB')))
|
||||
|
||||
# Add non-og tags
|
||||
instance = map_og_tag(instance, 'summary', 'description')
|
||||
instance = map_og_tag(instance, 'author', 'author', instance.settings.get('AUTHOR'))
|
||||
instance.ogtags.append(('canonical', instance.settings.get('SITEURL')))
|
||||
|
||||
|
||||
def register():
|
||||
signals.content_object_init.connect(tag_item)
|
|
@ -1,16 +1,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="{{ DEFAULT_LANG }}">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="description" content="" />
|
||||
<meta name="author" content="" />
|
||||
<link rel="shortcut icon" href="/static/img/logo-transparent.png">
|
||||
<meta http-equiv="Content-Language" content="en" />
|
||||
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width" />
|
||||
<link rel="alternate" type="application/atom+xml" href="/feed.atom" />
|
||||
|
||||
<title>{% block htmltitle %}Page{% endblock%} - {{ SITENAME }}</title>
|
||||
{% block metadata %}{% endblock %}
|
||||
|
||||
<link rel="stylesheet" href="/static/css/index.css" type="text/css">
|
||||
<title>{% block htmltitle %}Page{% endblock %} - {{ SITENAME }}</title>
|
||||
|
||||
<link rel="stylesheet" href="/static/css/index.css" type="text/css" />
|
||||
<link rel="shortcut icon" href="/static/img/logo-transparent.png" type="image/png" />
|
||||
</head>
|
||||
<body id="page-top">
|
||||
{% block navbar %}
|
||||
|
@ -21,9 +23,9 @@
|
|||
|
||||
{% include "extras/footer.html" %}
|
||||
|
||||
<script src="/static/js/jquery.js"></script>
|
||||
<script src="/static/js/libs.js"></script>
|
||||
<script src="/static/js/app.js"></script>
|
||||
<script src="/static/js/jquery.js" type="text/javascript"></script>
|
||||
<script src="/static/js/libs.js" type="text/javascript"></script>
|
||||
<script src="/static/js/app.js" type="text/javascript"></script>
|
||||
|
||||
<noscript>
|
||||
<style>html, body { display: none }</style>
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
{{ article.title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block metadata %}
|
||||
{% for tag, value in page.ogtags %}
|
||||
<meta property="{{ tag }}" content="{{ value|striptags|e }}" />
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="bg-primary">
|
||||
<div class="container text-center text-uppercase">
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
All {{ category }}
|
||||
{% endblock %}
|
||||
|
||||
{% block metadata %}
|
||||
{% for tag, value in page.ogtags %}
|
||||
<meta property="{{ tag }}" content="{{ value|striptags|e }}" />
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="bg-primary">
|
||||
<div class="container">
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
{{ page.title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block metadata %}
|
||||
{% for tag, value in page.ogtags %}
|
||||
<meta property="{{ tag }}" content="{{ value|striptags|e }}" />
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ page.content }}
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="description" content="" />
|
||||
<meta name="author" content="" />
|
||||
<meta http-equiv="Content-Language" content="en" />
|
||||
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width" />
|
||||
<link rel="alternate" type="application/atom+xml" href="/feed.atom" />
|
||||
|
||||
<title>{{ page.title }} | {{ SITENAME }}</title>
|
||||
{% for tag, value in page.ogtags %}
|
||||
<meta property="{{ tag }}" content="{{ value|striptags|e }}" />
|
||||
{% endfor %}
|
||||
|
||||
<link rel="stylesheet" href="/static/css/index.css" type="text/css">
|
||||
<title>{{ page.title }} - {{ SITENAME }}</title>
|
||||
|
||||
<link rel="stylesheet" href="/static/css/index.css" type="text/css" />
|
||||
<link rel="shortcut icon" href="/static/img/logo-transparent.png" type="image/png" />
|
||||
</head>
|
||||
<body>
|
||||
{{ page.content }}
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
{{ page.html_title or page.title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block metadata %}
|
||||
{% for tag, value in page.ogtags %}
|
||||
<meta property="{{ tag }}" content="{{ value|striptags|e }}" />
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="bg-primary">
|
||||
<div class="container text-center text-uppercase">
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
{{ page.title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block metadata %}
|
||||
{% for tag, value in page.ogtags %}
|
||||
<meta property="{{ tag }}" content="{{ value|striptags|e }}" />
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ page.content }}
|
||||
{% endblock %}
|
||||
|
|
|
@ -4,6 +4,12 @@
|
|||
{{ article.title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block metadata %}
|
||||
{% for tag, value in article.ogtags %}
|
||||
<meta property="{{ tag }}" content="{{ value|striptags|e }}" />
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="bg-primary">
|
||||
<div class="container text-center text-uppercase">
|
||||
|
|
Reference in a new issue