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.
In order of preference (default sort order):
- JSON-LD
- Open Graph
- HTML External Resource Link
- Apple Touch Icon
- Twitter Cards Markup
- Microsoft Tile Image
- Favicon
go get github.com/daetal-us/kii/cmd/kii
Note: results are always returned as an array.
Retrieve icons for a url:
kii http://apple.com
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"]
}