@@ -124,11 +124,17 @@ public function canonicalUrl()
124124 {
125125 $ url = Str::trim ($ this ->explicitUrl ?? $ this ->data ->get ('canonical_url ' ));
126126
127- if (! app ( ' request ' )-> has ( ' page ' )) {
127+ if (! Str:: startsWith ( $ url , config ( ' app.url ' ) )) {
128128 return $ url ;
129129 }
130130
131- $ page = (int ) app ('request ' )->get ('page ' );
131+ if (! $ paginator = Blink::get ('tag-paginator ' )) {
132+ return $ url ;
133+ }
134+
135+ $ paginator ->setPath ($ url );
136+
137+ $ page = $ paginator ->currentPage ();
132138
133139 switch (true ) {
134140 case config ('statamic.seo-pro.pagination ' ) === false :
@@ -137,11 +143,7 @@ public function canonicalUrl()
137143 return $ url ;
138144 }
139145
140- if (Str::startsWith ($ url , config ('app.url ' ))) {
141- $ url .= '?page= ' .$ page ;
142- }
143-
144- return $ url ;
146+ return URL ::makeAbsolute ($ paginator ->url ($ page ));
145147 }
146148
147149 protected function prevUrl ()
@@ -150,21 +152,25 @@ protected function prevUrl()
150152 return null ;
151153 }
152154
155+ $ url = Str::trim ($ this ->data ->get ('canonical_url ' ));
156+
157+ if (! Str::startsWith ($ url , config ('app.url ' ))) {
158+ return $ url ;
159+ }
160+
153161 if (! $ paginator = Blink::get ('tag-paginator ' )) {
154162 return null ;
155163 }
156164
157- $ url = Str::trim ($ this ->data ->get ('canonical_url ' ));
158-
159- $ page = $ paginator ->currentPage ();
160-
161- if (config ('statamic.seo-pro.pagination.enabled_on_first_page ' ) === false && $ page === 2 ) {
165+ if (config ('statamic.seo-pro.pagination.enabled_on_first_page ' ) === false && $ paginator ->currentPage () === 2 ) {
162166 return $ url ;
163167 }
164168
165- return $ page > 1 && $ page <= $ paginator ->lastPage ()
166- ? $ url .'?page= ' .($ page - 1 )
167- : null ;
169+ if (! $ prevUrl = $ paginator ->previousPageUrl ()) {
170+ return null ;
171+ }
172+
173+ return URL ::makeAbsolute ($ prevUrl );
168174 }
169175
170176 protected function nextUrl ()
@@ -173,17 +179,21 @@ protected function nextUrl()
173179 return null ;
174180 }
175181
182+ $ url = Str::trim ($ this ->data ->get ('canonical_url ' ));
183+
184+ if (! Str::startsWith ($ url , config ('app.url ' ))) {
185+ return $ url ;
186+ }
187+
176188 if (! $ paginator = Blink::get ('tag-paginator ' )) {
177189 return null ;
178190 }
179191
180- $ url = Str:: trim ( $ this -> data -> get ( ' canonical_url ' ));
181-
182- $ page = $ paginator -> currentPage ();
192+ if (! $ nextUrl = $ paginator -> nextPageUrl ()) {
193+ return null ;
194+ }
183195
184- return $ page < $ paginator ->lastPage ()
185- ? $ url .'?page= ' .($ page + 1 )
186- : null ;
196+ return URL ::makeAbsolute ($ nextUrl );
187197 }
188198
189199 protected function parse ($ key , $ item )
0 commit comments