remove inline meme text from post
Ted Unangst tedu@tedunangst.com
Sun, 30 Jun 2019 19:04:37 -0400
M
fun.go
→
fun.go
@@ -192,10 +192,8 @@ }
var re_memes = regexp.MustCompile("meme: ?([[:alnum:]_.-]+)") -func memetics(noise string) []*Donk { - var donks []*Donk - m := re_memes.FindAllString(noise, -1) - for _, x := range m { +func memetize(honk *Honk) { + repl := func(x string) string { name := x[5:] if name[0] == ' ' { name = name[1:]@@ -203,7 +201,7 @@ }
fd, err := os.Open("memes/" + name) if err != nil { log.Printf("no meme for %s", name) - continue + return x } var peek [512]byte n, _ := fd.Read(peek[:])@@ -214,7 +212,7 @@ url := fmt.Sprintf("https://%s/meme/%s", serverName, name)
res, err := stmtSaveFile.Exec("", name, url, ct, 0, "") if err != nil { log.Printf("error saving meme: %s", err) - continue + return x } var d Donk d.FileID, _ = res.LastInsertId()@@ -223,9 +221,11 @@ d.Name = name
d.Media = ct d.URL = url d.Local = false - donks = append(donks, &d) + honk.Donks = append(honk.Donks, &d) + log.Printf("replace with -") + return "" } - return donks + honk.Noise = re_memes.ReplaceAllStringFunc(honk.Noise, repl) } var re_bolder = regexp.MustCompile(`(^|\W)\*\*([\w\s,.!?'-]+)\*\*($|\W)`)
M
honk.go
→
honk.go
@@ -1047,7 +1047,7 @@ donk.Name = e.Name
honk.Donks = append(honk.Donks, donk) } } - honk.Donks = append(honk.Donks, memetics(honk.Noise)...) + memetize(&honk) aud := strings.Join(honk.Audience, " ") whofore := 2@@ -1069,7 +1069,7 @@ }
return } res, err := stmtSaveHonk.Exec(userinfo.UserID, what, honk.Honker, xid, rid, - dt.Format(dbtimeformat), "", aud, noise, convoy, whofore, "html", honk.Precis, honk.Oonker) + dt.Format(dbtimeformat), "", aud, honk.Noise, convoy, whofore, "html", honk.Precis, honk.Oonker) if err != nil { log.Printf("error saving honk: %s", err) return