1.0.1 • Published 1 year ago

grab-page-info v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

grab-page-info

Grabs Open Graph and Twitter Card metadata out of an HTML page

Installation

Use npm (or yarn, or pnpm) to add grab-page-info to your project:

npm install grab-page-info

grab-page-info contains CommonJS and ESM modules for use in Node, in the browser and at the edge.

Usage

import { grabPageInfo } from 'grab-page-info';
const html = '<html></html>';
const info = grabPageInfo(html);

Types

PageInfo

The info returned from the grabPageInfo method has the following properties:

PropertyTypeDescription
titlestringThe text inside the page's <title> tag
charsetstringThe character set from the page's <meta charset> tag, which gives the character encoding of the page's document
linksLinkData[]The details of any <link> tags in the page, including links for stylesheets, RSS feeds, icons, and so on
metaApplicationNamestringThe name of the application running in the web page
metaDescriptionstringA summary of the content of the page
metaAuthorstringThe name of the document's author
metaCreatorstringThe name of the creator of the document, such as an organization or institution
metaPublisherstringThe name of the document's publisher
metaCopyrightstringA copyright declaration for the content of the page
metaKeywordsstringWords relevant to the page's content separated by commas
metaRatingstringIndicates the appropriate age level for accessing the content of the page
metaGeneratorstringThe identifier of the software that generated the page
metaReferrerstringControls the HTTP Referer header of requests sent from the document
metaThemeColorstringA suggested color that user agents should use to customize the display of the page or of the surrounding user interface
metaColorSchemestringOne or more color schemes with which the document is compatible
metaRobotsstringThe behavior that cooperative crawlers, or "robots", should use with the page
metaGooglebotstringA synonym of robots which is only followed by the indexing crawler for Google
metaViewportstringGives hints about the size of the initial size of the viewport
openTitlestringThe title of the page as it should appear within the graph, e.g., "The Rock"
openTypestringThe type of the page, e.g., "video.movie". Depending on the type specified, other properties will also be set
openUrlstringThe canonical URL of the page that will be used as its permanent ID in the graph, e.g., "https://www.imdb.com/title/tt0117500/"
openImagesOpenImageData[]Images which should represent the page within the graph
openDescriptionstringA one to two sentence description of the page
openDeterminerstringThe word that appears before the page's title in a sentence. An enum of (a, an, the, "", auto). If auto is chosen, the consumer of your data should chose between "a" or "an". Default is "" (blank)
openLocalestringThe locale the page is marked up in. Of the format language_TERRITORY. Default is en_US
openAlternateLocalesstring[]An array of other locales the page is available in
openSiteNamestringIf the page is part of a larger web site, the name which should be displayed for the overall site. e.g., "IMDb"
openVideosOpenVideoData[]Video files that complement the page
openAudioOpenAudioDataAn audio file to accompany the page
twitterCardstringThe card type
twitterSitestringThe Twitter username of the website. Either twitter:site or twitter:site:id is required
twitterSiteIdstringThe Twitter ID of the website. Either twitter:site or twitter:site:id is required
twitterCreatorstringThe Twitter username of the content creator
twitterCreatorIdstringThe Twitter user ID of the content creator
twitterTitlestringThe title of the content (max 70 characters)
twitterDescriptionstringA description of the content (maximum 200 characters)
twitterImageTwitterImageDataAn image to use in the card. JPG, PNG, WEBP and GIF formats are supported
twitterPlayerTwitterPlayerDataA player iframe to use in the card
twitterAppTwitterAppDataDetails of the App to show in the card

LinkData

The details of a <link> tag, such as a link to a stylesheet, RSS feed, icon, and so on.

PropertyTypeDescription
hrefstringThe URL of the linked resource. A URL can be absolute or relative
relstringThe relationship of the linked document to the current document. Its value must be a space-separated list of link type values
titlestringThe title of the linked resource
typestringThe type of the content linked to. The value of the attribute should be a MIME type such as text/html, text/css, and so on
sizesstringThe sizes of the icons contained in the resource. It must be present only if the rel contains a value of icon or a non-standard type such as Apple's apple-touch-icon
mediastringSpecifies the media that the linked resource applies to. Its value must be a media type/media query

OpenImageData

An image which should represent a page within the graph.

PropertyTypeDescription
urlstringAn image URL which should represent the page within the graph
secureUrlstringAn alternate url to use if the webpage requires HTTPS
typestringA MIME type for this image
widthstringThe number of pixels wide
heightstringThe number of pixels high
altstringA description of what is in the image (not a caption). If the page specifies an image it should specify alt text

OpenVideoData

A video file that complements a page.

PropertyTypeDescription
urlstringA video URL which should accompany the page within the graph
secureUrlstringAn alternate url to use if the webpage requires HTTPS
typestringA MIME type for this video
widthstringThe number of pixels wide
heightstringThe number of pixels high

OpenAudioData

An audio file to accompany a page.

PropertyTypeDescription
urlstringAn audio URL which should accompany the page within the graph
secureUrlstringAn alternate url to use if the webpage requires HTTPS
typestringA MIME type for this audio

TwitterImageData

An image to use in in a Twitter card.

PropertyTypeDescription
urlstringThe URL of the image to use in the card. JPG, PNG, WEBP and GIF formats are supported
altstringA text description of the image conveying the essential nature of an image to users who are visually impaired. Maximum 420 characters

TwitterPlayerData

A player iframe to use in a Twitter card.

PropertyTypeDescription
urlstringThe HTTPS URL of the player iframe
widthstringThe width of the iframe in pixels
heightstringThe height of the iframe in pixels
streamstringA URL to a raw video or audio stream

TwitterAppData

Details of the App to show in a Twitter card.

PropertyTypeDescription
countrystringThe country the app is from
iPhoneNamestringThe name of the iPhone app
iPhoneIdstringThe iPhone app ID in the iTunes App Store
iPhoneUrlstringThe iPhone app's custom URL scheme (which must include '://' after the scheme name)
iPadNamestringThe name of the iPad optimized app
iPadIdstringThe iPad app ID in the iTunes App Store
iPadUrlstringThe iPad app's custom URL scheme
androidNamestringThe name of the Android app
androidIdstringThe Android app ID in the Google Play Store
androidUrlstringThe Android app's custom URL scheme
1.0.1

1 year ago