metadata

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Metadata package is a set of tools to parse HTML pages to extract their metadata.

For now, the following set of metadata specifications are supported:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Page

type Page struct {
	Lang       string     `json:"lang,omitempty"`
	Properties Properties `json:"properties,omitempty"`
	// contains filtered or unexported fields
}

Page is structure holding HTML page metadata.

func ReadPage

func ReadPage(body io.Reader) (Page, error)

ReadPage is use to extract metadata from an HTML page. It returns a Page struct for easy manipulation of those metadata.

Example
package main

import (
	"fmt"
	"strings"

	"github.com/processone/dpk/pkg/metadata"
)

func main() {
	html := `<!DOCTYPE html>
  <html lang="en">
  <head prefix="og: http://ogp.me/ns#">
      <meta charset="utf-8"/>
      <meta property="og:title" content="Open Graph title" />
  </head>
  <body><p>This is a test page</p></body>
  </html>`
	if page, err := metadata.ReadPage(strings.NewReader(html)); err != nil {
		fmt.Println(page.Title())
	}
}
Output:

Open Graph title

func (Page) Title

func (p Page) Title() string

Title returns the page title based on defined priorities (html 5 > dc > og > twitter > title)

type Properties

type Properties map[string]string

Properties is a map gathering HTML page metadata properties.

Jump to

Keyboard shortcuts

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