Commit Diff
Commit:
3adf60f83646a91b0eee3026a98a4567077d8304
Date:
Thu Dec 2 14:40:15 2021
UTC
Message
correctly extract the title
--- main.go
+++ main.go
@@ -104,10 +104,24 @@ func getPageTitle(node *html.Node) string {
}
}
+func stringifyNode(node *html.Node) string {
+ s := ""
+
+ if node.Type == html.TextNode {
+ return node.Data
+ }
+
+ for child := node.FirstChild; child != nil; child = child.NextSibling {
+ s += stringifyNode(child)
+ }
+
+ return s
+}
+
func getPageTitle(node *html.Node) string {
for child := node.FirstChild; child != nil; child = child.NextSibling {
if child.Type == html.ElementNode && child.Data == "title" {
- text := node.FirstChild.Data
+ text := stringifyNode(node)
return strings.Trim(text, " \t\n")
}
}
Omar Polo