summaryrefslogtreecommitdiff
path: root/includes/external/addressbook/node_modules/open-graph-scraper/dist/lib/extract.js
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-04-06 22:18:28 +0200
committerRaindropsSys <contact@minteck.org>2023-04-06 22:18:28 +0200
commit83354b2b88218090988dd6e526b0a2505b57e0f1 (patch)
treee3c73c38a122a78bb7e66fbb99056407edd9d4b9 /includes/external/addressbook/node_modules/open-graph-scraper/dist/lib/extract.js
parent47b8f2299a483024c4a6a8876af825a010954caa (diff)
downloadpluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.gz
pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.bz2
pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.zip
Updated 5 files and added 1110 files (automated)
Diffstat (limited to 'includes/external/addressbook/node_modules/open-graph-scraper/dist/lib/extract.js')
-rw-r--r--includes/external/addressbook/node_modules/open-graph-scraper/dist/lib/extract.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/includes/external/addressbook/node_modules/open-graph-scraper/dist/lib/extract.js b/includes/external/addressbook/node_modules/open-graph-scraper/dist/lib/extract.js
new file mode 100644
index 0000000..cd4b802
--- /dev/null
+++ b/includes/external/addressbook/node_modules/open-graph-scraper/dist/lib/extract.js
@@ -0,0 +1,58 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+const cheerio_1 = require("cheerio");
+const fallback_1 = require("./fallback");
+const fields_1 = require("./fields");
+const media = require("./media");
+const utils = require("./utils");
+/**
+ * extract all of the meta tags needed for ogs
+ *
+ * @param {sting} body - the body of the got request
+ * @param {object} options - options for ogs
+ * @return {object} object with ogs results
+ *
+ */
+function extractMetaTags(body, options, rawBody) {
+ let ogObject = {};
+ const $ = (0, cheerio_1.load)(body);
+ const metaFields = fields_1.default.concat(options.customMetaTags);
+ // find all of the open graph info in the meta tags
+ $('meta').each((index, meta) => {
+ if (!meta.attribs || (!meta.attribs.property && !meta.attribs.name))
+ return;
+ const property = meta.attribs.property || meta.attribs.name;
+ const content = meta.attribs.content || meta.attribs.value;
+ metaFields.forEach((item) => {
+ if (item && property.toLowerCase() === item.property.toLowerCase()) {
+ if (!item.multiple) {
+ ogObject[item.fieldName] = content;
+ }
+ else if (!ogObject[item.fieldName]) {
+ ogObject[item.fieldName] = [content];
+ }
+ else if (Array.isArray(ogObject[item.fieldName])) {
+ ogObject[item.fieldName].push(content);
+ }
+ }
+ });
+ });
+ // set ogImage to ogImageSecureURL/ogImageURL if there is no ogImage
+ if (!ogObject.ogImage && ogObject.ogImageSecureURL) {
+ ogObject.ogImage = ogObject.ogImageSecureURL;
+ }
+ else if (!ogObject.ogImage && ogObject.ogImageURL) {
+ ogObject.ogImage = ogObject.ogImageURL;
+ }
+ // formats the multiple media values
+ ogObject = media.mediaSetup(ogObject, options);
+ // if onlyGetOpenGraphInfo isn't set, run the open graph fallbacks
+ if (!options.onlyGetOpenGraphInfo) {
+ ogObject = (0, fallback_1.default)(ogObject, options, $, rawBody);
+ }
+ // TODO: Is this still needed?
+ // removes any undefs
+ ogObject = utils.removeNestedUndefinedValues(ogObject);
+ return ogObject;
+}
+exports.default = extractMetaTags;