Skip to content

Commit

Permalink
Refactor (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe authored Jul 2, 2024
1 parent a5b18c9 commit 9bfe2f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions link_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ func (f linkFinder) Find(n *html.Node, base *url.URL) map[string]error {
return ok
}) {

// https://github.com/raviqqe/muffet/issues/391
// preconnect and dns-prefetch hrefs are not http resources
// `preconnect` and `dns-prefetch` links are not HTTP resources.
if n.DataAtom == atom.Link {
rel := scrape.Attr(n, "rel")
if rel == "preconnect" || rel == "dns-prefetch" {

if rel := scrape.Attr(n, "rel"); rel == "preconnect" || rel == "dns-prefetch" {
continue
}
}
Expand Down
6 changes: 3 additions & 3 deletions link_finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ func TestLinkFinderIgnorePreconnect(t *testing.T) {
html string
linkCount int
}{
{`<link rel="preconnect" href="https://fonts.googleapis.com">`, 0},
{`<link rel="dns-prefetch" href="https://fonts.googleapis.com">`, 0},
{`<link rel="dns-prefetch" href="https://fonts.googleapis.com"><link href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,300;0,400;0,700;1,400&amp;family=Source+Sans+Pro:ital,wght@0,300;0,400;0,600;1,400&amp;display=swap" rel="stylesheet">`, 1},
{`<link rel="preconnect" href="https://foo.com">`, 0},
{`<link rel="dns-prefetch" href="https://foo.com">`, 0},
{`<link rel="dns-prefetch" href="https://foo.com"><link href="https://bar.com/baz.css" rel="stylesheet">`, 1},
} {
n, err := html.Parse(strings.NewReader(htmlWithBody(c.html)))
assert.Nil(t, err)
Expand Down

0 comments on commit 9bfe2f0

Please sign in to comment.