diff --git a/libs/blocks/article-feed/article-helpers.js b/libs/blocks/article-feed/article-helpers.js index e9cfe1d59b..fcb2f3f81d 100644 --- a/libs/blocks/article-feed/article-helpers.js +++ b/libs/blocks/article-feed/article-helpers.js @@ -81,12 +81,18 @@ function loadArticleTaxonomy(article) { // for now, we can only compute the category const { tags, path } = clonedArticle; + let topics; + if (tags) { - const topics = tags - .replace(/[["\]]/gm, '') - .split(',') - .map((t) => t.trim()) - .filter((t) => t && t !== ''); + if (Array.isArray(tags)) { + topics = tags.map((t) => t.trim()).filter((t) => t && t !== ''); + } else { + topics = tags + .replace(/[["\]]/gm, '') + .split(',') + .map((t) => t.trim()) + .filter((t) => t && t !== ''); + } const articleTax = computeTaxonomyFromTopics(topics, path); @@ -175,7 +181,7 @@ export async function loadTaxonomy() { */ export function formatCardLocaleDate(date) { if (!date) return ''; - const jsDate = !date.includes('-') ? calculateExcelDate(date) : date.replace(/-/g, '/'); + const jsDate = !date.toString().includes('-') ? calculateExcelDate(date) : date.replace(/-/g, '/'); const dateLocale = getConfig().locale?.ietf; diff --git a/test/blocks/article-feed/article-helpers.test.js b/test/blocks/article-feed/article-helpers.test.js new file mode 100644 index 0000000000..8508d53e68 --- /dev/null +++ b/test/blocks/article-feed/article-helpers.test.js @@ -0,0 +1,22 @@ +import { expect } from '@esm-bundle/chai'; +import { getArticleTaxonomy } from '../../../libs/blocks/article-feed/article-helpers.js'; + +describe('adobetv autoblock', () => { + it('Creates article taxonomy from strings', async () => { + const article = { + tags: 'hello, world', + path: '/no/types/for/you', + }; + const taxonomy = getArticleTaxonomy(article); + expect(taxonomy.topics[0]).to.equal('hello'); + }); + + it('Creates article taxonomy from an array of strings', async () => { + const article = { + tags: ['goodnight', 'moon'], + path: '/no/types/for/you', + }; + const taxonomy = getArticleTaxonomy(article); + expect(taxonomy.topics[0]).to.equal('goodnight'); + }); +});