gopengraph

package
v0.0.0-...-5c77d7d Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2014 License: MIT, MIT Imports: 2 Imported by: 0

README

Gopengraph CI Status

GopenGraph is a very simple Go library for parsing Open Graph protocol and Metadata information from web sites.

Installation

$ go get github.com/roperzh/gopengraph

Usage


import (
  "fmt"

  "github.com/PuerkitoBio/goquery"
  "github.com/roperzh/gopengraph"
)

// Directly from an URL
pageFromUrl := gopengraph.NewFromUrl("https://github.com/")

fmt.Printf("Title: %s, Description: %s", pageFromUrl.Title, pageFromUrl.Description)
// => Title: Build software better, together, Description: GitHub is ..

// From a *goquery.Document
doc, err := goquery.NewDocument(url)
pageFromDocument := gopengraph.New(doc)

fmt.Printf("og:site_name: %s, og:url: %s", pageFromDocument.OgAttrs["og:site_name"], pageFromDocument.OgAttrs["og:url"])
// => og:site_name: GitHub, og:url: https://github.com

Contributing

1- Fork it

2- Create your feature branch (git checkout -b my-new-feature)

3- Commit your changes (git commit -am 'Add some feature')

4- Push to the branch (git push origin my-new-feature)

5- Create new Pull Request

License

MIT License

Documentation

Overview

Package gopengraph

For a full guide visit https://github.com/roperzh/gopengraph

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GopenGraph

type GopenGraph struct {
	OgAttrs        map[string]string
	Title          string
	Description    string
	Url            string
	MandatoryAttrs []string
}

func New

func New(doc *goquery.Document) *GopenGraph

Build a new instance of the GopenGraph struct based on an already scrapped site

func NewFromUrl

func NewFromUrl(url string) (*GopenGraph, error)

Build a new instance of the GopenGraph Struct with an url string

func (*GopenGraph) IsValid

func (m *GopenGraph) IsValid() bool

Check if all MandatoryAttrs are present

func (*GopenGraph) PopulateAttrs

func (m *GopenGraph) PopulateAttrs(doc *goquery.Document)

Store the page Title and Description

func (*GopenGraph) PopulateOgTags

func (m *GopenGraph) PopulateOgTags(doc *goquery.Document)

Store all Open Graph tags (http://ogp.me/)

Jump to

Keyboard shortcuts

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