diff --git a/mediagoblin/routing.py b/mediagoblin/routing.py
index 1393f01..93222c5 100644
a
|
b
|
def get_url_map():
|
29 | 29 | add_route('index', '/', 'mediagoblin.views:root_view') |
30 | 30 | add_route('terms_of_service','/terms_of_service', |
31 | 31 | 'mediagoblin.views:terms_of_service') |
| 32 | add_route('sitemap','/sitemap.xml','mediagoblin.views:sitemap') |
| 33 | add_route('robots','/robots.txt','mediagoblin.views:robots') |
32 | 34 | mount('/auth', auth_routes) |
33 | 35 | mount('/mod', moderation_routes) |
34 | 36 | |
diff --git a/mediagoblin/templates/mediagoblin/robots.txt b/mediagoblin/templates/mediagoblin/robots.txt
new file mode 100644
index 0000000..be86b19
-
|
+
|
|
| 1 | Sitemap: {{ request.host_url }}sitemap.xml |
diff --git a/mediagoblin/templates/mediagoblin/sitemap.xml b/mediagoblin/templates/mediagoblin/sitemap.xml
new file mode 100644
index 0000000..877856e
-
|
+
|
|
| 1 | <?xml version="1.0" encoding="utf-8"?> |
| 2 | |
| 3 | <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
| 4 | {% for page in page_list %} |
| 5 | <url> |
| 6 | <loc>{{ page.loc }}</loc> |
| 7 | </url>{% endfor %} |
| 8 | </urlset> |
diff --git a/mediagoblin/views.py b/mediagoblin/views.py
index 4185c1b..8449b43 100644
a
|
b
|
from mediagoblin.db.models import MediaEntry
|
19 | 19 | from mediagoblin.tools.pagination import Pagination |
20 | 20 | from mediagoblin.tools.response import render_to_response, render_404 |
21 | 21 | from mediagoblin.decorators import uses_pagination, user_not_banned |
| 22 | from mediagoblin.db.models import (MediaEntry, Collection, User) |
22 | 23 | |
23 | 24 | |
24 | 25 | @user_not_banned |
… |
… |
def terms_of_service(request):
|
51 | 52 | |
52 | 53 | return render_to_response(request, |
53 | 54 | 'mediagoblin/terms_of_service.html', {}) |
| 55 | |
| 56 | def sitemap(request): |
| 57 | page_list = [] |
| 58 | host_url = request.host_url[:-1] |
| 59 | list_of_users = User.query.all() |
| 60 | list_of_media = MediaEntry.query.filter_by( |
| 61 | state=u'processed') |
| 62 | list_of_collections = Collection.query.all() |
| 63 | |
| 64 | for item in list_of_users: |
| 65 | if item.has_privilege(u'active'): |
| 66 | page_list.append({"loc": host_url + request.urlgen("mediagoblin.user_pages.user_home", |
| 67 | user=item.username)}) |
| 68 | page_list.append({"loc": host_url + request.urlgen("mediagoblin.user_pages.user_gallery", |
| 69 | user=item.username)}) |
| 70 | page_list.append({"loc": host_url + request.urlgen("mediagoblin.user_pages.collection_list", |
| 71 | user=item.username)}) |
| 72 | for item in list_of_media: |
| 73 | page_list.append({"loc": host_url + item.url_for_self(request.urlgen)}) |
| 74 | for item in list_of_collections: |
| 75 | page_list.append({"loc": host_url + item.url_for_self(request.urlgen)}) |
| 76 | |
| 77 | return render_to_response(request, |
| 78 | 'mediagoblin/sitemap.xml', {"page_list": page_list}) |
| 79 | |
| 80 | def robots(request): |
| 81 | return render_to_response(request,'mediagoblin/robots.txt', {}) |