Skip to content

Latest commit

 

History

History
104 lines (87 loc) · 2.48 KB

README.md

File metadata and controls

104 lines (87 loc) · 2.48 KB

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"]
}