From 519fc46af90b7211c85840ec184a3dfe6eb59f4d Mon Sep 17 00:00:00 2001 From: TeshuKatepalli Date: Tue, 5 Dec 2023 11:44:38 +0530 Subject: [PATCH 1/2] Updated the trim function to remove the edge case --- blocks/recent-posts/recent-posts.js | 4 ++-- scripts/scripts.js | 10 ++++++---- templates/Blog/Blog.js | 4 ++-- templates/News/News.js | 7 ++++--- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/blocks/recent-posts/recent-posts.js b/blocks/recent-posts/recent-posts.js index 774daeaf..af514fb2 100644 --- a/blocks/recent-posts/recent-posts.js +++ b/blocks/recent-posts/recent-posts.js @@ -56,7 +56,7 @@ export default async function decorate(block) { const title = blogTitles.children[0]; const blogsContainer = div({ class: 'col recent-posts' }); let sortedResults = []; - const filteredResults = postData.filter((item) => item.path.includes('/news/') && (topic ? JSON.parse(item.tags).filter((tag) => tag.toLowerCase() === topic.toLowerCase()).length > 0 : true)); + const filteredResults = postData.filter((item) => item.path.includes('/news/') && (topic ? JSON.parse(item.tags).filter((tag) => tag.toLowerCase().trim() === topic.toLowerCase().trim()).length > 0 : true)); if (filteredResults.length) { sortedResults = filteredResults.sort((ar1, ar2) => ar2.date - ar1.date); } @@ -70,7 +70,7 @@ export default async function decorate(block) { const title = newsTitles.children[1]; const blogsContainer = div({ class: 'col recent-posts' }); let sortedResults = []; - const filteredResults = postData.filter((item) => item.path.includes('/blog/') && (topic ? JSON.parse(item.tags).filter((tag) => tag.toLowerCase() === topic.toLowerCase()).length > 0 : true)); + const filteredResults = postData.filter((item) => item.path.includes('/blog/') && (topic ? JSON.parse(item.tags).filter((tag) => tag.toLowerCase().trim() === topic.toLowerCase().trim()).length > 0 : true)); if (filteredResults.length) { sortedResults = filteredResults.sort((ar1, ar2) => ar2.date - ar1.date); } diff --git a/scripts/scripts.js b/scripts/scripts.js index efac4cab..f31767a0 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -123,10 +123,12 @@ async function decorateNavigation(main) { if (getMetadata('navigation')) { const sidebarElement = main.querySelector('#sidebar'); const navigation = await getSubNavigation(window.location.pathname); - const block = await buildBlock('sidebar-navigation', navigation); - sidebarElement.prepend(block); - if (document.body.classList.contains('full-width')) { - document.body.classList.remove('full-width'); + if(navigation) { + const block = await buildBlock('sidebar-navigation', navigation); + sidebarElement.prepend(block); + if (document.body.classList.contains('full-width')) { + document.body.classList.remove('full-width'); + } } } } diff --git a/templates/Blog/Blog.js b/templates/Blog/Blog.js index 0125a148..6abdf7bb 100644 --- a/templates/Blog/Blog.js +++ b/templates/Blog/Blog.js @@ -65,10 +65,10 @@ function generateTopicBlock(results) { const tagCounts = {}; results.forEach((arc) => { JSON.parse(arc.tags).forEach((tag) => { - tagCounts[tag] = (tagCounts[tag] || 0) + 1; + tagCounts[tag.trim()] = (tagCounts[tag.trim()] || 0) + 1; }); }); - const tagCountArray = Object.entries(tagCounts).map(([tag, count]) => ({ title: tag, count })); + const tagCountArray = Object.entries(tagCounts).map(([tag, count]) => ({ title: tag.trim(), count })); return createSidebar('Topic', tagCountArray, 10); } diff --git a/templates/News/News.js b/templates/News/News.js index 5eb7d91d..861f9767 100644 --- a/templates/News/News.js +++ b/templates/News/News.js @@ -64,10 +64,10 @@ function generateTopicBlock(results) { const tagCounts = {}; results.forEach((arc) => { JSON.parse(arc.tags).forEach((tag) => { - tagCounts[tag] = (tagCounts[tag] || 0) + 1; + tagCounts[tag.trim()] = (tagCounts[tag.trim()] || 0) + 1; }); }); - const tagCountArray = Object.entries(tagCounts).map(([tag, count]) => ({ title: tag, count })); + const tagCountArray = Object.entries(tagCounts).map(([tag, count]) => ({ title: tag.trim(), count })); return createSidebar('Topic', tagCountArray, 10); } @@ -246,12 +246,13 @@ export default async function buildAutoBlocks(block) { } const data = await fetchNewsData(); + console.log(data); let filteredResults = data.filter((item) => { const path = item.path.toLowerCase(); const regex = /^\/about-us\/news\/.*$/; return regex.test(path); }); - + console.log(filteredResults); if (filteredResults.length) { filteredResults = filteredResults.sort((ar1, ar2) => ar2.date - ar1.date); } From f3a6253cc9f20a0fcb7dc8a983ac130cfb20d3aa Mon Sep 17 00:00:00 2001 From: TeshuKatepalli Date: Tue, 5 Dec 2023 11:51:57 +0530 Subject: [PATCH 2/2] removed lint issues --- scripts/scripts.js | 2 +- styles/Typo.css | 2 +- templates/Blog/Blog.js | 4 ++-- templates/News/News.js | 6 ++---- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index f31767a0..b27b3c5f 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -123,7 +123,7 @@ async function decorateNavigation(main) { if (getMetadata('navigation')) { const sidebarElement = main.querySelector('#sidebar'); const navigation = await getSubNavigation(window.location.pathname); - if(navigation) { + if (navigation) { const block = await buildBlock('sidebar-navigation', navigation); sidebarElement.prepend(block); if (document.body.classList.contains('full-width')) { diff --git a/styles/Typo.css b/styles/Typo.css index b6296c0d..cd5d3c02 100644 --- a/styles/Typo.css +++ b/styles/Typo.css @@ -415,7 +415,7 @@ hr { clear: both; display: block; height: 1px; - padding: 1em 0; + margin: 1em 0; } pre { diff --git a/templates/Blog/Blog.js b/templates/Blog/Blog.js index 6abdf7bb..11e8ab63 100644 --- a/templates/Blog/Blog.js +++ b/templates/Blog/Blog.js @@ -68,8 +68,8 @@ function generateTopicBlock(results) { tagCounts[tag.trim()] = (tagCounts[tag.trim()] || 0) + 1; }); }); - const tagCountArray = Object.entries(tagCounts).map(([tag, count]) => ({ title: tag.trim(), count })); - return createSidebar('Topic', tagCountArray, 10); + const tagCArray = Object.entries(tagCounts).map(([tag, count]) => ({ title: tag.trim(), count })); + return createSidebar('Topic', tagCArray, 10); } function generateResultsBlock(articles, currentPage, totalArticles) { diff --git a/templates/News/News.js b/templates/News/News.js index 861f9767..61f32a44 100644 --- a/templates/News/News.js +++ b/templates/News/News.js @@ -67,8 +67,8 @@ function generateTopicBlock(results) { tagCounts[tag.trim()] = (tagCounts[tag.trim()] || 0) + 1; }); }); - const tagCountArray = Object.entries(tagCounts).map(([tag, count]) => ({ title: tag.trim(), count })); - return createSidebar('Topic', tagCountArray, 10); + const tagCArray = Object.entries(tagCounts).map(([tag, count]) => ({ title: tag.trim(), count })); + return createSidebar('Topic', tagCArray, 10); } function generateResultsBlock(articles, currentPage, totalArticles) { @@ -246,13 +246,11 @@ export default async function buildAutoBlocks(block) { } const data = await fetchNewsData(); - console.log(data); let filteredResults = data.filter((item) => { const path = item.path.toLowerCase(); const regex = /^\/about-us\/news\/.*$/; return regex.test(path); }); - console.log(filteredResults); if (filteredResults.length) { filteredResults = filteredResults.sort((ar1, ar2) => ar2.date - ar1.date); }