Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWPW-161587 - Support typed query indexes #3205

Open
wants to merge 1 commit into
base: stage
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions libs/blocks/article-feed/article-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down
22 changes: 22 additions & 0 deletions test/blocks/article-feed/article-helpers.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
Loading