Skip to content

Commit

Permalink
Exclude style tags from head element search
Browse files Browse the repository at this point in the history
  • Loading branch information
alileza committed Mar 3, 2024
1 parent c42b59b commit 951c0a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions redirector/htmlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ func FetchHeadElements(targetURL string) (string, error) {
return html.Parse(resp.Body)
}

// Recursive function to find all elements within <head> excluding scripts and stylesheets
// Recursive function to find all elements within <head> excluding scripts, stylesheets, and style tags
findHeadElements := func(n *html.Node) []*html.Node {
var headElements []*html.Node
var traverse func(*html.Node)
traverse = func(n *html.Node) {
if n.Type == html.ElementNode && n.Data == "head" {
for child := n.FirstChild; child != nil; child = child.NextSibling {
if child.Data != "script" && child.Data != "link" {
// Exclude script, link, and style tags
if child.Data != "script" && child.Data != "link" && child.Data != "style" {
headElements = append(headElements, child)
}
}
Expand Down
2 changes: 1 addition & 1 deletion routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ a: https://a.com
abc: https://hehe.com
db: https://distrobe.at
doner: kebab123
go: https://google.com
me: https://alileza.me
test: https://google.com
tos: tos

0 comments on commit 951c0a8

Please sign in to comment.