MCPcopy Create free account
hub / github.com/Vespa314/cflow / extractHTMLMeta

Function extractHTMLMeta

plugin/http-getter/html_meta.go:42–85  ·  view source on GitHub ↗
(resp io.Reader)

Source from the content-addressed store, hash-verified

40}
41
42func extractHTMLMeta(resp io.Reader) *HTMLMeta {
43 tokenizer := html.NewTokenizer(resp)
44 htmlMeta := new(HTMLMeta)
45
46 for {
47 tokenType := tokenizer.Next()
48 if tokenType == html.ErrorToken {
49 break
50 } else if tokenType == html.StartTagToken || tokenType == html.SelfClosingTagToken {
51 token := tokenizer.Token()
52 if token.DataAtom == atom.Body {
53 break
54 }
55
56 if token.DataAtom == atom.Title {
57 tokenizer.Next()
58 token := tokenizer.Token()
59 htmlMeta.Title = token.Data
60 } else if token.DataAtom == atom.Meta {
61 description, ok := extractMetaProperty(token, "description")
62 if ok {
63 htmlMeta.Description = description
64 }
65
66 ogTitle, ok := extractMetaProperty(token, "og:title")
67 if ok {
68 htmlMeta.Title = ogTitle
69 }
70
71 ogDescription, ok := extractMetaProperty(token, "og:description")
72 if ok {
73 htmlMeta.Description = ogDescription
74 }
75
76 ogImage, ok := extractMetaProperty(token, "og:image")
77 if ok {
78 htmlMeta.Image = ogImage
79 }
80 }
81 }
82 }
83
84 return htmlMeta
85}
86
87func extractMetaProperty(token html.Token, prop string) (content string, ok bool) {
88 content, ok = "", false

Callers 1

GetHTMLMetaFunction · 0.85

Calls 1

extractMetaPropertyFunction · 0.85

Tested by

no test coverage detected