Add page numbers to canonical tags

This commit is contained in:
Jake Howard 2023-10-06 21:19:01 +01:00
parent 28a54e9d56
commit 6b117956c0
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -1,5 +1,6 @@
from datetime import timedelta
from typing import Any, Optional, Type
from urllib.parse import urlencode
from django.contrib.humanize.templatetags.humanize import NaturalTimeFormatter
from django.contrib.syndication.views import Feed
@ -269,6 +270,12 @@ class BaseListingPage(RoutablePageMixin, BaseContentPage):
return HttpResponseBadRequest()
return super().index_route(request)
def get_meta_url(self) -> str:
query_data = self.serializer.validated_data.copy()
if query_data["page"] == 1:
del query_data["page"]
return super().get_meta_url() + urlencode(query_data)
@route(r"^feed/$")
@method_decorator(cache_page(60 * 30))
def feed(self, request: HttpRequest) -> HttpResponse: