diff --git a/OpenBench/seo.py b/OpenBench/seo.py new file mode 100644 index 0000000..9765b5f --- /dev/null +++ b/OpenBench/seo.py @@ -0,0 +1,50 @@ +import django.http + +# Public pages worth listing for search engines. The API, the client +# endpoints, the account pages and the creation forms are left out on purpose. +PUBLIC_PATHS = [ + '/', + '/index/', + '/greens/', + '/users/', + '/events/', + '/machines/', + '/networks/', +] + +# Prefixes that crawlers have no business visiting +DISALLOWED_PREFIXES = [ + '/api/', + '/client', + '/scripts/', + '/login/', + '/register/', + '/logout/', + '/profile', + '/newTest/', + '/newTune/', + '/newDatagen/', + '/newNetwork/', +] + +def robots_txt(request): + + lines = ['User-agent: *'] + lines += ['Disallow: {}'.format(prefix) for prefix in DISALLOWED_PREFIXES] + lines += ['', 'Sitemap: {}'.format(request.build_absolute_uri('/sitemap.xml'))] + + return django.http.HttpResponse('\n'.join(lines) + '\n', content_type='text/plain') + +def sitemap_xml(request): + + entries = ''.join( + '{}'.format(request.build_absolute_uri(path)) + for path in PUBLIC_PATHS + ) + + body = ( + '\n' + '{}\n' + ).format(entries) + + return django.http.HttpResponse(body, content_type='application/xml') diff --git a/OpenBench/urls.py b/OpenBench/urls.py index 764d856..d8648f0 100644 --- a/OpenBench/urls.py +++ b/OpenBench/urls.py @@ -18,10 +18,14 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -import django.urls, OpenBench.views +import django.urls, OpenBench.views, OpenBench.seo urlpatterns = [ + # Files for search engines + django.urls.path(r'robots.txt', OpenBench.seo.robots_txt), + django.urls.path(r'sitemap.xml', OpenBench.seo.sitemap_xml), + # Links for account management django.urls.path(r'register/', OpenBench.views.register), django.urls.path(r'login/', OpenBench.views.login), diff --git a/Templates/OpenBench/base.html b/Templates/OpenBench/base.html index 7f4f2be..5fb41b7 100644 --- a/Templates/OpenBench/base.html +++ b/Templates/OpenBench/base.html @@ -27,7 +27,21 @@ - RektBench + {% block title %}RektBench - Distributed SPRT Testing for Chess Engines{% endblock %} + + + + + + + + + + + + {% block scripts %} {% endblock %}