@@ -29,11 +29,27 @@ const {
2929 * @param {* } checkedProducts
3030 * @returns
3131 */
32- function urlkeymatch ( publishedProduct , queriedProducts ) {
32+ function urlkeymatch ( publishedProduct , queriedProducts , context ) {
33+ const locale = context . locale ;
3334 let path = publishedProduct . path . split ( '/' ) ;
35+ const sku = publishedProduct . sku ;
36+
37+ //special case for products/default, IE the template page
38+ if ( ! sku ) {
39+ return true ;
40+ }
41+
42+ // if locale is provided and not in the path, return true (do not delete markup)
43+ if ( locale ?. trim ( ) && ! path . includes ( locale ) ) {
44+ return true ;
45+ }
46+
47+ const pdpUrlFormat = context . pathFormat . split ( '/' ) ;
48+ const urlKeyIndex = pdpUrlFormat . indexOf ( '{urlKey}' ) ;
3449
3550 const result = queriedProducts . some ( ( product ) => {
36- if ( path . includes ( product . urlKey ) ) {
51+ const urlKey = product . urlKey . split ( '/' ) . pop ( ) ;
52+ if ( path [ urlKeyIndex ] ?. toLowerCase ( ) === urlKey ?. toLowerCase ( ) ) {
3753 return true ;
3854 }
3955 } ) ;
@@ -53,7 +69,7 @@ async function markUpCleanUP(context, filesLib, logger, adminApi) {
5369 let queryResult = await requestSaaS ( GetUrlKeyQuery , 'getUrlKey' , { skus : publishedSkus } , context ) ;
5470 queryResult = queryResult . data . products ;
5571
56- const redundantpublishedProducts = publishedProducts . data . filter ( ( product ) => ! urlkeymatch ( product , queryResult ) )
72+ const redundantpublishedProducts = publishedProducts . data . filter ( ( product ) => ! urlkeymatch ( product , queryResult , context ) )
5773 context . counts . detected = redundantpublishedProducts . length ;
5874
5975 for ( const product of redundantpublishedProducts ) {
@@ -113,6 +129,7 @@ async function main(params) {
113129 contentUrl,
114130 logLevel,
115131 logIngestorEndpoint,
132+ adminAuthToken
116133 } = cfg ;
117134
118135 const counts = { detected : 0 , deleted : 0 , unpublished : 0 } ;
@@ -129,7 +146,7 @@ async function main(params) {
129146 logLevel,
130147 logIngestorEndpoint,
131148 }
132- const adminApi = new AdminAPI ( { org : params . ORG , site : params . SITE } , sharedContext , { authToken : params . AEM_ADMIN_AUTH_TOKEN } ) ;
149+ const adminApi = new AdminAPI ( { org : params . ORG , site : params . SITE } , sharedContext , { authToken : adminAuthToken } ) ;
133150
134151 let activationResult = { status : { } } ;
135152
@@ -143,7 +160,7 @@ async function main(params) {
143160 context . locale = locale ;
144161 tempLocale = locale ;
145162 }
146- activationResult . status [ tempLocale ] = await markUpCleanUP ( context , filesLib , logger ) ;
163+ activationResult . status [ tempLocale ] = await markUpCleanUP ( context , filesLib , logger , adminApi ) ;
147164 }
148165
149166 await observabilityClient . sendActivationResult ( activationResult ) ;
0 commit comments