From 6dbc19560e6bf664f0d69481ccb6417ef73f04e5 Mon Sep 17 00:00:00 2001 From: Kiran Murugulla Date: Wed, 18 Mar 2026 19:34:29 -0400 Subject: [PATCH 1/3] fix: /whatson homepage underfill by filtering out invalid image rows and handling blogsbypaths edge case --- aemedge/blocks/category/category.js | 3 +++ aemedge/scripts/utils.js | 33 +++++++++++++++++++---------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/aemedge/blocks/category/category.js b/aemedge/blocks/category/category.js index e6274e38..a75e9920 100644 --- a/aemedge/blocks/category/category.js +++ b/aemedge/blocks/category/category.js @@ -118,10 +118,13 @@ export default async function decorate(block) { if (numberofblogs > 0) { blogs = await getBlogs(categories.map((cat) => pathToTag(cat)), numberofblogs, limit); mergedBlogs = [...blogs, ...blogsbypaths]; + } else { + mergedBlogs = blogsbypaths; } } else { mergedBlogs = await getBlogs(categories.map((cat) => pathToTag(cat)), numberofblogs, limit); } + mergedBlogs.forEach(async (blog, i) => { if (blog.image === '') return; let card; diff --git a/aemedge/scripts/utils.js b/aemedge/scripts/utils.js index 23d4c7d8..fc246253 100644 --- a/aemedge/scripts/utils.js +++ b/aemedge/scripts/utils.js @@ -200,7 +200,8 @@ export async function fetchData(path) { const json = await response.json(); return json.data.map((row) => { - if (row.image.startsWith('/default-meta-image.png')) { + const img = row.image; + if (typeof img === 'string' && img.startsWith('/default-meta-image.png')) { row.image = `/${window.hlx.codeBasePath}${row.image}`; } return row; @@ -223,6 +224,19 @@ function compareArrays(arr, arr2) { return arr.every((i) => arr2.includes(i)); } +/** + * Returns true if the entry has a renderable blog image. + * Excludes missing, empty, '0', and default-meta-image to avoid underfill or runtime errors. + * @param {Object} entry - Query-index row + * @returns {boolean} + */ +function hasValidBlogImage(entry) { + return typeof entry.image === 'string' + && entry.image !== '' + && entry.image !== '0' + && !entry.image.includes('default-meta-image.png'); +} + /** * Retrieves blogs matching specific tags * @param {Array} categories - An array of categories to filter by @@ -231,21 +245,17 @@ function compareArrays(arr, arr2) { * @returns {Promise} - A promise resolving to the filtered blogs array */ export async function getBlogs(categories, num, limit = '') { + // Note: query-index.json does not support ?limit= param; always returns full index if (!window.allBlogs) { - window.allBlogs = await fetchData(`/whatson/query-index.json${limit ? `?limit=${limit}` : ''}`); + window.allBlogs = await fetchData('/whatson/query-index.json'); } const isBlogsHome = (window.location.pathname === '/whatson' || window.location.pathname === '/whatson/'); const blogArticles = isBlogsHome ? window.allBlogs.filter( - (e) => (e.template === 'blog-article' - && e.image !== '' - && !e.image.startsWith('//aemedge/default-meta-image.png') - && (e.hideFromHome !== 'yes')), + (e) => (e.template === 'blog-article' && hasValidBlogImage(e) && (e.hideFromHome !== 'yes')), ) : window.allBlogs.filter( - (e) => (e.template === 'blog-article' - && e.image !== '' - && !e.image.startsWith('//aemedge/default-meta-image.png')), + (e) => (e.template === 'blog-article' && hasValidBlogImage(e)), ); if ((categories && categories.length > 0)) { @@ -266,11 +276,12 @@ export async function getBlogs(categories, num, limit = '') { } export async function getBlogsByPaths(paths, limit = '') { + // Note: query-index.json does not honor ?limit= query param if (!window.allBlogs) { - window.allBlogs = await fetchData(`/whatson/query-index.json${limit ? `?limit=${limit}` : ''}`); + window.allBlogs = await fetchData('/whatson/query-index.json'); } const blogArticles = window.allBlogs.filter( - (e) => (e.template !== 'blog-category' && e.image !== '' && !e.image.startsWith('//aemedge/default-meta-image.png')), + (e) => (e.template !== 'blog-category' && hasValidBlogImage(e)), ); let filterArticles = []; if (paths && paths.length > 0) { From 7253f0fe4a615a9e595306d2e7cf05054c77594d Mon Sep 17 00:00:00 2001 From: Kiran Murugulla Date: Wed, 18 Mar 2026 19:36:56 -0400 Subject: [PATCH 2/3] fix : lint --- aemedge/scripts/utils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aemedge/scripts/utils.js b/aemedge/scripts/utils.js index fc246253..b7b44574 100644 --- a/aemedge/scripts/utils.js +++ b/aemedge/scripts/utils.js @@ -241,10 +241,10 @@ function hasValidBlogImage(entry) { * Retrieves blogs matching specific tags * @param {Array} categories - An array of categories to filter by * @param {number} num - The number of blogs to retrieve - * @param {string} limit - The limit of blogs to retrieve from the query-index + * @param {string} _limit - Unused; query-index does not support limit param * @returns {Promise} - A promise resolving to the filtered blogs array */ -export async function getBlogs(categories, num, limit = '') { +export async function getBlogs(categories, num, _limit = '') { // Note: query-index.json does not support ?limit= param; always returns full index if (!window.allBlogs) { window.allBlogs = await fetchData('/whatson/query-index.json'); @@ -275,7 +275,7 @@ export async function getBlogs(categories, num, limit = '') { return blogArticles; } -export async function getBlogsByPaths(paths, limit = '') { +export async function getBlogsByPaths(paths, _limit = '') { // Note: query-index.json does not honor ?limit= query param if (!window.allBlogs) { window.allBlogs = await fetchData('/whatson/query-index.json'); From e152610961a05258af945c418e24388403827411 Mon Sep 17 00:00:00 2001 From: Kiran Murugulla Date: Wed, 18 Mar 2026 19:47:54 -0400 Subject: [PATCH 3/3] fix: removing the limit to make sure it loads all 7 on home page --- aemedge/blocks/category/category.js | 13 +++---------- aemedge/scripts/utils.js | 15 +++++++-------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/aemedge/blocks/category/category.js b/aemedge/blocks/category/category.js index a75e9920..3fdb6a88 100644 --- a/aemedge/blocks/category/category.js +++ b/aemedge/blocks/category/category.js @@ -9,8 +9,6 @@ import { pathToTag, } from '../../scripts/utils.js'; -const LIMIT_100 = '100'; - // Create cardLarge images for 2 breakpoints export async function addCardImageLarge(row, style, eagerImage = true) { const cardImageDiv = createTag('div', { class: 'card-image' }); @@ -103,26 +101,21 @@ export default async function decorate(block) { lastSegmentOfURL = currentCategory; } - let limit = ''; - // check if whatson homepage and add limit what we pull from query index for better performance - if (window.location.pathname === '/whatson' || window.location.pathname === '/whatson/') { - limit = LIMIT_100; - } let blogsbypaths; - if (paths.length >= 1) blogsbypaths = await getBlogsByPaths(paths, limit); + if (paths.length >= 1) blogsbypaths = await getBlogsByPaths(paths); let blogs; let mergedBlogs; if (blogsbypaths && (blogsbypaths.length > 0 && blogsbypaths.length < 8)) { numberofblogs -= blogsbypaths.length; // Get blogs if (numberofblogs > 0) { - blogs = await getBlogs(categories.map((cat) => pathToTag(cat)), numberofblogs, limit); + blogs = await getBlogs(categories.map((cat) => pathToTag(cat)), numberofblogs); mergedBlogs = [...blogs, ...blogsbypaths]; } else { mergedBlogs = blogsbypaths; } } else { - mergedBlogs = await getBlogs(categories.map((cat) => pathToTag(cat)), numberofblogs, limit); + mergedBlogs = await getBlogs(categories.map((cat) => pathToTag(cat)), numberofblogs); } mergedBlogs.forEach(async (blog, i) => { diff --git a/aemedge/scripts/utils.js b/aemedge/scripts/utils.js index b7b44574..371a5b1c 100644 --- a/aemedge/scripts/utils.js +++ b/aemedge/scripts/utils.js @@ -237,19 +237,19 @@ function hasValidBlogImage(entry) { && !entry.image.includes('default-meta-image.png'); } +const QUERY_INDEX_PATH = '/whatson/query-index.json'; + /** * Retrieves blogs matching specific tags * @param {Array} categories - An array of categories to filter by * @param {number} num - The number of blogs to retrieve - * @param {string} _limit - Unused; query-index does not support limit param * @returns {Promise} - A promise resolving to the filtered blogs array */ -export async function getBlogs(categories, num, _limit = '') { - // Note: query-index.json does not support ?limit= param; always returns full index +export async function getBlogs(categories, num) { + const isBlogsHome = (window.location.pathname === '/whatson' || window.location.pathname === '/whatson/'); if (!window.allBlogs) { - window.allBlogs = await fetchData('/whatson/query-index.json'); + window.allBlogs = await fetchData(QUERY_INDEX_PATH); } - const isBlogsHome = (window.location.pathname === '/whatson' || window.location.pathname === '/whatson/'); const blogArticles = isBlogsHome ? window.allBlogs.filter( (e) => (e.template === 'blog-article' && hasValidBlogImage(e) && (e.hideFromHome !== 'yes')), @@ -275,10 +275,9 @@ export async function getBlogs(categories, num, _limit = '') { return blogArticles; } -export async function getBlogsByPaths(paths, _limit = '') { - // Note: query-index.json does not honor ?limit= query param +export async function getBlogsByPaths(paths) { if (!window.allBlogs) { - window.allBlogs = await fetchData('/whatson/query-index.json'); + window.allBlogs = await fetchData(QUERY_INDEX_PATH); } const blogArticles = window.allBlogs.filter( (e) => (e.template !== 'blog-category' && hasValidBlogImage(e)),