diff --git a/shared/templatetags/__init__.py b/shared/templatetags/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/shared/templatetags/structured_data.py b/shared/templatetags/structured_data.py new file mode 100644 index 0000000000000000000000000000000000000000..94be91221b9ecbe4326d13edeb77e953b484af4d --- /dev/null +++ b/shared/templatetags/structured_data.py @@ -0,0 +1,45 @@ +# definice vlastnich tagu pro strukturovana data (pro ucely SEO) + +import urllib + +import django.middleware.csrf +from django import template +from django.conf import settings +from django.utils.safestring import mark_safe + +register = template.Library() + + +@register.simple_tag +def breadcrumb(page): + """ SEO structured data typu breadcrumb """ + + parent = page.get_parent() if page.get_parent().url else page + + return mark_safe( + """<script type="application/ld+json">{ + "@context": "http://schema.org", + "@type": "BreadcrumbList", + "itemListElement":[ +{ + "@type": "ListItem", + "position": 1, + "item":{ + "@id": "https://pirati.cz", + "name": "Piráti" }}, + { + "@type": "ListItem", + "position": 2, + "item": { + "@id": "%s", + "name": "%s"}}, + { + "@type": "ListItem", + "position": 3, + "item": { + "@id": "%s", + "name": "%s"}} +</script> +""" + % (parent.url, parent, page.url, page) + ) diff --git a/uniweb/templates/uniweb/base.html b/uniweb/templates/uniweb/base.html index e7960a3d35ccfbdc4274049566e9c4b827a27e27..047d31abaf0bc67eec3bb1cabbf7857312aa2ff5 100644 --- a/uniweb/templates/uniweb/base.html +++ b/uniweb/templates/uniweb/base.html @@ -1,4 +1,4 @@ -{% load static wagtailcore_tags wagtailimages_tags wagtailmetadata_tags %} +{% load static wagtailcore_tags wagtailimages_tags wagtailmetadata_tags structured_data %} <!doctype html> <html lang="cs"> <head> @@ -86,6 +86,7 @@ </nav> <div class="container container--default lg:py-4"> + {% breadcrumb page %} {% block content %}{% endblock %} </div>