From 1fe6079588e120b41139616c79f8643bbca60a38 Mon Sep 17 00:00:00 2001 From: Karl Pauls Date: Wed, 27 Sep 2023 14:15:11 +0200 Subject: [PATCH 1/3] chore: basic decorateIcons parallel test (#12) --- .../decorate/decorateIcons.parallel.test.html | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/decorate/decorateIcons.parallel.test.html diff --git a/test/decorate/decorateIcons.parallel.test.html b/test/decorate/decorateIcons.parallel.test.html new file mode 100644 index 0000000..3181c27 --- /dev/null +++ b/test/decorate/decorateIcons.parallel.test.html @@ -0,0 +1,38 @@ + + + +
+ +
+
+ +
+ + + From a7a511137178eecf2e56a942f0d022cef8b1314e Mon Sep 17 00:00:00 2001 From: Bruce Lefebvre Date: Wed, 27 Sep 2023 08:17:36 -0400 Subject: [PATCH 2/3] feat: enable getMetadata to query any document (#17) --- src/dom-utils.js | 7 ++++--- test/dom-utils/getMetadata.test.html | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/dom-utils.js b/src/dom-utils.js index 0a0088f..6b5e8d6 100644 --- a/src/dom-utils.js +++ b/src/dom-utils.js @@ -42,7 +42,7 @@ export async function loadScript(src, attrs) { const script = document.createElement('script'); script.src = src; if (attrs) { - // eslint-disable-next-line no-restricted-syntax, guard-for-in + // eslint-disable-next-line no-restricted-syntax, guard-for-in for (const attr in attrs) { script.setAttribute(attr, attrs[attr]); } @@ -59,11 +59,12 @@ export async function loadScript(src, attrs) { /** * Retrieves the content of metadata tags. * @param {string} name The metadata name (or property) + * @param {Document} doc Document object to query for metadata. Defaults to the window's document * @returns {string} The metadata value(s) */ -export function getMetadata(name) { +export function getMetadata(name, doc = document) { const attr = name && name.includes(':') ? 'property' : 'name'; - const meta = [...document.head.querySelectorAll(`meta[${attr}="${name}"]`)].map((m) => m.content).join(', '); + const meta = [...doc.head.querySelectorAll(`meta[${attr}="${name}"]`)].map((m) => m.content).join(', '); return meta || ''; } diff --git a/test/dom-utils/getMetadata.test.html b/test/dom-utils/getMetadata.test.html index eff664a..58f90b8 100644 --- a/test/dom-utils/getMetadata.test.html +++ b/test/dom-utils/getMetadata.test.html @@ -30,7 +30,31 @@ it('get article:tag', () => { expect(getMetadata('article:tag')).to.equal('tag 1, tag 2, tag 3'); }); + + // Test a custom document + const testDoc = document.implementation.createHTMLDocument(); + const titleMeta = testDoc.createElement('meta'); + titleMeta.setAttribute('property', 'og:title'); + titleMeta.setAttribute('content', 'Camping in Western Australia'); + testDoc.head.appendChild(titleMeta); + + const descriptionMeta = testDoc.createElement('meta'); + descriptionMeta.setAttribute('property', 'og:description'); + descriptionMeta.setAttribute('content', 'The Australian West coast is a camper’s heaven.'); + testDoc.head.appendChild(descriptionMeta); + + it('get og:title from custom document', () => { + expect(getMetadata('og:title', testDoc)).to.equal('Camping in Western Australia'); + }); + + it('get og:description from custom document', () => { + expect(getMetadata('og:description', testDoc)).to.equal('The Australian West coast is a camper’s heaven.'); + }); + + it('query metadata which does not exist from custom document', () => { + expect(getMetadata('og:not-set-metadata', testDoc)).to.equal(''); + }); }); - \ No newline at end of file + From cc08a79bcc296cd7a36db7da9f2dd43409fc810d Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 27 Sep 2023 12:18:30 +0000 Subject: [PATCH 3/3] chore(release): 1.3.0 [skip ci] # [1.3.0](https://github.com/adobe/aem-lib/compare/v1.2.1...v1.3.0) (2023-09-27) ### Features * enable getMetadata to query any document ([#17](https://github.com/adobe/aem-lib/issues/17)) ([a7a5111](https://github.com/adobe/aem-lib/commit/a7a511137178eecf2e56a942f0d022cef8b1314e)) --- CHANGELOG.md | 7 +++++++ dist/aem.js | 5 +++-- package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84c1284..8edd16f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [1.3.0](https://github.com/adobe/aem-lib/compare/v1.2.1...v1.3.0) (2023-09-27) + + +### Features + +* enable getMetadata to query any document ([#17](https://github.com/adobe/aem-lib/issues/17)) ([a7a5111](https://github.com/adobe/aem-lib/commit/a7a511137178eecf2e56a942f0d022cef8b1314e)) + ## [1.2.1](https://github.com/adobe/aem-lib/compare/v1.2.0...v1.2.1) (2023-09-27) diff --git a/dist/aem.js b/dist/aem.js index 0f2e15b..6b58e22 100644 --- a/dist/aem.js +++ b/dist/aem.js @@ -282,11 +282,12 @@ async function loadScript(src, attrs) { /** * Retrieves the content of metadata tags. * @param {string} name The metadata name (or property) + * @param {Document} doc Document object to query for metadata. Defaults to the window's document * @returns {string} The metadata value(s) */ -function getMetadata(name) { +function getMetadata(name, doc = document) { const attr = name && name.includes(':') ? 'property' : 'name'; - const meta = [...document.head.querySelectorAll(`meta[${attr}="${name}"]`)] + const meta = [...doc.head.querySelectorAll(`meta[${attr}="${name}"]`)] .map((m) => m.content) .join(', '); return meta || ''; diff --git a/package-lock.json b/package-lock.json index 3272a2e..14fd442 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@adobe/aem-lib", - "version": "1.2.1", + "version": "1.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@adobe/aem-lib", - "version": "1.2.1", + "version": "1.3.0", "license": "Apache License 2.0", "dependencies": { "@adobe/helix-rum-js": "1.4.1" diff --git a/package.json b/package.json index 1403921..15bdc21 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@adobe/aem-lib", "private": true, - "version": "1.2.1", + "version": "1.3.0", "description": "AEM Library", "type": "module", "scripts": {