diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..848c2d4 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,7 @@ +{ + "extends": ["airbnb-base", "prettier"], + "plugins": ["prettier"], + "rules": { + "prettier/prettier": ["error"] + } +} \ No newline at end of file diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..17b1d52 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,5 @@ +{ + "semi": false, + "singleQuote": true, + "trailingComma": "es5" +} \ No newline at end of file diff --git a/best-cigars-guide/blocks/article-list/article-list.js b/best-cigars-guide/blocks/article-list/article-list.js index 22cc3b8..b2c171a 100644 --- a/best-cigars-guide/blocks/article-list/article-list.js +++ b/best-cigars-guide/blocks/article-list/article-list.js @@ -74,8 +74,7 @@ export default function decorate(block) { anchor.appendChild(picture); } } else if ( - !div.querySelector('picture') && - li.querySelector('.article-list-card-body') === null + !div.querySelector('picture') && li.querySelector('.article-list-card-body') === null ) { // second div is for the article body div.className = 'article-list-card-body'; @@ -85,7 +84,7 @@ export default function decorate(block) { // Set class names for the first and second paragraphs within the article-list-card-body const paragraphs = div.previousSibling.querySelectorAll('p'); if (paragraphs.length > 0) { - //change article title to an h3 + // change article title to an h3 const h3 = document.createElement('h3'); h3.className = 'article-title'; h3.textContent = paragraphs[0].textContent; @@ -120,13 +119,9 @@ export default function decorate(block) { }); // optimize images - ul.querySelectorAll('img').forEach((img) => - img - .closest('picture') - .replaceWith( - createOptimizedPicture(img.src, img.alt, false, [{ width: '750' }]) - ) - ); + ul.querySelectorAll('img').forEach((img) => img.closest('picture').replaceWith( + createOptimizedPicture(img.src, img.alt, false, [{ width: '750' }]), + )); // Remove any empty div tags [...ul.querySelectorAll('div')].forEach((div) => { diff --git a/package-lock.json b/package-lock.json index f3ce874..a8c5eb5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,9 +12,10 @@ "@babel/core": "7.24.4", "@babel/eslint-parser": "7.24.1", "chai": "5.1.0", - "eslint": "8.57.0", - "eslint-config-airbnb-base": "15.0.0", - "eslint-plugin-import": "2.29.1", + "eslint": "^8.57.0", + "eslint-config-airbnb-base": "^15.0.0", + "eslint-plugin-import": "^2.29.1", + "prettier": "^3.2.5", "stylelint": "16.3.1", "stylelint-config-standard": "36.0.0" } @@ -3205,6 +3206,21 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", + "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", @@ -6432,6 +6448,12 @@ "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true }, + "prettier": { + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", + "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", + "dev": true + }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", diff --git a/package.json b/package.json index 8bd4b96..c1041e8 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,10 @@ "@babel/core": "7.24.4", "@babel/eslint-parser": "7.24.1", "chai": "5.1.0", - "eslint": "8.57.0", - "eslint-config-airbnb-base": "15.0.0", - "eslint-plugin-import": "2.29.1", + "eslint": "^8.57.0", + "eslint-config-airbnb-base": "^15.0.0", + "eslint-plugin-import": "^2.29.1", + "prettier": "^3.2.5", "stylelint": "16.3.1", "stylelint-config-standard": "36.0.0" } diff --git a/tools/importer/import-category.js b/tools/importer/import-category.js deleted file mode 100644 index ecc4b38..0000000 --- a/tools/importer/import-category.js +++ /dev/null @@ -1,90 +0,0 @@ -const formatUrl = (originalUrl) => { - // Create a URL object based on the original URL - var url = new URL(originalUrl); - - // Set the new domain (including protocol) - url.hostname = 'www.famous-smoke.com'; - url.protocol = 'https:'; - url.port = ''; - - return url; -} - -const createMetadataBlock = (main, document) => { - const meta = {}; - - // find the element - const title = document.querySelector('title'); - if (title) { - meta.Title = title.innerHTML.replace(/[\n\t]/gm, ``); - } - - // find the <meta property="og:description"> element - const desc = document.querySelector('[property="og:description"]'); - if (desc) { - meta.Description = desc.content; - } - - // set the <meta property="og:image"> element - meta.image = 'https://www.famous-smoke.com/best-cigars-guide/icons/best-cigars-guide.png'; - - // helper to create the metadata block - const block = WebImporter.Blocks.getMetadataBlock(document, meta); - - // append the block to the main element - main.append(block); - - // returning the meta object might be usefull to other rules - return meta; -}; - -const createArticleListBlock = (main, document) => { - var categories = [['Article-list']]; - let categoriesList = document.querySelector('.categories-list'); - let divElements = categoriesList.querySelectorAll('div'); - - divElements.forEach(function (element) { - var title = element.querySelector('h3').textContent.trim(); - var description = element.querySelector('p').textContent.trim(); - var image = element.querySelector('img'); - - var linkElement = element.querySelector('a.button'); - linkElement.class = 'button'; - var link = linkElement ? linkElement.href : ''; - - var card = [ - [image], - [title], - [description], - [formatUrl(link)] - ]; - - categories.push(card); - }); - - const articleList = WebImporter.DOMUtils.createTable(categories, document); - - main.append(articleList); - - // remove .categories-list from main because we just added it manually - WebImporter.DOMUtils.remove(main, ['.categories-list']); - - return articleList; -}; - -const removeSectionsNotForImport = (main, document) => { - // remove any section from main not needed for import - WebImporter.DOMUtils.remove(main, ['.category-dropdown','.breadcrumb']); -}; - -export default { - transformDOM: ({ document }) => { - const main = document.querySelector('main'); - - createMetadataBlock(main, document); - createArticleListBlock(main, document); - removeSectionsNotForImport(main, document); - - return main; - }, -};