From d8657df4d59fffd09dbeefb024e870a94c319c8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Delval?= Date: Thu, 23 Nov 2023 12:21:03 +0100 Subject: [PATCH] Linting (#46) --- tools/importer/import.js | 3 +- tools/importer/transformers/blogArticle.js | 27 ++++++++--------- tools/importer/transformers/blogBanner.js | 35 ++++++++-------------- tools/importer/transformers/index.js | 4 +-- tools/importer/transformers/metadata.js | 11 +++---- 5 files changed, 36 insertions(+), 44 deletions(-) diff --git a/tools/importer/import.js b/tools/importer/import.js index c2382d15..ad1d1107 100644 --- a/tools/importer/import.js +++ b/tools/importer/import.js @@ -59,7 +59,8 @@ export default { 'div.cmp-page__skiptomaincontent', 'div#mainContent', 'div.page-header', - // Remove navigation from the beginning of blog entries as well as readmore-type teasers and blurb about 24petwatch at the end + // Remove navigation from the beginning of blog entries as well as + // readmore-type teasers and blurb about 24petwatch at the end 'nav', 'div.imagelist', 'div.cmp-experiencefragment--blog-page-cta-component', diff --git a/tools/importer/transformers/blogArticle.js b/tools/importer/transformers/blogArticle.js index 7a9f88bf..91aac66a 100644 --- a/tools/importer/transformers/blogArticle.js +++ b/tools/importer/transformers/blogArticle.js @@ -1,19 +1,18 @@ function createBlogArticle(main, document) { - // Try to remove dts and dds that are not needed - const dts = document.querySelectorAll('dt'); - const dds = document.querySelectorAll('dd'); - if ( dts ) { - for( let i = 0; i < dts.length; i += 1) { - if( dts[i].textContent === 'Text') - { - const div = document.createElement('div'); - div.innerHTML = dds[i].innerHTML; - dts[i].closest('article').appendChild(div); - dts[i].remove(); - dds[i].remove(); - } - } + // Try to remove dts and dds that are not needed + const dts = document.querySelectorAll('dt'); + const dds = document.querySelectorAll('dd'); + if (dts) { + for (let i = 0; i < dts.length; i += 1) { + if (dts[i].textContent === 'Text') { + const div = document.createElement('div'); + div.innerHTML = dds[i].innerHTML; + dts[i].closest('article').appendChild(div); + dts[i].remove(); + dds[i].remove(); } + } + } } export default createBlogArticle; diff --git a/tools/importer/transformers/blogBanner.js b/tools/importer/transformers/blogBanner.js index 32bc6620..b61b1b9e 100644 --- a/tools/importer/transformers/blogBanner.js +++ b/tools/importer/transformers/blogBanner.js @@ -1,26 +1,17 @@ function blogBanner(main, document) { - - // Banner image is in mainContent element - const bannerImage = main.querySelector('#mainContent img'); - - if( bannerImage ){ - - // Create div to hold image - const div = document.createElement('div'); - const img = document.createElement('img'); - const imgSrc = bannerImage.getAttribute('src'); - img.setAttribute('src', imgSrc); - div.append(img); - - main.prepend(div); - - } - - // const p = document.createElement('p'); - // p.textContent = 'Hello world!'; - // main.append(p); - - + // Banner image is in mainContent element + const bannerImage = main.querySelector('#mainContent img'); + + if (bannerImage) { + // Create div to hold image + const div = document.createElement('div'); + const img = document.createElement('img'); + const imgSrc = bannerImage.getAttribute('src'); + img.setAttribute('src', imgSrc); + div.append(img); + + main.prepend(div); + } } export default blogBanner; diff --git a/tools/importer/transformers/index.js b/tools/importer/transformers/index.js index 89883ccf..fd19d391 100644 --- a/tools/importer/transformers/index.js +++ b/tools/importer/transformers/index.js @@ -4,7 +4,7 @@ import createFooter from './footer.js'; import createFullLayoutSection from './fullLayoutSection.js'; import createHomepage from './homepage.js'; import createHeader from './header.js'; -import createHero from './hero.js'; +// import createHero from './hero.js'; import createMetadata from './metadata.js'; import createBold from './bold.js'; import blogBanner from './blogBanner.js'; @@ -36,5 +36,5 @@ export const preTransformers = [ export const postTransformers = [ createMetadata, - cleanBlog + cleanBlog, ]; diff --git a/tools/importer/transformers/metadata.js b/tools/importer/transformers/metadata.js index fce65176..6d59aea4 100644 --- a/tools/importer/transformers/metadata.js +++ b/tools/importer/transformers/metadata.js @@ -27,18 +27,19 @@ const createMetadata = (main, document) => { // Get blog article tags const blogTags = document.querySelectorAll('div.cmp-contentfragment__element--tag > dd.cmp-contentfragment__element-value'); - if( blogTags ) { - for( let i = 0; i < blogTags.length; i += 1 ) { + if (blogTags) { + for (let i = 0; i < blogTags.length; i += 1) { meta.Tags = blogTags[i].innerHTML.replace('
', ' '); } } // Get blog related articles - // Assumes that related articles are rendered as the only ul on the page, if not, related articles are borked for the page + // Assumes that related articles are rendered as the only ul on the page, + // if not, related articles are borked for the page const relatedArticles = document.querySelector('ul.cmp-image-list__list'); - if ( relatedArticles ){ + if (relatedArticles) { const articleLinks = relatedArticles.querySelectorAll('a.cmp-image-list__item-title-link'); - for ( let i = 0; i < articleLinks.length; i += 0 ) { + for (let i = 0; i < articleLinks.length; i += 0) { meta.Related = articleLinks[i].getAttribute('href'); } }