Sitemaps for page that should be public viewable

This commit is contained in:
2017-11-03 07:16:47 +01:00
parent 8719c2377a
commit 7ef69849a4
8 changed files with 72 additions and 3210 deletions

View File

@@ -1,31 +1,23 @@
"""Add News and static pages to the global sitemap."""
from django.contrib.sitemaps import Sitemap
from kasu.sitemaps import GenericSitemap
from .models import Article, Page
class ArticleSitemap(Sitemap):
"""Add the news artivles to the Sitemap"""
changefreq = "never"
priority = 0.6
class ArticleSitemap(GenericSitemap):
"""Add all published news articles to the Sitemap."""
min_priority = 0.25
def items(self):
@staticmethod
def items():
"""only add published articles to the sitemap"""
return Article.objects.published()
def lastmod(self, article):
"""return the last modification date of the article."""
return article.date_modified
class PageSitemap(Sitemap):
class PageSitemap(GenericSitemap):
"""add the static pages to the sitemap."""
changefreq = "monthly"
priority = 0.4
min_priority = 0.5
def items(self):
@staticmethod
def items():
"""add all pages to the sitemap."""
return Page.objects.all()
def lastmod(self, page):
"""return the last modification date of the page."""
return page.date_modified

View File

@@ -1,23 +1,16 @@
"""To geneate a Sitemap with all events."""
from django.contrib.sitemaps import Sitemap
from kasu.sitemaps import GenericSitemap
from django.utils import timezone
from .models import Event
class EventSitemap(Sitemap):
"""To add an event to the global sitemap."""
class EventSitemap(GenericSitemap):
"""sitemap to help indexing all events on this site."""
changefreq = "never"
protocol = 'https'
priority_field = 'start'
def items(self):
"""add all events to the sitemap."""
@staticmethod
def items():
"""add all upcoming and archived events to the sitemap."""
return Event.objects.all()
def priority(self, event):
"""give events closer to the present a higer priority for crawlers."""
delta = abs((timezone.now() - event.start) / 300.0)
return max(1 - delta, 0.1)
def lastmod(self, event):
"""return the last modification date."""
return event.date_modified

View File

@@ -1,7 +1,7 @@
{% extends "events/event_detail.html" %}
{% load i18n thumbnail %}
{% block title %}{{event.name}}{% endblock %}
{% block title %}{% trans "Photos" %}: {{ event.name }}{% endblock %}
{% block opengraph %}
<meta property="og:type" content="album" />

27
src/kasu/sitemaps.py Normal file
View File

@@ -0,0 +1,27 @@
from django.contrib.sitemaps import Sitemap
from django.utils import timezone
class GenericSitemap(Sitemap):
changefreq = "never"
default_priority = 0.5
lastmod_field = 'date_modified'
min_priority = 0.1
priority_field = 'date_modified'
protocol = 'https'
def lastmod(self, entry):
"""return the last modification date."""
return getattr(entry, self.lastmod_field)
def priority(self, entry):
"""
Set a priority hint for crawlers.
hightes priority = 1, lowest priority = 0.1, normal priority = 0.5
updatet entries in the next/past 30 days (a month) should have a normal
priority. The nearer to the present day the higher the priority should
be.
"""
delta = timezone.now() - getattr(entry, self.priority_field)
priority = round(1 - abs(self.default_priority / 30 * delta.days), 2)
return max(self.min_priority, priority)

File diff suppressed because one or more lines are too long

View File

@@ -3,5 +3,4 @@ Sitemap: https://kasu.at/sitemap.xml
Disallow: /admin/
Disallow: /cgi-bin/
Disallow: /users/
Disallow: /ranking/
Host: kasu.at

View File

@@ -10,11 +10,17 @@ from content import views, feeds
from content.sitemaps import ArticleSitemap, PageSitemap
from events.sitemaps import EventSitemap
from events.views import EventListIcal
from mahjong_ranking.sitemaps import *
from maistar_ranking.sitemaps import *
from membership.views import MembershipDetail
admin.autodiscover()
sitemaps = { # Ignore PyLintBear (C0103)
sitemaps = {
'event_rankings': EventRankingSitemap,
'event_hanchans': EventHanchanSitemap,
'mahjong_seasons': MajongSeasonSitemap,
'maistar_games': MaistarGamesSitemap,
'articles': ArticleSitemap,
'events': EventSitemap,
'pages': PageSitemap,
@@ -68,4 +74,5 @@ if settings.DEBUG:
urlpatterns += [url(r'^rosetta/', include('rosetta.urls'))]
if 'debug_toolbar' in settings.INSTALLED_APPS:
import debug_toolbar
urlpatterns += [url(r'^__debug__/', include(debug_toolbar.urls)), ]

View File

@@ -0,0 +1,17 @@
"""To geneate a Sitemap with all events."""
from kasu.sitemaps import GenericSitemap
from django.utils import timezone
from django.urls import reverse
from events.models import Event
class MaistarGamesSitemap(GenericSitemap):
@staticmethod
def items():
"""add all upcoming and archived events to the sitemap."""
return Event.objects.all().exclude(maistargame_set=None)
@staticmethod
def location(event):
return reverse('maistar-game-list', kwargs={'event': event.id})