mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
Refactor icon finder
Changes: - Continue the discovery process when the feed icon is invalid - Search all icons from the HTML document and do not stop on the first one
This commit is contained in:
parent
7650c81ad9
commit
9fd2dfa680
3 changed files with 172 additions and 113 deletions
|
@ -112,59 +112,16 @@ func TestParseDocumentWithWhitespaceIconURL(t *testing.T) {
|
|||
/static/img/favicon.ico
|
||||
">`
|
||||
|
||||
iconURL, err := findIconURLFromHTMLDocument(strings.NewReader(html))
|
||||
iconURLs, err := findIconURLsFromHTMLDocument(strings.NewReader(html))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if iconURL != "/static/img/favicon.ico" {
|
||||
t.Errorf(`Invalid icon URL, got %q`, iconURL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateIconURL(t *testing.T) {
|
||||
iconURL, err := generateIconURL("https://example.org/", "/favicon.png")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if iconURL != "https://example.org/favicon.png" {
|
||||
t.Errorf(`Invalid icon URL, got %q`, iconURL)
|
||||
}
|
||||
|
||||
iconURL, err = generateIconURL("https://example.org/", "img/favicon.png")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if iconURL != "https://example.org/img/favicon.png" {
|
||||
t.Errorf(`Invalid icon URL, got %q`, iconURL)
|
||||
}
|
||||
|
||||
iconURL, err = generateIconURL("https://example.org/", "https://example.org/img/favicon.png")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if iconURL != "https://example.org/img/favicon.png" {
|
||||
t.Errorf(`Invalid icon URL, got %q`, iconURL)
|
||||
}
|
||||
|
||||
iconURL, err = generateIconURL("https://example.org/", "//example.org/img/favicon.png")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if iconURL != "https://example.org/img/favicon.png" {
|
||||
t.Errorf(`Invalid icon URL, got %q`, iconURL)
|
||||
}
|
||||
|
||||
iconURL, err = generateIconURL("https://example.org/", " ")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if iconURL != "https://example.org/favicon.ico" {
|
||||
t.Errorf(`Invalid icon URL, got %q`, iconURL)
|
||||
if len(iconURLs) != 1 {
|
||||
t.Fatalf(`Invalid number of icon URLs, got %d`, len(iconURLs))
|
||||
}
|
||||
|
||||
if iconURLs[0] != "/static/img/favicon.ico" {
|
||||
t.Errorf(`Invalid icon URL, got %q`, iconURLs[0])
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue