diff --git a/TealCode/TealCode/urls.py b/TealCode/TealCode/urls.py index 36ba2d2..1f36fb8 100644 --- a/TealCode/TealCode/urls.py +++ b/TealCode/TealCode/urls.py @@ -21,6 +21,5 @@ urlpatterns = [ path('', include('main.urls')), path('analytics/', include('analytics.urls')), path("robots.txt", TemplateView.as_view(template_name="robots.txt", content_type="text/plain")), - path("sitemap.xml", TemplateView.as_view(template_name="sitemap.xml", content_type="text/xml")), path('AD/SDGFOLKJASDNVASDFASDFSLAKDF/', admin.site.urls), ] diff --git a/TealCode/main/models.py b/TealCode/main/models.py index d76a65b..044827a 100644 --- a/TealCode/main/models.py +++ b/TealCode/main/models.py @@ -6,7 +6,7 @@ class Category(models.Model): title = models.CharField(max_length=100, unique=True) display_name = models.CharField(max_length= 100) date_created = models.DateTimeField(default=timezone.now) - + def __str__(self): return self.title diff --git a/TealCode/main/templates/sitemap.xml b/TealCode/main/templates/sitemap.xml index 6109335..190b53d 100644 --- a/TealCode/main/templates/sitemap.xml +++ b/TealCode/main/templates/sitemap.xml @@ -1,3 +1,4 @@ +{% load filter_blank %} @@ -15,8 +16,21 @@ 2021-11-19T20:00:06+00:00 0.70 - + + {% for c in categories %} + + https://code.tealfire.de/category/{{c.title|filter_blank }}/ + {{ c.date_created|date:"Y-m-d" }}T{{ c.date_created|date:"H:i:s" }}+00:00 + 0.80 + + {% endfor %} - + {% for t in topics %} + + https://code.tealfire.de/topic/{{t.category.title}}/{{t.title|filter_blank}}/ + {{ t.date_created|date:"Y-m-d" }}T{{ t.date_created|date:"H:i:s" }}+00:00 + 0.80 + + {% endfor %} \ No newline at end of file diff --git a/TealCode/main/templatetags/__init__.py b/TealCode/main/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/TealCode/main/templatetags/filter_blank.py b/TealCode/main/templatetags/filter_blank.py new file mode 100644 index 0000000..81887c3 --- /dev/null +++ b/TealCode/main/templatetags/filter_blank.py @@ -0,0 +1,7 @@ +from django import template + +register = template.Library() + +@register.filter +def filter_blank(value): + return value.replace(" ", "%20") \ No newline at end of file diff --git a/TealCode/main/urls.py b/TealCode/main/urls.py index a338f5c..bde56a9 100644 --- a/TealCode/main/urls.py +++ b/TealCode/main/urls.py @@ -7,4 +7,5 @@ urlpatterns = [ path('category//', views.category, name="main-category"), path('about/', views.about, name="main-about"), path('privacy/', views.privacy, name="main-privacy"), + path('sitemap.xml', views.sitemap, name="main-sitemap"), ] diff --git a/TealCode/main/views.py b/TealCode/main/views.py index 9fb86d0..3c687a7 100644 --- a/TealCode/main/views.py +++ b/TealCode/main/views.py @@ -2,6 +2,7 @@ from django.http.response import HttpResponse from django.shortcuts import render, redirect from .models import Category, Topic from analytics.models import View +from django.views.generic.base import TemplateView def index(req): view = View(ip=get_client_ip(req), home=True) @@ -58,6 +59,17 @@ def category(req, category): +def sitemap(req): + topics = Topic.objects.all() + categories = Category.objects.all() + #REPLACE ALL BLANKS WITH %20 + + + context = { + 'topics': topics, + 'categories': categories + } + return render(req, 'sitemap.xml', context, 'text/xml') def about(req): return render(req, "main/about.html")