microformats

package module
Version: v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2020 License: MIT Imports: 12 Imported by: 15

README

microformats

GoDoc Test Status Test Coverage

microformats is a go library and tool for parsing microformats, supporting both classic v1 and v2 syntax. It is based on Andy Leap's original library.

Usage

Import the package:

import "willnorris.com/go/microformats"

Fetch the HTML contents of a page, and call Parse or ParseNode, depending on what input you have (an io.Reader or an html.Node). See an example of each in cmd/gomf/main.go.

Documentation

Overview

Package microformats provides a microformats parser, supporting both v1 and v2 syntax.

Usage:

import "willnorris.com/go/microformats"

Retrieve the HTML contents of a page, and call Parse or ParseNode, depending on what input you have (an io.Reader or an html.Node).

To parse only a section of an HTML document, use a package like goquery to select the root node to parse from. For example, see cmd/gomf/main.go.

See also: http://microformats.org/wiki/microformats2

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	// Items includes all top-level microformats found on the page.
	Items []*Microformat `json:"items"`

	// Rels includes all related URLs found on the page (<a> or <link>
	// elements with a "rel" value).  Map keys are the rel value, mapped to
	// a slice of URLs with that relation.  For example:
	//
	//     map[string][]string{
	//         "author": {"http://example.com/a", "http://example.com/b"},
	//         "alternate": {"http://example.com/fr"},
	//     }
	//
	// Relative URL values are resolved to absolute URLs using the base URL
	// of the page.
	Rels map[string][]string `json:"rels"`

	// RelURLs maps related URLs found on the page to additional metadata
	// about that relationship. If a URL is linked to more than once, only
	// the metadata for the first link is included here.  Relative URL
	// values are resolved to absolute URLs using the base URL of the page.
	RelURLs map[string]*RelURL `json:"rel-urls"`
}

Data specifies all of the microformats and data parsed from a single HTML page.

func Parse

func Parse(r io.Reader, baseURL *url.URL) *Data

Parse the microformats found in the HTML document read from r. baseURL is the URL this document was retrieved from and is used to resolve any relative URLs.

func ParseNode

func ParseNode(doc *html.Node, baseURL *url.URL) *Data

ParseNode parses the microformats found in doc. baseURL is the URL this document was retrieved from and is used to resolve any relative URLs.

type Microformat

type Microformat struct {
	ID         string                   `json:"id,omitempty"`
	Value      string                   `json:"value,omitempty"`
	HTML       string                   `json:"html,omitempty"`
	Type       []string                 `json:"type"`
	Properties map[string][]interface{} `json:"properties"`
	Shape      string                   `json:"shape,omitempty"`
	Coords     string                   `json:"coords,omitempty"`
	Children   []*Microformat           `json:"children,omitempty"`
	// contains filtered or unexported fields
}

Microformat specifies a single microformat object and its properties. It may represent a person, an address, a blog post, etc.

type RelURL

type RelURL struct {
	Rels     []string `json:"rels,omitempty"`
	Text     string   `json:"text,omitempty"`
	Media    string   `json:"media,omitempty"`
	HrefLang string   `json:"hreflang,omitempty"`
	Title    string   `json:"title,omitempty"`
	Type     string   `json:"type,omitempty"`
}

RelURL represents the attributes of a URL. The URL value itself is the map key in the RelURLs field of the Data type.

Directories

Path Synopsis
cmd
gomf
The gomf tool is a command line tool which parses microformats from the specified URL.
The gomf tool is a command line tool which parses microformats from the specified URL.
gomfweb
The gomfweb command runs a simple web server that demonstrates the use of the go microformats library.
The gomfweb command runs a simple web server that demonstrates the use of the go microformats library.
Package ptd implements Post Type Discovery as defined by https://www.w3.org/TR/post-type-discovery/
Package ptd implements Post Type Discovery as defined by https://www.w3.org/TR/post-type-discovery/

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to