Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add webpage schema

Krzysztof Wolski62d3a822b4dc
diff --git a/saleor/core/context_processors.py b/saleor/core/context_processors.py
index 6431659fe2..0ad06852a9 100644
--- a/saleor/core/context_processors.py
+++ b/saleor/core/context_processors.py
@@ -1,4 +1,9 @@
+from __future__ import unicode_literals
+
+import json
+
from django.conf import settings
+from django.urls import reverse
from ..product.models import Category
@@ -25,3 +30,21 @@ def categories(request):
def search_enabled(request):
return {'SEARCH_IS_ENABLED': bool(settings.SEARCH_BACKENDS)}
+
+
+def webpage_schema(request):
+ # Todo: add editing this data in dashboard
+ data = {
+ '@context': 'http://schema.org',
+ '@type': 'WebSite',
+ 'url': settings.SITE_ADDRESS,
+ 'name': settings.SITE_NAME,
+ 'description': settings.SITE_DESCRIPTION,
+ }
+ if bool(settings.SEARCH_BACKENDS):
+ data['potentialAction'] = {
+ '@type': 'SearchAction',
+ 'target': '%s%s?q={search_term}' % (settings.SITE_ADDRESS,
+ reverse('search:search')),
+ 'query-input': 'required name=search_term'}
+ return {'webpage_schema': json.dumps(data)}
diff --git a/saleor/settings.py b/saleor/settings.py
index 316fbdbdb6..4a9f1f96af 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -94,6 +94,7 @@ context_processors = [
'saleor.cart.context_processors.cart_counter',
'saleor.core.context_processors.search_enabled',
'saleor.site.context_processors.settings',
+ 'saleor.core.context_processors.webpage_schema',
]
loaders = [
@@ -373,3 +374,7 @@ GRAPHENE = {
}
SITE_SETTINGS_ID = 1
+
+SITE_ADDRESS = os.environ.get('SITE_ADDRESS', 'localhost:8000')
+SITE_NAME = os.environ.get('SITE_NAME', 'Saleor')
+SITE_DESCRIPTION = 'Shop with unique products and great prices.'
diff --git a/templates/base.html b/templates/base.html
index 959c57d3fe..a25d35062f 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -24,7 +24,7 @@
<![endif]-->
</head>
- <body itemscope itemtype="http://schema.org/WebPage">
+ <body>
{% block header %}
<header class="navbar" role="navigation">
<div class="navbar__login hidden-sm-down">
@@ -209,6 +209,7 @@
{% render_bundle 'vendor' 'js' %}
{% render_bundle 'storefront' 'js' %}
{% endblock footer_scripts %}
+ <script type="application/ld+json">{{ webpage_schema|safe }}</script>
</body>
</html>