OpenGraphJS
OpenGraphJS builds a JSON object from a web page which follows the Open Graph Protocol. The JavaScript object returned by this library contains important metadata such as the description, image, and title.
Installation
npm install opengraphjs
Usage
Promise support
- Its easy, if you are using a version of node with Promises you are ready to go!
- Other versions of node:
- define
global.Promise = require('bluebird');
- Feel free to substitute Bluebird with your perferred promise library
- define
// Include itvar ogjs = ;// Pass in a URL ;
Callbacks
// Include itvar ogjs = ;// Pass in a URL;
Expected ouput
Sample
title: 'Open Graph protocol' type: 'website' url: 'http://ogp.me/' description: 'The Open Graph protocol enables any web page to become a rich object in a social graph.' image: url: 'http://ogp.me/logo.png' type: 'image/png' width: '300' height: '300'
Supported properties
Property Name | JS Name | Type | Description |
---|---|---|---|
og:title | title | string | title set in og:title, if missing uses the page's title tag |
og:type | type | string | open graph type for the current document |
og:url | url | string | sharable url to content |
og:description | description | string | describes the media/page being shared |
og:determiner | determiner | string | |
og:locale | locale | object | has two properties, `name` which contains the default locale and `alternate` which is an array of strings with additional locales |
og:site_name | siteName | string | |
og:image | image | array | Array of objects Properties: - url (always present) - secureUrl (optional) - width (optional) - height (optional) |
og:video | video | array | Array of objects Properties: - url (always present) - secureUrl (optional) - width (optional) - height (optional) |
og:audio | audio | array | Array of objects Properties: - url (always present) - secureUrl (optional) |
Credits and Acknowledgements
- Inspired by openGraphScraper