From 6b117956c09546acd5fa63c4a25510cf12933d6a Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 6 Oct 2023 21:19:01 +0100 Subject: [PATCH] Add page numbers to canonical tags --- website/common/models.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/website/common/models.py b/website/common/models.py index 2558990..6088649 100644 --- a/website/common/models.py +++ b/website/common/models.py @@ -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: