all repos — honk @ 5aa91b020bb92fe076570e2a0b3fb1ae1b74b741

my fork of honk

match all images in hoots
Ted Unangst tedu@tedunangst.com
Sat, 05 Feb 2022 16:23:40 -0500
commit

5aa91b020bb92fe076570e2a0b3fb1ae1b74b741

parent

574517c141f7b4e2c18d38af56e5a5cb522466f1

1 files changed, 8 insertions(+), 6 deletions(-)

jump to
M hoot.gohoot.go

@@ -44,21 +44,23 @@ if err != nil {

log.Printf("error parsing hoot: %s", err) return url } - divs := tweetsel.MatchAll(root) url = strings.Replace(url, "mobile.twitter.com", "twitter.com", -1) - - var wanted string wantmatch := authorregex.FindStringSubmatch(url) + var wanted string if len(wantmatch) == 2 { wanted = wantmatch[1] } - var buf strings.Builder - fmt.Fprintf(&buf, "%s\n", url) + var htf htfilter.Filter htf.Imager = func(node *html.Node) string { return fmt.Sprintf(" <img src='%s'>", htfilter.GetAttr(node, "src")) } + + var buf strings.Builder + fmt.Fprintf(&buf, "%s\n", url) + + divs := tweetsel.MatchAll(root) for i, div := range divs { twp := div.Parent.Parent.Parent link := url

@@ -87,7 +89,7 @@ }

if author != wanted { continue } - if img := imgsel.MatchFirst(twp); img != nil { + for img := imgsel.MatchFirst(twp); img != nil; imgsel.MatchFirst(twp) { img.Parent.RemoveChild(img) div.AppendChild(img) }