Skip to content

Commit

Permalink
Merge pull request #766 from hlxsites/topics-pages-fix
Browse files Browse the repository at this point in the history
topic pages: fix urls & banner
  • Loading branch information
davenichols-DHLS authored Feb 7, 2024
2 parents 1e9cce5 + b41d2b8 commit e895646
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 13 additions & 4 deletions blocks/card-list/card-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ import {
ul, a, div, span, h2,
} from '../../scripts/dom-builder.js';

import { toClassName } from '../../scripts/lib-franklin.js';
import { getMetadata, toClassName } from '../../scripts/lib-franklin.js';
import createArticleCard from './articleCard.js';
import createApplicationCard from './applicationCard.js';
import createLibraryCard from './libraryCard.js';
import { makePublicUrl } from '../../scripts/scripts.js';

const getSelectionFromUrl = () => (window.location.pathname.indexOf('topics') > -1 ? toClassName(window.location.pathname.split('/').pop()) : '');
const getSelectionFromUrl = () => (window.location.pathname.indexOf('topics') > -1 ? toClassName(window.location.pathname.replace('.html', '').split('/').pop()) : '');
const getPageFromUrl = () => toClassName(new URLSearchParams(window.location.search).get('page')) || '';

const createTopicUrl = (keyword = '') => {
if (window.location.pathname.indexOf('topics') > -1) {
return window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1) + toClassName(keyword).toLowerCase();
}
return `${window.location.pathname}/topics/${toClassName(keyword).toLowerCase()}`;
return `${window.location.pathname.replace('.html', '')}/topics/${toClassName(keyword).toLowerCase()}`;
};

const patchBannerHeading = () => {
document.querySelector('body .banner h1').textContent = getMetadata('heading');
};

const createPaginationLink = (page, label, current = false) => {
Expand Down Expand Up @@ -119,6 +123,12 @@ const createFilters = (articles, activeTag) => {
}
tags.append(tagAnchor);
});

// patch banner heading with selected tag only on topics pages
if (getMetadata('heading') && window.location.pathname.indexOf('topics') > -1) {
patchBannerHeading();
}

return tags;
};

Expand Down Expand Up @@ -203,7 +213,6 @@ export default async function decorate(block) {
// render pagination and filters
const filterTags = createFilters(articles, activeTagFilter);
const paginationElements = createPagination(filteredArticles, page, limitPerPage);

block.append(filterTags, cardList, paginationElements);
}
}
4 changes: 4 additions & 0 deletions tools/importer/transformers/cardList.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const URLS_TO_BLOCK_MAP = [
url: '/news.html',
blockName: 'Card List (news)',
},
{
url: '/news/topics-template.html',
blockName: 'Card List (news, url-filtered)',
},
{
url: '/application.html',
blockName: 'Card List (application)',
Expand Down

0 comments on commit e895646

Please sign in to comment.