From bcfa0b24c1352fe523a70901cb9f278e6df16c00 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Thu, 25 Sep 2014 21:50:25 -0400 Subject: [PATCH] Add a robots view to support robots.txt. --- xonstat/__init__.py | 4 ++++ xonstat/static/robots.txt | 7 +++++++ xonstat/views/__init__.py | 2 ++ xonstat/views/static.py | 7 +++++++ 4 files changed, 20 insertions(+) create mode 100644 xonstat/static/robots.txt create mode 100644 xonstat/views/static.py diff --git a/xonstat/__init__.py b/xonstat/__init__.py index d2ace0a..0dfe363 100644 --- a/xonstat/__init__.py +++ b/xonstat/__init__.py @@ -42,6 +42,10 @@ def main(global_config, **settings): # for static assets config.add_static_view('static', 'xonstat:static') + # robots + config.add_route("robots", "robots.txt") + config.add_view(robots, route_name="robots") + # for 404s config.add_view(notfound, context=HTTPNotFound, renderer="404.mako") diff --git a/xonstat/static/robots.txt b/xonstat/static/robots.txt new file mode 100644 index 0000000..9c6ebed --- /dev/null +++ b/xonstat/static/robots.txt @@ -0,0 +1,7 @@ +User-agent: * +Disallow: /players/ +Disallow: /player/ +Disallow: /games/ +Disallow: /game/ +Disallow: /servers/ +Disallow: /server/ diff --git a/xonstat/views/__init__.py b/xonstat/views/__init__.py index 85fd2ca..e795308 100644 --- a/xonstat/views/__init__.py +++ b/xonstat/views/__init__.py @@ -30,3 +30,5 @@ from xonstat.views.main import main_index, top_players_by_time, top_servers_by from xonstat.views.main import top_servers_by_players, top_maps_by_times_played from xonstat.views.admin import forbidden, login, merge + +from xonstat.views.static import robots diff --git a/xonstat/views/static.py b/xonstat/views/static.py new file mode 100644 index 0000000..9d45854 --- /dev/null +++ b/xonstat/views/static.py @@ -0,0 +1,7 @@ +import os +from pyramid.response import FileResponse + +def robots(request): + here = os.path.dirname(__file__) + robots_txt = os.path.join(here, "../static", "robots.txt") + return FileResponse(robots_txt, request=request) -- 2.39.2