55 removeSourceUrl ,
66 NotFoundError ,
77 getSiteBySourceUrl ,
8+ addQueryArgs ,
89} from '../../utils' ;
910import { PostEntity } from '../types' ;
1011import { postMatchers } from '../utils/matchers' ;
@@ -90,6 +91,8 @@ export class SinglePostFetchStrategy<
9091
9192 shouldCheckCurrentPathAgainstPostLink : boolean = true ;
9293
94+ optimizeYoastPayload : boolean = false ;
95+
9396 getDefaultEndpoint ( ) : string {
9497 return endpoints . posts ;
9598 }
@@ -108,6 +111,8 @@ export class SinglePostFetchStrategy<
108111
109112 this . path = nonUrlParams . fullPath ?? path ;
110113
114+ this . optimizeYoastPayload = ! ! config . integrations ?. yoastSEO ?. optimizeYoastPayload ;
115+
111116 // eslint-disable-next-line @typescript-eslint/no-unused-vars
112117 const { year, day, month, ...params } = parsePath ( postMatchers , path ) ;
113118
@@ -289,6 +294,7 @@ export class SinglePostFetchStrategy<
289294 */
290295 async fetcher ( url : string , params : P , options : Partial < FetchOptions > = { } ) {
291296 const { burstCache = false } = options ;
297+ let finalUrl = url ;
292298
293299 if ( params . authToken ) {
294300 options . previewToken = params . authToken ;
@@ -319,7 +325,13 @@ export class SinglePostFetchStrategy<
319325 }
320326
321327 try {
322- const result = await super . fetcher ( url , params , options ) ;
328+ if ( this . optimizeYoastPayload ) {
329+ finalUrl = addQueryArgs ( finalUrl , {
330+ optimizeYoastPayload : true ,
331+ } ) ;
332+ }
333+
334+ const result = await super . fetcher ( finalUrl , params , options ) ;
323335
324336 return result ;
325337 } catch ( e ) {
0 commit comments