From dd3b8180957ab3f6b290847f24114e3f9284386c Mon Sep 17 00:00:00 2001
From: Jarmil <jarmil.halamicek@seznam.cz>
Date: Mon, 14 Sep 2020 12:42:49 +0200
Subject: [PATCH] Pridani breadcrumb - vylepsene SEO

---
 shared/templatetags/__init__.py        |  0
 shared/templatetags/structured_data.py | 45 ++++++++++++++++++++++++++
 uniweb/templates/uniweb/base.html      |  3 +-
 3 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 shared/templatetags/__init__.py
 create mode 100644 shared/templatetags/structured_data.py

diff --git a/shared/templatetags/__init__.py b/shared/templatetags/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/shared/templatetags/structured_data.py b/shared/templatetags/structured_data.py
new file mode 100644
index 000000000..94be91221
--- /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 e7960a3d3..047d31aba 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>
 
-- 
GitLab