feat: add revlidation for loyalty page
This commit is contained in:
@@ -53,3 +53,26 @@ export async function getContentTypeByPathName(
|
||||
return PageTypeEnum.CurrentBlocksPage
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Function to remove empty objects from a fetched content type.
|
||||
* Used since Contentstack returns empty objects for all non
|
||||
* queried in modular blocks.
|
||||
*/
|
||||
export function removeEmptyObjects<T>(obj: T): T {
|
||||
const copy = obj as any
|
||||
|
||||
for (let key in copy) {
|
||||
if (typeof copy[key] === "object" && copy[key] !== null) {
|
||||
copy[key] = removeEmptyObjects(copy[key])
|
||||
if (Object.keys(copy[key]).length === 0 && !Array.isArray(copy[key])) {
|
||||
delete copy[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(copy)) {
|
||||
return copy.filter((item) => item != null).map(removeEmptyObjects) as T
|
||||
}
|
||||
|
||||
return copy as T
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user