File tree 2 files changed +7
-3
lines changed
2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -57,8 +57,12 @@ public function getCanonical(): ?TagInterface
57
57
58
58
public function setPaginationLinks (Paginator $ paginator ): self
59
59
{
60
- $ this ->setCanonical ($ paginator ->currentPage () > 1 ? $ paginator ->url ($ paginator ->currentPage ()) : $ paginator ->url (1 ));
61
-
60
+ $ canonical = $ paginator ->url ($ paginator ->currentPage ());
61
+ if ($ paginator ->currentPage () == 1 ) {
62
+ $ canonical = preg_replace ('/[?&]page=\d+/ ' , '' , $ canonical );
63
+ $ canonical = rtrim ($ canonical , '? ' );
64
+ }
65
+ $ this ->setCanonical ($ canonical );
62
66
$ this ->setNextHref ($ paginator ->nextPageUrl ());
63
67
$ this ->setPrevHref ($ paginator ->previousPageUrl ());
64
68
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ function test_its_can_be_set_from_paginator()
21
21
// Mock methods to simulate paginator behavior for the first page.
22
22
$ paginator ->shouldReceive ('nextPageUrl ' )->once ()->andReturn ('http://site.com?page=2 ' );
23
23
$ paginator ->shouldReceive ('previousPageUrl ' )->once ()->andReturn (null ); // No previous page for the first page
24
- $ paginator ->shouldReceive ('currentPage ' )->once ()->andReturn (1 );
24
+ $ paginator ->shouldReceive ('currentPage ' )->twice ()->andReturn (1 );
25
25
$ paginator ->shouldReceive ('url ' )->with (1 )->andReturn ('http://site.com ' ); // Canonical URL without ?page=1
26
26
$ paginator ->shouldReceive ('url ' )->with (2 )->andReturn ('http://site.com?page=2 ' );
27
27
You can’t perform that action at this time.
0 commit comments