@tryghost/kg-parser-plugins
Advanced tools
Comparing version 0.8.1 to 0.9.0
@@ -76,23 +76,46 @@ 'use strict'; | ||
let anchor = node.querySelector('.markup--mixtapeEmbed-anchor').href; | ||
let title = node.querySelector('.markup--mixtapeEmbed-strong'); | ||
let desc = node.querySelector('.markup--mixtapeEmbed-em'); | ||
let img = node.querySelector('.mixtapeImage'); | ||
let imgSrc = false; | ||
// Grab the relevant elements - Anchor wraps most of the data | ||
let anchorElement = node.querySelector('.markup--mixtapeEmbed-anchor'); | ||
let titleElement = anchorElement.querySelector('.markup--mixtapeEmbed-strong'); | ||
let descElement = anchorElement.querySelector('.markup--mixtapeEmbed-em'); | ||
// Image is a top level field inside it's own a tag | ||
let imgElement = node.querySelector('.mixtapeImage'); | ||
// Image is optional, | ||
// The element usually still exists with an additional has.mixtapeImage--empty class and has no background image | ||
if (img && img.style['background-image']) { | ||
imgSrc = img.style['background-image'].match(/url\(([^)]*?)\)/)[1]; | ||
// Grab individual values from the elements | ||
let url = anchorElement.href; | ||
let title = ''; | ||
let description = ''; | ||
if (titleElement && titleElement.innerHTML) { | ||
title = cleanBasicHtml(titleElement.innerHTML, options); | ||
// Cleanup anchor so we can see what's left now that we've processed title | ||
anchorElement.removeChild(titleElement); | ||
} | ||
// Format our preferred structure. | ||
if (descElement && descElement.innerHTML) { | ||
description = cleanBasicHtml(descElement.innerHTML, options); | ||
// Cleanup anchor so we can see what's left now that we've processed description | ||
anchorElement.removeChild(descElement); | ||
} | ||
// // Format our preferred structure. | ||
let metadata = { | ||
url: anchor, | ||
title: title, | ||
description: desc, | ||
thumbnail: imgSrc | ||
url, | ||
title, | ||
description | ||
}; | ||
let payload = {metadata, url: metadata.url, type: 'bookmark'}; | ||
// Publisher is the remaining text in the anchor, once title & desc are removed | ||
let publisher = cleanBasicHtml(anchorElement.innerHTML, options); | ||
if (publisher) { | ||
metadata.publisher = publisher; | ||
} | ||
// Image is optional, | ||
// The element usually still exists with an additional has.mixtapeImage--empty class and has no background image | ||
if (imgElement && imgElement.style['background-image']) { | ||
metadata.thumbnail = imgElement.style['background-image'].match(/url\(([^)]*?)\)/)[1]; | ||
} | ||
let payload = {url, metadata}; | ||
let cardSection = builder.createCardSection('bookmark', payload); | ||
@@ -99,0 +122,0 @@ addSection(cardSection); |
@@ -70,26 +70,49 @@ import cleanBasicHtml from '@tryghost/kg-clean-basic-html'; | ||
return; | ||
} // Grab the relevant elements - Anchor wraps most of the data | ||
let anchorElement = node.querySelector('.markup--mixtapeEmbed-anchor'); | ||
let titleElement = anchorElement.querySelector('.markup--mixtapeEmbed-strong'); | ||
let descElement = anchorElement.querySelector('.markup--mixtapeEmbed-em'); // Image is a top level field inside it's own a tag | ||
let imgElement = node.querySelector('.mixtapeImage'); // Grab individual values from the elements | ||
let url = anchorElement.href; | ||
let title = ''; | ||
let description = ''; | ||
if (titleElement && titleElement.innerHTML) { | ||
title = cleanBasicHtml(titleElement.innerHTML, options); // Cleanup anchor so we can see what's left now that we've processed title | ||
anchorElement.removeChild(titleElement); | ||
} | ||
let anchor = node.querySelector('.markup--mixtapeEmbed-anchor').href; | ||
let title = node.querySelector('.markup--mixtapeEmbed-strong'); | ||
let desc = node.querySelector('.markup--mixtapeEmbed-em'); | ||
let img = node.querySelector('.mixtapeImage'); | ||
let imgSrc = false; // Image is optional, | ||
if (descElement && descElement.innerHTML) { | ||
description = cleanBasicHtml(descElement.innerHTML, options); // Cleanup anchor so we can see what's left now that we've processed description | ||
anchorElement.removeChild(descElement); | ||
} // // Format our preferred structure. | ||
let metadata = { | ||
url, | ||
title, | ||
description | ||
}; // Publisher is the remaining text in the anchor, once title & desc are removed | ||
let publisher = cleanBasicHtml(anchorElement.innerHTML, options); | ||
if (publisher) { | ||
metadata.publisher = publisher; | ||
} // Image is optional, | ||
// The element usually still exists with an additional has.mixtapeImage--empty class and has no background image | ||
if (img && img.style['background-image']) { | ||
imgSrc = img.style['background-image'].match(/url\(([^)]*?)\)/)[1]; | ||
} // Format our preferred structure. | ||
if (imgElement && imgElement.style['background-image']) { | ||
metadata.thumbnail = imgElement.style['background-image'].match(/url\(([^)]*?)\)/)[1]; | ||
} | ||
let metadata = { | ||
url: anchor, | ||
title: title, | ||
description: desc, | ||
thumbnail: imgSrc | ||
}; | ||
let payload = { | ||
metadata, | ||
url: metadata.url, | ||
type: 'bookmark' | ||
url, | ||
metadata | ||
}; | ||
@@ -96,0 +119,0 @@ let cardSection = builder.createCardSection('bookmark', payload); |
@@ -81,23 +81,46 @@ /* global DOMParser, window */ | ||
let anchor = node.querySelector('.markup--mixtapeEmbed-anchor').href; | ||
let title = node.querySelector('.markup--mixtapeEmbed-strong'); | ||
let desc = node.querySelector('.markup--mixtapeEmbed-em'); | ||
let img = node.querySelector('.mixtapeImage'); | ||
let imgSrc = false; | ||
// Grab the relevant elements - Anchor wraps most of the data | ||
let anchorElement = node.querySelector('.markup--mixtapeEmbed-anchor'); | ||
let titleElement = anchorElement.querySelector('.markup--mixtapeEmbed-strong'); | ||
let descElement = anchorElement.querySelector('.markup--mixtapeEmbed-em'); | ||
// Image is a top level field inside it's own a tag | ||
let imgElement = node.querySelector('.mixtapeImage'); | ||
// Image is optional, | ||
// The element usually still exists with an additional has.mixtapeImage--empty class and has no background image | ||
if (img && img.style['background-image']) { | ||
imgSrc = img.style['background-image'].match(/url\(([^)]*?)\)/)[1]; | ||
// Grab individual values from the elements | ||
let url = anchorElement.href; | ||
let title = ''; | ||
let description = ''; | ||
if (titleElement && titleElement.innerHTML) { | ||
title = cleanBasicHtml(titleElement.innerHTML, options); | ||
// Cleanup anchor so we can see what's left now that we've processed title | ||
anchorElement.removeChild(titleElement); | ||
} | ||
// Format our preferred structure. | ||
if (descElement && descElement.innerHTML) { | ||
description = cleanBasicHtml(descElement.innerHTML, options); | ||
// Cleanup anchor so we can see what's left now that we've processed description | ||
anchorElement.removeChild(descElement); | ||
} | ||
// // Format our preferred structure. | ||
let metadata = { | ||
url: anchor, | ||
title: title, | ||
description: desc, | ||
thumbnail: imgSrc | ||
url, | ||
title, | ||
description | ||
}; | ||
let payload = {metadata, url: metadata.url, type: 'bookmark'}; | ||
// Publisher is the remaining text in the anchor, once title & desc are removed | ||
let publisher = cleanBasicHtml(anchorElement.innerHTML, options); | ||
if (publisher) { | ||
metadata.publisher = publisher; | ||
} | ||
// Image is optional, | ||
// The element usually still exists with an additional has.mixtapeImage--empty class and has no background image | ||
if (imgElement && imgElement.style['background-image']) { | ||
metadata.thumbnail = imgElement.style['background-image'].match(/url\(([^)]*?)\)/)[1]; | ||
} | ||
let payload = {url, metadata}; | ||
let cardSection = builder.createCardSection('bookmark', payload); | ||
@@ -104,0 +127,0 @@ addSection(cardSection); |
{ | ||
"name": "@tryghost/kg-parser-plugins", | ||
"version": "0.8.1", | ||
"version": "0.9.0", | ||
"repository": "https://github.com/TryGhost/Koenig/tree/master/packages/kg-parser-plugins", | ||
@@ -30,8 +30,8 @@ "author": "Ghost Foundation", | ||
"devDependencies": { | ||
"@babel/core": "7.7.2", | ||
"@babel/preset-env": "7.7.1", | ||
"@babel/core": "7.8.3", | ||
"@babel/preset-env": "7.8.3", | ||
"@tryghost/mobiledoc-kit": "0.11.2-ghost.4", | ||
"jsdom": "15.2.1", | ||
"mocha": "6.2.0", | ||
"rollup": "1.26.4", | ||
"rollup": "1.29.0", | ||
"rollup-plugin-babel": "4.3.3", | ||
@@ -42,5 +42,5 @@ "should": "13.2.3", | ||
"dependencies": { | ||
"@tryghost/kg-clean-basic-html": "^0.1.4" | ||
"@tryghost/kg-clean-basic-html": "^0.1.5" | ||
}, | ||
"gitHead": "075f36f96f6dfd03241b558aab72d23b44badcdc" | ||
"gitHead": "b20e921c2767eec7b36da94dc9fd85859b83cf9c" | ||
} |
@@ -41,2 +41,2 @@ # Koenig Parser Plugins | ||
Copyright (c) 2018-2019 Ghost Foundation - Released under the [MIT license](LICENSE). | ||
Copyright (c) 2013-2020 Ghost Foundation - Released under the [MIT license](LICENSE). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73571
1074