Skip to content

Commit

Permalink
Updated for wsaw hub page
Browse files Browse the repository at this point in the history
  • Loading branch information
rgravitvl committed Dec 11, 2024
1 parent ff49747 commit 4f849b3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
20 changes: 11 additions & 9 deletions blocks/card-list/card-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import {
ul, a, div, span,
} from '../../scripts/dom-builder.js';

let tag = getMetadata('template') === 'wsaw' ? 'solutions' : 'topics';

Check failure on line 6 in blocks/card-list/card-list.js

View workflow job for this annotation

GitHub Actions / build

'tag' is never reassigned. Use 'const' instead

Check failure on line 6 in blocks/card-list/card-list.js

View workflow job for this annotation

GitHub Actions / build

'getMetadata' was used before it was defined
import { getMetadata, toClassName } from '../../scripts/lib-franklin.js';

Check failure on line 7 in blocks/card-list/card-list.js

View workflow job for this annotation

GitHub Actions / build

Import in body of module; reorder to top
import createArticleCard from './articleCard.js';

Check failure on line 8 in blocks/card-list/card-list.js

View workflow job for this annotation

GitHub Actions / build

Import in body of module; reorder to top
import createLibraryCard from './libraryCard.js';

Check failure on line 9 in blocks/card-list/card-list.js

View workflow job for this annotation

GitHub Actions / build

Import in body of module; reorder to top
import createApplicationCard from './applicationCard.js';

Check failure on line 10 in blocks/card-list/card-list.js

View workflow job for this annotation

GitHub Actions / build

Import in body of module; reorder to top
import { makePublicUrl } from '../../scripts/scripts.js';

Check failure on line 11 in blocks/card-list/card-list.js

View workflow job for this annotation

GitHub Actions / build

Import in body of module; reorder to top
import { buildItemListSchema } from '../../scripts/schema.js';

Check failure on line 12 in blocks/card-list/card-list.js

View workflow job for this annotation

GitHub Actions / build

Import in body of module; reorder to top

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

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

const patchBannerHeading = () => {
Expand Down Expand Up @@ -83,7 +84,7 @@ const createPagination = (entries, page, limit) => {

export function createFilters(articles, viewAll = false) {
// collect tag filters
const allKeywords = articles.map((item) => item.topics.replace(/,\s*/g, ',').split(','));
const allKeywords = articles.map((item) => item[tag].replace(/,\s*/g, ',').split(','));
const keywords = new Set([].concat(...allKeywords));
keywords.delete('');
keywords.delete('Blog'); // filter out generic blog tag
Expand All @@ -92,8 +93,8 @@ export function createFilters(articles, viewAll = false) {
// render tag cloud
const newUrl = new URL(window.location);
newUrl.searchParams.delete('page');
if (window.location.pathname.indexOf('topics') > -1) {
newUrl.pathname = window.location.pathname.substring(0, window.location.pathname.indexOf('/topics/'));
if (window.location.pathname.indexOf(tag) > -1) {
newUrl.pathname = window.location.pathname.substring(0, window.location.pathname.indexOf(`/${tag}/`));
}
const tags = viewAll ? div(
{ class: 'flex flex-wrap gap-2 gap-y-0 mb-4' },
Expand Down Expand Up @@ -138,7 +139,7 @@ export function createFilters(articles, viewAll = false) {
});

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

Expand All @@ -150,8 +151,9 @@ export default async function decorate(block) {
if (articleType) block.classList.remove(articleType);
block.textContent = '';

const indexType = getMetadata('template') === 'wsaw' ? 'wsaw' : 'article';
// fetch and sort all articles
const articles = await ffetch('/us/en/article-index.json')
const articles = await ffetch(`/us/en/${indexType}-index.json`)
.chunks(500)
.filter(({ type }) => type.toLowerCase() === articleType)
.filter((article) => !article.path.includes('/topics-template'))
Expand All @@ -160,7 +162,7 @@ export default async function decorate(block) {
const activeTagFilter = block.classList.contains('url-filtered') ? getSelectionFromUrl() : '';
if (activeTagFilter) {
filteredArticles = articles.filter(
(item) => toClassName(item.topics).toLowerCase().indexOf(activeTagFilter) > -1,
(item) => toClassName(item[tag]).toLowerCase().indexOf(activeTagFilter) > -1,
);
}
buildItemListSchema(filteredArticles, 'resources');
Expand Down
3 changes: 2 additions & 1 deletion fstab.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ folders:
/us/en/products/bundles/: /us/en/products/product-coveo
/us/en/blog/topics/: /us/en/blog/topics-template
/us/en/news/topics/: /us/en/news/topics-template
/us/en/library/topics/: /us/en/library/topics-template
/us/en/library/topics/: /us/en/library/topics-template
/us/en/we-see-a-way/solutions/: /us/en/we-see-a-way
35 changes: 35 additions & 0 deletions helix-query.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ indices:
topics:
select: head > meta[name="topics"]
value: attribute(el, "content")
solutions:
select: head > meta[name="solutions"]
value: attribute(el, "content")
readingTime:
select: head > meta[name="readingtime"]
value: attribute(el, "content")
Expand Down Expand Up @@ -79,3 +82,35 @@ indices:
solution:
select: head > meta[name="solution"]
value: attribute(el, "content")
wsaw:
include:
- /us/en/we-see-a-way/**
target: /us/en/wsaw-index.json
properties:
lastModified:
select: none
value: parseTimestamp(headers["last-modified"], "ddd, DD MMM YYYY hh:mm:ss GMT")
title:
select: main h1
value: textContent(el)
navTitle:
select: head > meta[name="navtitle"]
value: attribute(el, "content")
description:
select: head > meta[name="description"]
value: attribute(el, "content")
image:
select: head > meta[property="og:image"]
value: match(attribute(el, "content"), "^(https?:\/\/.*?(danaher.com))+(.*)|^(.*)")
solutions:
select: head > meta[name="solutions"]
value: attribute(el, "content")
publishDate:
select: head > meta[name="publishdate"]
value: parseTimestamp(attribute(el, "content"), "ddd, DD MMM YYYY hh:mm:ss GMT")
type:
select: head > meta[name="template"]
value: attribute(el, "content")
brand:
select: head > meta[name="brand"]
value: attribute(el, "content")
4 changes: 4 additions & 0 deletions tools/importer/transformers/cardList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* global WebImporter */
const URLS_TO_BLOCK_MAP = [
{
url: '/we-see-a-way.html',
blockName: 'Card List (wsaw)',
},
{
url: '/blog.html',
blockName: 'Card List (blog)',
Expand Down

0 comments on commit 4f849b3

Please sign in to comment.