File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed
Expand file tree Collapse file tree 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
5757
5858 public function setPaginationLinks (Paginator $ paginator ): self
5959 {
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 );
6266 $ this ->setNextHref ($ paginator ->nextPageUrl ());
6367 $ this ->setPrevHref ($ paginator ->previousPageUrl ());
6468
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ function test_its_can_be_set_from_paginator()
2121 // Mock methods to simulate paginator behavior for the first page.
2222 $ paginator ->shouldReceive ('nextPageUrl ' )->once ()->andReturn ('http://site.com?page=2 ' );
2323 $ 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 );
2525 $ paginator ->shouldReceive ('url ' )->with (1 )->andReturn ('http://site.com ' ); // Canonical URL without ?page=1
2626 $ paginator ->shouldReceive ('url ' )->with (2 )->andReturn ('http://site.com?page=2 ' );
2727
You can’t perform that action at this time.
0 commit comments