mirror of
https://github.com/DerTyp7/tealcode-django-python.git
synced 2025-10-29 12:32:09 +01:00
added dynamic sitemap
This commit is contained in:
@@ -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),
|
||||
]
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{% load filter_blank %}
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/0.9 http://www.sitemaps.org/schemas/0.9/sitemap.xsd">
|
||||
<!--Main Pages-->
|
||||
<url>
|
||||
@@ -15,8 +16,21 @@
|
||||
<lastmod>2021-11-19T20:00:06+00:00</lastmod>
|
||||
<priority>0.70</priority>
|
||||
</url>
|
||||
<!--Category Pages-->
|
||||
|
||||
<!--Category Pages-->
|
||||
{% for c in categories %}
|
||||
<url>
|
||||
<loc>https://code.tealfire.de/category/{{c.title|filter_blank }}/</loc>
|
||||
<lastmod>{{ c.date_created|date:"Y-m-d" }}T{{ c.date_created|date:"H:i:s" }}+00:00</lastmod>
|
||||
<priority>0.80</priority>
|
||||
</url>
|
||||
{% endfor %}
|
||||
<!--Topic Pages-->
|
||||
|
||||
{% for t in topics %}
|
||||
<url>
|
||||
<loc>https://code.tealfire.de/topic/{{t.category.title}}/{{t.title|filter_blank}}/</loc>
|
||||
<lastmod>{{ t.date_created|date:"Y-m-d" }}T{{ t.date_created|date:"H:i:s" }}+00:00</lastmod>
|
||||
<priority>0.80</priority>
|
||||
</url>
|
||||
{% endfor %}
|
||||
</urlset>
|
||||
0
TealCode/main/templatetags/__init__.py
Normal file
0
TealCode/main/templatetags/__init__.py
Normal file
7
TealCode/main/templatetags/filter_blank.py
Normal file
7
TealCode/main/templatetags/filter_blank.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@register.filter
|
||||
def filter_blank(value):
|
||||
return value.replace(" ", "%20")
|
||||
@@ -7,4 +7,5 @@ urlpatterns = [
|
||||
path('category/<str: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"),
|
||||
]
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user