Skip to content
/ kii Public

A command line utility and library to extract representative icons from various structured data formats and other forms embedded in HTML.

License

Notifications You must be signed in to change notification settings

daetal-us/kii

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A command line utility and library to extract representative icons from various structured data formats and other forms embedded in HTML.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages