|
|
@@ -241,13 +241,6 @@ func resizeIcon(icon *model.Icon) *model.Icon {
|
|
|
}
|
|
|
|
|
|
func findIconURLsFromHTMLDocument(body io.Reader, contentType string) ([]string, error) {
|
|
|
- queries := []string{
|
|
|
- "link[rel='icon' i]",
|
|
|
- "link[rel='shortcut icon' i]",
|
|
|
- "link[rel='icon shortcut' i]",
|
|
|
- "link[rel='apple-touch-icon-precomposed.png']",
|
|
|
- }
|
|
|
-
|
|
|
htmlDocumentReader, err := encoding.NewCharsetReader(body, contentType)
|
|
|
if err != nil {
|
|
|
return nil, fmt.Errorf("icon: unable to create charset reader: %w", err)
|
|
|
@@ -258,20 +251,26 @@ func findIconURLsFromHTMLDocument(body io.Reader, contentType string) ([]string,
|
|
|
return nil, fmt.Errorf("icon: unable to read document: %v", err)
|
|
|
}
|
|
|
|
|
|
+ queries := []string{
|
|
|
+ "link[rel='icon' i][href]",
|
|
|
+ "link[rel='shortcut icon' i][href]",
|
|
|
+ "link[rel='icon shortcut' i][href]",
|
|
|
+ "link[rel='apple-touch-icon-precomposed.png'][href]",
|
|
|
+ }
|
|
|
+
|
|
|
var iconURLs []string
|
|
|
for _, query := range queries {
|
|
|
slog.Debug("Searching icon URL in HTML document", slog.String("query", query))
|
|
|
|
|
|
- doc.Find(query).Each(func(i int, s *goquery.Selection) {
|
|
|
- if href, exists := s.Attr("href"); exists {
|
|
|
- if iconURL := strings.TrimSpace(href); iconURL != "" {
|
|
|
- iconURLs = append(iconURLs, iconURL)
|
|
|
- slog.Debug("Found icon URL in HTML document",
|
|
|
- slog.String("query", query),
|
|
|
- slog.String("icon_url", iconURL))
|
|
|
- }
|
|
|
+ for _, s := range doc.Find(query).EachIter() {
|
|
|
+ href, _ := s.Attr("href")
|
|
|
+ if iconURL := strings.TrimSpace(href); iconURL != "" {
|
|
|
+ iconURLs = append(iconURLs, iconURL)
|
|
|
+ slog.Debug("Found icon URL in HTML document",
|
|
|
+ slog.String("query", query),
|
|
|
+ slog.String("icon_url", iconURL))
|
|
|
}
|
|
|
- })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return iconURLs, nil
|