Skip to content

Commit d13575b

Browse files
authored
fixed locale and mark up clean up (#259)
fixed an issue for mark up clean up and stores with multiple locale. fixed an issue with misnamed env variable
1 parent faa9f58 commit d13575b

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

actions/mark-up-clean-up/index.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

runners/run-mark-up-clean-up.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { main } = require('../actions/mark-up-clean-up/index');
1111
auth: process.env.AIO_runtime_auth,
1212
}
1313
},
14-
AEM_ADMIN_AUTH_TOKEN: process.env.AEM_ADMIN_API_AUTH_TOKEN,
14+
AEM_ADMIN_API_AUTH_TOKEN: process.env.AEM_ADMIN_API_AUTH_TOKEN,
1515
SITE: process.env.SITE,
1616
ORG: process.env.ORG,
1717
STORE_URL: process.env.STORE_URL,

0 commit comments

Comments
 (0)