@@ -30,6 +30,8 @@ type Document struct {
3030}
3131
3232type DocumentPreview struct {
33+ Icon string
34+ Name string
3335 Title string
3436 Description string
3537 Images []string
@@ -165,6 +167,10 @@ func (scraper *Scraper) parseDocument(doc *Document) error {
165167 doc .Preview .Images = []string {}
166168 // saves previews' link in case that <link rel="canonical"> is found after <meta property="og:url">
167169 link := doc .Preview .Link
170+ // set default value to site name if <meta property="og:site_name"> not found
171+ doc .Preview .Name = scraper .Url .Host
172+ // set default icon to web root if <link rel="icon" href="/favicon.ico"> not found
173+ doc .Preview .Icon = fmt .Sprintf ("%s://%s%s" , scraper .Url .Scheme , scraper .Url .Host , "/favicon.ico" )
168174 for {
169175 tokenType := t .Next ()
170176 if tokenType == html .ErrorToken {
@@ -185,11 +191,15 @@ func (scraper *Scraper) parseDocument(doc *Document) error {
185191
186192 case "link" :
187193 var canonical bool
194+ var hasIcon bool
188195 var href string
189196 for _ , attr := range token .Attr {
190197 if cleanStr (attr .Key ) == "rel" && cleanStr (attr .Val ) == "canonical" {
191198 canonical = true
192199 }
200+ if cleanStr (attr .Key ) == "rel" && cleanStr (attr .Val ) == "icon" {
201+ hasIcon = true
202+ }
193203 if cleanStr (attr .Key ) == "href" {
194204 href = attr .Val
195205 }
@@ -201,6 +211,9 @@ func (scraper *Scraper) parseDocument(doc *Document) error {
201211 return err
202212 }
203213 }
214+ if len (href ) > 0 && hasIcon {
215+ doc .Preview .Icon = href
216+ }
204217 }
205218
206219 case "meta" :
@@ -221,6 +234,8 @@ func (scraper *Scraper) parseDocument(doc *Document) error {
221234 }
222235 }
223236 switch cleanStr (property ) {
237+ case "og:site_name" :
238+ doc .Preview .Name = content
224239 case "og:title" :
225240 doc .Preview .Title = content
226241 case "og:description" :
0 commit comments