Skip to content

Commit

Permalink
Merge pull request #216 from hlxsites/bug/recent-news
Browse files Browse the repository at this point in the history
Bug/recent news
  • Loading branch information
pardeepgera23 authored Dec 5, 2023
2 parents 8edcba1 + f3a6253 commit 534f4d2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions blocks/recent-posts/recent-posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
10 changes: 6 additions & 4 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion styles/Typo.css
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ hr {
clear: both;
display: block;
height: 1px;
padding: 1em 0;
margin: 1em 0;
}

pre {
Expand Down
6 changes: 3 additions & 3 deletions templates/Blog/Blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ 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 }));
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) {
Expand Down
7 changes: 3 additions & 4 deletions templates/News/News.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ 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 }));
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) {
Expand Down Expand Up @@ -251,7 +251,6 @@ export default async function buildAutoBlocks(block) {
const regex = /^\/about-us\/news\/.*$/;
return regex.test(path);
});

if (filteredResults.length) {
filteredResults = filteredResults.sort((ar1, ar2) => ar2.date - ar1.date);
}
Expand Down

0 comments on commit 534f4d2

Please sign in to comment.