opengraph

package
v0.0.0-...-977eb4a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TitleProp                 = "title"
	TypeProp                  = "type"
	ImageProp                 = "image"
	URLProp                   = "url"
	DescriptionProp           = "description"
	SiteNameProp              = "site_name"
	ImageStructPropPfx        = "image:"
	ImageURLProp              = "image:url"
	ImageSecureURLProp        = "image:secure_url"
	ImageTypeProp             = "image:type"
	ImageWidthProp            = "image:width"
	ImageHeightProp           = "image:height"
	ProfileFirstnameProp      = "first_name"
	ProfileLastnameProp       = "last_name"
	ArticleSectionProp        = "section"
	ArticlePublishedTimeProp  = "published_time"
	ArticleModifiedTimeProp   = "modified_time"
	ArticleExpirationTimeProp = "expiration_time"
	ArticleAuthorProp         = "author"
	ProfileObjtype            = "profile"
	ArticleObjtype            = "article"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ArticlePropParser

type ArticlePropParser struct {
	Authors []string
	// contains filtered or unexported fields
}

func (*ArticlePropParser) Parse

func (pp *ArticlePropParser) Parse(property, content string, propertyTable map[string]string) bool

type ImagePropParser

type ImagePropParser struct {
	ImageList []data.MarkupImage
}

func (*ImagePropParser) Parse

func (pp *ImagePropParser) Parse(property, content string, propertyTable map[string]string) bool

func (*ImagePropParser) Verify

func (pp *ImagePropParser) Verify()

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser recognizes and parses the Open Graph Protocol markup tags and returns the properties that matter to distilled content.

First, it extracts the prefix and/or xmlns attributes from the HTML or HEAD tags to determine the prefixes that will be used for the protocol. If no prefix is specified, we fall back to the commonly used ones, e.g. "og". Then, it scans the OpenGraph Protocol <meta> elements that we care about, extracts their content, and stores them semantically, i.e. taking into consideration arrays, structures, and object types. Callers call get* to access these properties.

The properties we care about are:

  • 4 required properties: title, type, image, url.
  • 2 optional properties: description, site_name.
  • image structured properties: image:url, image:secure_url, image:type, image:width, image:height
  • profile object properties: first_name, last_name
  • article object properties: section, published_time, modified_time, expiration_time, author; each author is a URL to the author's profile.

func NewParser

func NewParser(root *html.Node, timingInfo *data.TimingInfo) (*Parser, error)

func (*Parser) Article

func (ps *Parser) Article() *data.MarkupArticle

Article returns the properties of the "article" object when value of "og:type" is "article". The properties are published_time, modified_time and expiration_time, section, and a list of URLs to each author's profile.

func (*Parser) Author

func (ps *Parser) Author() string

Author returns the concatenated first_name and last_name (delimited by a whitespace) of the "profile" object when value of "og:type" is "profile".

func (*Parser) Copyright

func (ps *Parser) Copyright() string

Copyright returns empty since OpenGraph not support it.

func (*Parser) Description

func (ps *Parser) Description() string

Description returns the optional "description" of the document.

func (*Parser) Images

func (ps *Parser) Images() []data.MarkupImage

Images returns the structured properties of all "image" structures. Each "image" structure consists of image, image:url, image:secure_url, image:type, image:width, and image:height.

func (*Parser) OptOut

func (ps *Parser) OptOut() bool

OptOut returns false since OpenGraph not support it. While this is not directly supported, the page owner can simply omit the required tags and init() will return a null OpenGraphProtocolParser.

func (*Parser) Publisher

func (ps *Parser) Publisher() string

Publisher returns the optional "site_name" of the document.

func (*Parser) Title

func (ps *Parser) Title() string

Title returns the required "title" of the document.

func (*Parser) Type

func (ps *Parser) Type() string

Type returns the required "type" of the document if it's an article, empty string otherwise.

func (*Parser) URL

func (ps *Parser) URL() string

URL returns the required "url" of the document.

type Prefix

type Prefix uint
const (
	OG Prefix = iota
	Profile
	Article
)

type PrefixNameList

type PrefixNameList map[Prefix]string

type ProfilePropParser

type ProfilePropParser struct {
	// contains filtered or unexported fields
}

func (*ProfilePropParser) GetFullName

func (pp *ProfilePropParser) GetFullName(propertyTable map[string]string) string

func (*ProfilePropParser) Parse

func (pp *ProfilePropParser) Parse(property, content string, propertyTable map[string]string) bool

type PropParser

type PropParser interface {
	Parse(property, content string, propertyTable map[string]string) bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL