Skip to content
This repository has been archived by the owner on Feb 24, 2022. It is now read-only.

Commit

Permalink
Scrape image:width and image:height, if available
Browse files Browse the repository at this point in the history
  • Loading branch information
pdehaan committed Aug 17, 2016
1 parent 23d758a commit 7c88bc8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const titleRules = buildRuleset('title', [

const canonicalUrlRules = buildRuleset('url', [
['meta[property="og:url"]', node => node.element.content],
['meta[name="twitter:url"]', node => node.element.content],
['link[rel="canonical"]', node => node.element.href],
]);

Expand All @@ -57,6 +58,14 @@ const imageRules = buildRuleset('image', [
['img', node => node.element.src],
]);

const imageWidthRules = buildRuleset('image_width', [
['meta[property="og:image:width"]', node => node.element.content],
]);

const imageHeightRules = buildRuleset('image_height', [
['meta[property="og:image:height"]', node => node.element.content],
]);

const descriptionRules = buildRuleset('description', [
['meta[property="og:description"]', node => node.element.content],
['meta[name="description"]', node => node.element.content],
Expand All @@ -70,16 +79,17 @@ const typeRules = buildRuleset('type', [
const metadataRules = {
description: descriptionRules,
icon_url: iconRules,
image_height: imageHeightRules,
image_url: imageRules,
image_width: imageWidthRules,
title: titleRules,
type: typeRules,
url: canonicalUrlRules
url: canonicalUrlRules,
};


function getMetadata(doc, rules) {
function getMetadata(doc, ruleSet = metadataRules) {
const metadata = {};
const ruleSet = rules || metadataRules;

Object.keys(ruleSet).map(metadataKey => {
const metadataRule = ruleSet[metadataKey];
Expand Down

0 comments on commit 7c88bc8

Please sign in to comment.