diff --git a/blog/scripts/utils.js b/blog/scripts/utils.js index 5f0ab42..1ae323e 100644 --- a/blog/scripts/utils.js +++ b/blog/scripts/utils.js @@ -61,27 +61,6 @@ function buildBlock(blockName, content) { return (blockEl); } -function buildTagsBlock() { - const metadata = document.head.querySelectorAll('meta[property="article:tag"]'); - if (!metadata.length) return; - const tagsArray = [...metadata].map((el) => el.content); - const tagsBlock = buildBlock('tags', tagsArray.join(', ')); - const main = document.querySelector('main'); - const recBlock = main.querySelector('.recommended-articles'); - - if (!recBlock) { - main.lastElementChild.append(tagsBlock); - return; - } - - // Put tags block before recommended articles block - if (recBlock.parentElement.childElementCount === 1) { - recBlock.parentElement.previousElementSibling.append(tagsBlock); - } else { - recBlock.before(tagsBlock); - } -} - function getImageCaption(picture) { // Check if the parent element has a caption const parentEl = picture.parentNode; @@ -99,24 +78,18 @@ function getImageCaption(picture) { async function buildArticleHeader(el) { const miloLibs = getLibs(); const { getMetadata, getConfig } = await import(`${miloLibs}/utils/utils.js`); - const { loadTaxonomy, getLinkForTopic, getTaxonomyModule } = await import(`${miloLibs}/blocks/article-feed/article-helpers.js`); - if (!getTaxonomyModule()) { - await loadTaxonomy(); - } const div = document.createElement('div'); const h1 = el.querySelector('h1'); const picture = el.querySelector('picture'); const caption = getImageCaption(picture); const figure = document.createElement('div'); figure.append(picture, caption); - const category = getMetadata('category'); const author = getMetadata('author') || 'Adobe Communications Team'; const { locale } = getConfig(); const authorURL = getMetadata('author-url') || (author ? `${locale.contentRoot}/authors/${author.replace(/[^0-9a-z]/gi, '-').toLowerCase()}` : null); const publicationDate = getMetadata('publication-date'); - const categoryTag = getLinkForTopic(category); const articleHeaderBlockEl = buildBlock('article-header', [ - [`

${categoryTag}

`], + ['

'], [h1], [`

${authorURL ? `${author}` : author}

${publicationDate}

`], @@ -132,7 +105,6 @@ export async function buildAutoBlocks() { const mainEl = document.querySelector('main'); try { if (getMetadata('publication-date') && !mainEl.querySelector('.article-header')) { - buildTagsBlock(mainEl); await buildArticleHeader(mainEl); } } catch (error) { diff --git a/test/scripts/mocks/tagsHead.html b/test/scripts/mocks/tagsHead.html deleted file mode 100644 index f869b4e..0000000 --- a/test/scripts/mocks/tagsHead.html +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/test/scripts/mocks/tagsWithRecBody.html b/test/scripts/mocks/tagsWithRecBody.html deleted file mode 100644 index 8eaf8e2..0000000 --- a/test/scripts/mocks/tagsWithRecBody.html +++ /dev/null @@ -1,15 +0,0 @@ -
-
-

Customer experience — what it is, why it’s important, and how to deliver it

-

See what Adobe Experience Cloud can do for you. Request a demo today.

- -
-
diff --git a/test/scripts/mocks/tagsWithRecSectionBody.html b/test/scripts/mocks/tagsWithRecSectionBody.html deleted file mode 100644 index 1484d89..0000000 --- a/test/scripts/mocks/tagsWithRecSectionBody.html +++ /dev/null @@ -1,17 +0,0 @@ -
-
-

Customer experience — what it is, why it’s important, and how to deliver it

-

See what Adobe Experience Cloud can do for you. Request a demo today.

-
-
- -
-
diff --git a/test/scripts/utils.test.js b/test/scripts/utils.test.js index 26fd910..8b5e7de 100644 --- a/test/scripts/utils.test.js +++ b/test/scripts/utils.test.js @@ -56,8 +56,9 @@ describe('Auto Blocks', () => { document.head.innerHTML = metadata; }); - beforeEach(() => { + beforeEach(async () => { sinon.stub(window.lana, 'log'); + document.body.innerHTML = await readFile({ path: './mocks/body.html' }); }); afterEach(() => { @@ -70,27 +71,14 @@ describe('Auto Blocks', () => { expect(window.lana.log.called).to.be.true; }); - it('builds the tags block', async () => { - document.body.innerHTML = await readFile({ path: './mocks/body.html' }); - await buildAutoBlocks(); - expect(document.querySelector('.tags')).to.exist; - }); - - it('inserts the tags block before recommended articles if present', async () => { - document.body.innerHTML = await readFile({ path: './mocks/tagsWithRecBody.html' }); - await buildAutoBlocks(); - expect(document.querySelector('.tags + .recommended-articles')).to.exist; - }); - - it('inserts the tags block in section before recommended articles if present', async () => { - document.body.innerHTML = await readFile({ path: './mocks/tagsWithRecSectionBody.html' }); + it('builds the article header block', async () => { await buildAutoBlocks(); - expect(document.querySelector('.before-rec .tags')).to.exist; + expect(document.querySelector('.article-header')).to.exist; }); - it('builds the article header block', async () => { - document.body.innerHTML = await readFile({ path: './mocks/body.html' }); + it('does not show the category', async () => { await buildAutoBlocks(); - expect(document.querySelector('.article-header')).to.exist; + const category = document.head.querySelector('meta[name=category]').content; + expect(document.querySelector('.article-header').innerText.includes(category)).to.be.false; }); });