kii

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2018 License: MIT Imports: 7 Imported by: 0

README

KIʻI

A golang command line utility and library to extract distinct, representative icons from various structured data formats and other forms embedded in HTML -- typically associated with a particular website or web page.

Supported Formats

In order of preference (default sort order):

Installation

go get github.com/daetal-us/kii/cmd/kii

Usage

Note: results are always returned as an array.

Command Line

Retrieve icons for a url:

kii http://apple.com
Golang
package main

import (
	"log"
	"encoding/json"

	"github.com/daetal-us/kii"
)

func main() {
	extractFromHTML()
	extractFromURL()
}

func extractFromHTML() {
	html := `
	<html>
		<head>
			<meta property="og:image" content="a.png">
			<meta name="twitter:image" content="a.png" />
			<link rel="shortcut icon" href="b.ico" />
		</head>
		<body>
			<script type="application/ld+json">
			{
				"@type": "Organization",
				"name": "Example",
				"image": "c.png"
			}
			</script>
		</body>
	</html>
	`
	results, err := kii.FromHTML(html)
	if err != nil {
		log.Fatal(err)
	}
	encoded, err := json.Marshal(results)
	if err != nil {
		log.fatal(err)
	}
	log.Println(string(encoded)) // ["c.png","a.png","b.ico"]
}

func extractFromURL() {
	results, err := kii.FromURL("http://apple.com")
	if err != nil {
		log.Fatal(err)
	}
	encoded, err := json.Marshal(results)
	if err != nil {
		log.fatal(err)
	}
	log.Println(string(encoded)) // [...,"favicon.ico"]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromHTML

func FromHTML(html string) (result []string, err error)

func FromReader

func FromReader(r io.Reader) (results []string, err error)

func FromURL

func FromURL(u string) (result []string, err error)

Types

This section is empty.

Directories

Path Synopsis
cmd
kii

Jump to

Keyboard shortcuts

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