Merge lp:~widelands-dev/widelands-website/sitemap into lp:widelands-website

Proposed by kaputtnik
Status: Merged
Merged at revision: 434
Proposed branch: lp:~widelands-dev/widelands-website/sitemap
Merge into: lp:widelands-website
Diff against target: 502 lines (+168/-188)
17 files modified
news/sitemap.py (+7/-4)
pybb/sitemap.py (+13/-0)
settings.py (+1/-0)
sitemap_urls.py (+29/-0)
sphinxdoc/sitemap.py (+23/-0)
sphinxdoc/templates/sphinxdoc/app_list.html (+0/-14)
sphinxdoc/templates/sphinxdoc/documentation.html (+0/-65)
sphinxdoc/templates/sphinxdoc/genindex.html (+0/-38)
sphinxdoc/templates/sphinxdoc/modindex.html (+0/-13)
sphinxdoc/templates/sphinxdoc/search_form.html (+0/-12)
sphinxdoc/urls.py (+16/-37)
sphinxdoc/views.py (+1/-2)
static_sitemap.py (+13/-0)
templates/sphinxdoc/documentation.html (+1/-1)
urls.py (+5/-2)
wiki/sitemap.py (+13/-0)
wlhelp/sitemap.py (+46/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands-website/sitemap
Reviewer Review Type Date Requested Status
SirVer Approve
kaputtnik (community) Needs Resubmitting
Review via email: mp+310261@code.launchpad.net

Description of the change

Adding a sitemap.xml containing links to:

- Wiki (each article)
- News (news of last2 years)
- Forums (only links to section of forum, e.g. /forum/forum/3/)
- Mainpage
- Changelog
- Encyclopedia (Tribes, Buildings, Workers, Wares)
- Developer documentation (a link to the index)

I decided that each app has his own sitemap.py file containing what links get into sitemap.xml for this app. Added a new file sitemap_urls.py included from urls.py which gathers all sitemap files and serves the sitemap.xml.

Changes to sphinxdoc:

- Removed unused templates
- Updated urls.py to fit with future django versions (other urls.py files had this update already)

Changes to settings:

Same as in anti_spam_4, removed static string 'widelands' to make working with branches easier.

---------

There is a management command 'ping_google' available (works only if the site is registered on google webmaster tools), which could be used in a cron job to inform google of changes in sitemap.xml. I am not sure how often this should be called. See also: https://docs.djangoproject.com/en/1.8/ref/contrib/sitemaps/#pinging-google

To post a comment you must log in.
437. By kaputtnik

provide only news which are not in future and no drafts

438. By kaputtnik

resolved merge conflict because of settings.py

439. By kaputtnik

merged with trunk

440. By kaputtnik

merged with trunk

441. By kaputtnik

merged with trunk and fixed wrong resolving of merge conflict

Revision history for this message
kaputtnik (franku) wrote :

I have failed with the last merge conflict, causing the missing entry 'django.contrib.sitemaps' in installed apps :-S. But this is fixed now.

review: Needs Resubmitting
Revision history for this message
SirVer (sirver) wrote :

code lgtm. not tested.

review: Approve
442. By kaputtnik

consistent use of 2 blank lines after imports

Revision history for this message
kaputtnik (franku) wrote :

merged and committed.

Thanks for the review :-)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'news/sitemap.py'
2--- news/sitemap.py 2009-02-21 18:24:02 +0000
3+++ news/sitemap.py 2016-11-22 19:21:51 +0000
4@@ -1,5 +1,7 @@
5 from django.contrib.sitemaps import Sitemap
6-from widelands.news.models import Post
7+from .models import Post
8+from datetime import datetime
9+from datetime import timedelta
10
11
12 class NewsSitemap(Sitemap):
13@@ -7,7 +9,8 @@
14 priority = 0.5
15
16 def items(self):
17- return Post.objects.published()
18+ start_date = datetime.today() - timedelta(days=365 * 2)
19+ return Post.objects.published().filter(publish__gt=start_date)
20
21- def lastmod(self, obj):
22- return obj.publish
23+ def lastmod(self, obj):
24+ return obj.publish
25
26=== added file 'pybb/sitemap.py'
27--- pybb/sitemap.py 1970-01-01 00:00:00 +0000
28+++ pybb/sitemap.py 2016-11-22 19:21:51 +0000
29@@ -0,0 +1,13 @@
30+from django.contrib.sitemaps import Sitemap
31+from pybb.models import Forum
32+
33+
34+class ForumSitemap(Sitemap):
35+ changefreq = 'monthly'
36+ priority = 0.5
37+
38+ def items(self):
39+ return Forum.objects.all()
40+
41+ def lastmod(self, obj):
42+ return obj.updated
43
44=== modified file 'settings.py'
45--- settings.py 2016-11-15 08:03:19 +0000
46+++ settings.py 2016-11-22 19:21:51 +0000
47@@ -76,6 +76,7 @@
48 'django.contrib.staticfiles',
49 'django.contrib.sites',
50 'django.contrib.humanize',
51+ 'django.contrib.sitemaps',
52 'django_comments',
53 'nocaptcha_recaptcha',
54 # Thirdparty apps, but need preload
55
56=== added file 'sitemap_urls.py'
57--- sitemap_urls.py 1970-01-01 00:00:00 +0000
58+++ sitemap_urls.py 2016-11-22 19:21:51 +0000
59@@ -0,0 +1,29 @@
60+from django.conf.urls import *
61+
62+from mainpage.views import mainpage
63+from django.contrib.sitemaps.views import sitemap
64+from static_sitemap import StaticViewSitemap
65+from wiki.sitemap import *
66+from news.sitemap import *
67+from pybb.sitemap import *
68+from wlhelp.sitemap import *
69+from sphinxdoc.sitemap import *
70+
71+
72+sitemaps = {
73+ 'static': StaticViewSitemap,
74+ 'docs': DocumentationSitemap,
75+ 'news': NewsSitemap,
76+ 'wiki': WikiSitemap,
77+ 'forum': ForumSitemap,
78+ 'wlhelptribe': WlHelpTribeSitemap,
79+ 'wlhelpware': WlHelpWareSitemap,
80+ 'wlhelpworker': WlHelpWorkerSitemap,
81+ 'wlhelpbuildings': WlHelpBuildingSitemap,
82+ }
83+
84+urlpatterns = [
85+ # Creating a sitemap.xml
86+ url(r'^$', sitemap, {'sitemaps': sitemaps},
87+ name='django.contrib.sitemaps.views.sitemap')
88+ ]
89
90=== added file 'sphinxdoc/sitemap.py'
91--- sphinxdoc/sitemap.py 1970-01-01 00:00:00 +0000
92+++ sphinxdoc/sitemap.py 2016-11-22 19:21:51 +0000
93@@ -0,0 +1,23 @@
94+from django.contrib.sitemaps import Sitemap
95+from sphinxdoc.models import App
96+import datetime
97+import os
98+
99+app = App.objects.get(slug='wl')
100+
101+
102+class DocumentationSitemap(Sitemap):
103+ """This is just a dummy class to return the link to docs/wl/genindex."""
104+
105+ changefreq = 'yearly'
106+ priority = 0.5
107+
108+ def items(self):
109+ return ['']
110+
111+ def location(self, item):
112+ return '/docs/wl/genindex/'
113+
114+ def lastmod(self, item):
115+ return datetime.datetime.fromtimestamp(
116+ os.path.getmtime(os.path.join(app.path, 'last_build')))
117
118=== removed directory 'sphinxdoc/templates'
119=== removed directory 'sphinxdoc/templates/sphinxdoc'
120=== removed file 'sphinxdoc/templates/sphinxdoc/app_list.html'
121--- sphinxdoc/templates/sphinxdoc/app_list.html 2016-06-13 07:14:59 +0000
122+++ sphinxdoc/templates/sphinxdoc/app_list.html 1970-01-01 00:00:00 +0000
123@@ -1,14 +0,0 @@
124-{% extends 'base.html' %}
125-
126-{% block title %}{{ block.super }} » Documentation Overview{% endblock %}
127-
128-{% block content %}
129-<div>
130- <h2 class="pagetitle">Documentation Overview</h2>
131- <ul>
132- {% for app in app_list %}
133- <li><a href="{{ app.get_absolute_url }}">{{ app.name }}</a></li>
134- {% endfor %}
135- </ul>
136-</div>
137-{% endblock content %}
138
139=== removed file 'sphinxdoc/templates/sphinxdoc/documentation.html'
140--- sphinxdoc/templates/sphinxdoc/documentation.html 2016-06-13 07:14:59 +0000
141+++ sphinxdoc/templates/sphinxdoc/documentation.html 1970-01-01 00:00:00 +0000
142@@ -1,65 +0,0 @@
143-{% extends 'base.html' %}
144-
145-{% block title %}{{ block.super }} » {{ app.name }}{% for p in doc.parents %} » {{ p.title|striptags|safe }}{% endfor %} » {{ doc.title|striptags|safe }}{% endblock %}
146-
147-{% block content %}
148-<div class="pagination-top">
149- » <a href="{{ app.get_absolute_url }}">{{ app.name }}</a>
150- {% for p in doc.parents %}
151- » <a href="{{ p.link }}">{{ p.title|safe }}</a>
152- {% endfor %}
153- » {{ doc.title|safe }}
154- {% if doc.prev or doc.next %}
155- <br /><br />
156- <span class="left">
157- {% if doc.prev %}
158- Prev: <a href="{{ doc.prev.link }}">{{ doc.prev.title|safe }}</a>
159- {% endif %}</span><span class="right">
160- {% if doc.next %}
161- Next: <a href="{{ doc.next.link }}">{{ doc.next.title|safe }}</a>
162- {% endif %}</span>
163- {% endif %}
164-</div>
165-
166-<div class="sphinx">
167- {% block doc_body %}
168- {{ doc.body|safe }}
169- {% endblock %}
170-</div>
171-
172-<div class="pagination-bottom">
173- {% if doc.prev or doc.next %}
174- <span class="left">
175- {% if doc.prev %}
176- Prev: <a href="{{ doc.prev.link }}">{{ doc.prev.title|safe }}</a>
177- {% endif %}</span><span class="right">
178- {% if doc.next %}
179- Next: <a href="{{ doc.next.link }}">{{ doc.next.title|safe }}</a>
180- {% endif %}</span>
181- <br /><br />
182- {% endif %}
183- » <a href="{{ app.get_absolute_url }}">{{ app.name }} documentation</a>
184- {% for p in doc.parents %}
185- » <a href="{{ p.link }}">{{ p.title|safe }}</a>
186- {% endfor %}
187- » {{ doc.title|safe }}
188- <br /><br />
189- Last update: {{ update_date|date:"Y-m-d H:i" }} (<a href="http://www.timeanddate.com/worldclock/city.html?n=37">CET</a>)
190-</div>
191-{% endblock content %}
192-
193-{% block sidebar %}
194- {% block doc_toc %}
195-<div class="box">
196- <h2>Contents</h2>
197- {{ doc.toc|safe }}
198-</div>
199- {% endblock %}
200-<div class="box">
201- <h2>Search</h2>
202- <em>Not yet implemented</em>
203- {# {% load docs %} #}
204- {# {% search_form %} #}
205-</div>
206- {{ block.super }}
207-{% endblock sidebar %}
208
209=== removed file 'sphinxdoc/templates/sphinxdoc/genindex.html'
210--- sphinxdoc/templates/sphinxdoc/genindex.html 2016-06-13 07:14:59 +0000
211+++ sphinxdoc/templates/sphinxdoc/genindex.html 1970-01-01 00:00:00 +0000
212@@ -1,38 +0,0 @@
213-{% extends 'sphinxdoc/documentation.html' %}
214-
215-{% block doc_body %}
216- <h1>General Index</h1>
217- <p class="indexletters">
218- {% for letter, _ in doc.genindexentries %}
219- <a href="#{{ letter }}">{{ letter }}</a> {% if not forloop.last %} •{% endif %}
220- {% endfor %}
221- </p>
222-
223- {% for letter, entries in doc.genindexentries %}
224- <br />
225- <h2 id="{{ letter }}">{{ letter }}</h2>
226- <dl class="index">
227- {% for name, contents in entries %}
228- <dt>
229- {# contents.0 is a list of links for the item #}
230- {% if contents.0 %}
231- <a href="{{ contents.0.0 }}">{{ name }}</a>
232- {% else %}
233- {{ name }}
234- {% endif %}
235- </dt>
236- {# contents.1 is a list of subitems #}
237- {% if contents.1 %}
238- {% for subname, sublinks in contents.1 %}
239- <dd>
240- <a href="{{ sublinks.0 }}">{{ subname }}</a>
241- {% for link in sublinks|slice:"1:" %}, <a href="{{ link }}">[Link]</a>{% endfor %}
242- </dd>
243- {% endfor %}
244- {% endif %}
245- {% endfor %}
246- </dl>
247- {% endfor %}
248- <br />
249-{% endblock doc_body %}
250-{% block doc_toc %}{% endblock %}
251
252=== removed file 'sphinxdoc/templates/sphinxdoc/modindex.html'
253--- sphinxdoc/templates/sphinxdoc/modindex.html 2016-06-13 07:14:59 +0000
254+++ sphinxdoc/templates/sphinxdoc/modindex.html 1970-01-01 00:00:00 +0000
255@@ -1,13 +0,0 @@
256-{% extends 'sphinxdoc/documentation.html' %}
257-
258-{% block doc_body %}
259- <h1>Module Index</h1>
260- <dl>
261- {% for modname, collapse, cgroup, indent, fname, synops, pform, dep in doc.modindexentries %}
262- <dt><a href="{{ fname }}"><tt class="literal xref">{{ modname }}</tt></a></dt>
263- <dd>{{ synops }}</dd>
264- {% endfor %}
265- </dl>
266- <br />
267-{% endblock doc_body %}
268-{% block doc_toc %}{% endblock %}
269
270=== removed file 'sphinxdoc/templates/sphinxdoc/search_form.html'
271--- sphinxdoc/templates/sphinxdoc/search_form.html 2016-06-13 07:14:59 +0000
272+++ sphinxdoc/templates/sphinxdoc/search_form.html 1970-01-01 00:00:00 +0000
273@@ -1,12 +0,0 @@
274-<form action="{{ action|escape }}" id="{{ search_form_id|escape }}" class="search">
275- <div>
276- <input type="hidden" name="cx" value="009763561546736975936:e88ek0eurf4" />
277- <input type="hidden" name="cof" value="FORID:11" />
278- <input type="hidden" name="ie" value="UTF-8" />
279- <input type="hidden" name="hl" value="{{ lang|escape }}" />
280- {{ form.q }}
281- <input type="submit" name="sa" class="submit" value="Search" />
282- {{ form.as_q }}
283- </div>
284-</form>
285-<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form={{ search_form_id|escape }}&amp;lang={{ lang|escape }}"></script>
286\ No newline at end of file
287
288=== modified file 'sphinxdoc/urls.py'
289--- sphinxdoc/urls.py 2016-06-13 07:14:59 +0000
290+++ sphinxdoc/urls.py 2016-11-22 19:21:51 +0000
291@@ -2,7 +2,7 @@
292
293 from django.conf.urls import *
294 from django.views.generic.list import ListView
295-
296+from sphinxdoc import views
297 from sphinxdoc import models
298
299 app_info = {
300@@ -11,39 +11,18 @@
301 }
302
303
304-urlpatterns = patterns('sphinxdoc.views',
305- url(
306- r'^$',
307- ListView.as_view(),
308- app_info,
309- ),
310- url(
311- r'^(?P<slug>[\w-]+)/search/$',
312- 'search',
313- name='doc-search',
314- ),
315- url(
316- r'^(?P<slug>[\w-]+)/_images/(?P<path>.*)$',
317- 'images',
318- ),
319- url(
320- r'^(?P<slug>[\w-]+)/_source/(?P<path>.*)$',
321- 'source',
322- ),
323- url(
324- r'^(?P<slug>[\w-]+)/_objects/$',
325- 'objects_inventory',
326- name='objects-inv',
327- ),
328- url(
329- r'^(?P<slug>[\w-]+)/$',
330- 'documentation',
331- {'url': ''},
332- name='doc-index',
333- ),
334- url(
335- r'^(?P<slug>[\w-]+)/(?P<url>(([\w-]+)/)+)$',
336- 'documentation',
337- name='doc-detail',
338- ),
339-)
340+urlpatterns = [
341+ url(r'^$', ListView.as_view(), app_info,),
342+ url(r'^(?P<slug>[\w-]+)/search/$',
343+ views.search, name='doc-search', ),
344+ url(r'^(?P<slug>[\w-]+)/_images/(?P<path>.*)$',
345+ views.images, ),
346+ url(r'^(?P<slug>[\w-]+)/_source/(?P<path>.*)$',
347+ views.source, ),
348+ url(r'^(?P<slug>[\w-]+)/_objects/$',
349+ views.objects_inventory, name='objects-inv', ),
350+ url(r'^(?P<slug>[\w-]+)/$',
351+ views.documentation, {'url': ''}, name='doc-index', ),
352+ url(r'^(?P<slug>[\w-]+)/(?P<url>(([\w-]+)/)+)$',
353+ views.documentation, name='doc-detail', ),
354+]
355
356=== modified file 'sphinxdoc/views.py'
357--- sphinxdoc/views.py 2016-08-02 19:22:42 +0000
358+++ sphinxdoc/views.py 2016-11-22 19:21:51 +0000
359@@ -6,7 +6,6 @@
360 from django.http import Http404
361 from django.shortcuts import get_object_or_404, render_to_response
362 from django.template import RequestContext
363-#from django.utils import simplejson as json
364 import json
365 from django.views import static
366
367@@ -52,7 +51,7 @@
368 }
369 if 'title' not in data['doc']:
370 data['doc']['title'] = SPECIAL_TITLES[page_name]
371-
372+
373 return render_to_response(templates, data,
374 context_instance=RequestContext(request))
375
376
377=== added file 'static_sitemap.py'
378--- static_sitemap.py 1970-01-01 00:00:00 +0000
379+++ static_sitemap.py 2016-11-22 19:21:51 +0000
380@@ -0,0 +1,13 @@
381+from django.contrib.sitemaps import Sitemap
382+from django.core.urlresolvers import reverse
383+
384+
385+class StaticViewSitemap(Sitemap):
386+ priority = 0.5
387+ changefreq = 'yearly'
388+
389+ def items(self):
390+ return ['mainpage', 'changelog']
391+
392+ def location(self, item):
393+ return reverse(item)
394
395=== modified file 'templates/sphinxdoc/documentation.html'
396--- templates/sphinxdoc/documentation.html 2016-07-19 21:36:58 +0000
397+++ templates/sphinxdoc/documentation.html 2016-11-22 19:21:51 +0000
398@@ -30,7 +30,7 @@
399
400 <div class="sphinx">
401 {% block doc_body %}
402- {{ doc.body|safe }}
403+ {{ doc.body|safe }}
404 {% endblock %}
405 </div>
406
407
408=== modified file 'urls.py'
409--- urls.py 2016-11-14 21:05:57 +0000
410+++ urls.py 2016-11-22 19:21:51 +0000
411@@ -5,17 +5,20 @@
412 admin.autodiscover()
413
414 from mainpage.views import mainpage
415-
416 from news.feeds import NewsPostsFeed
417 from django.views.generic.base import RedirectView
418 from django.contrib.syndication.views import Feed
419 from registration.backends.hmac.views import RegistrationView
420 from mainpage.forms import RegistrationWithCaptchaForm
421
422+
423 urlpatterns = [
424+ # Creating a sitemap.xml
425+ url(r'^sitemap\.xml/', include('sitemap_urls')),
426+
427 # Uncomment the next line to enable the admin:
428 url(r'^admin/', admin.site.urls),
429-
430+
431 # Django builtin / Registration
432 # overwrite registration with own implementation
433 url (r'^accounts/register/$', RegistrationView.as_view(form_class=RegistrationWithCaptchaForm), name='registration_register'),
434
435=== added file 'wiki/sitemap.py'
436--- wiki/sitemap.py 1970-01-01 00:00:00 +0000
437+++ wiki/sitemap.py 2016-11-22 19:21:51 +0000
438@@ -0,0 +1,13 @@
439+from django.contrib.sitemaps import Sitemap
440+from wiki.models import Article
441+
442+
443+class WikiSitemap(Sitemap):
444+ changefreq = 'yearly'
445+ priority = 0.5
446+
447+ def items(self):
448+ return Article.objects.all()
449+
450+ def lastmod(self, obj):
451+ return obj.last_update
452
453=== added file 'wlhelp/sitemap.py'
454--- wlhelp/sitemap.py 1970-01-01 00:00:00 +0000
455+++ wlhelp/sitemap.py 2016-11-22 19:21:51 +0000
456@@ -0,0 +1,46 @@
457+from django.contrib.sitemaps import Sitemap
458+from wlhelp.models import Tribe, Building, Ware, Worker
459+
460+
461+class WlHelpTribeSitemap(Sitemap):
462+ changefreq = 'yearly'
463+ priority = 0.5
464+
465+ def items(self):
466+ return Tribe.objects.all()
467+
468+ def location(self, obj):
469+ return '/encyclopedia/%s' % obj.name
470+
471+
472+class WlHelpBuildingSitemap(Sitemap):
473+ changefreq = 'yearly'
474+ priority = 0.5
475+
476+ def items(self):
477+ return Building.objects.all()
478+
479+ def location(self, obj):
480+ return '/encyclopedia/%s/buildings/%s' % (obj.tribe.name, obj.name)
481+
482+
483+class WlHelpWareSitemap(Sitemap):
484+ changefreq = 'yearly'
485+ priority = 0.5
486+
487+ def items(self):
488+ return Ware.objects.all()
489+
490+ def location(self, obj):
491+ return '/encyclopedia/%s/wares/%s' % (obj.tribe.name, obj.name)
492+
493+
494+class WlHelpWorkerSitemap(Sitemap):
495+ changefreq = 'yearly'
496+ priority = 0.5
497+
498+ def items(self):
499+ return Worker.objects.all()
500+
501+ def location(self, obj):
502+ return '/encyclopedia/%s/workers/%s' % (obj.tribe.name, obj.name)

Subscribers

People subscribed via source and target branches