move hashtag to mz module
Ted Unangst tedu@tedunangst.com
Mon, 20 Jul 2020 23:00:36 -0400
2 files changed,
9 insertions(+),
37 deletions(-)
M
fun.go
→
fun.go
@@ -34,6 +34,7 @@ "humungus.tedunangst.com/r/webs/cache"
"humungus.tedunangst.com/r/webs/htfilter" "humungus.tedunangst.com/r/webs/httpsig" "humungus.tedunangst.com/r/webs/templates" + "humungus.tedunangst.com/r/webs/mz" ) var allowedclasses = make(map[string]bool)@@ -68,7 +69,6 @@ }
if local && h.What != "bonked" { h.Noise = re_memes.ReplaceAllString(h.Noise, "") h.Noise = mentionize(h.Noise) - h.Noise = ontologize(h.Noise) } h.Username, h.Handle = handles(h.Honker) if !local {@@ -236,10 +236,12 @@ }
} honk.Precis = markitzero(strings.TrimSpace(honk.Precis)) + var marker mz.Marker + marker.HashLinker = ontoreplacer noise = strings.TrimSpace(noise) - noise = markitzero(noise) + noise = marker.Mark(noise) honk.Noise = noise - honk.Onts = oneofakind(ontologies(honk.Noise)) + honk.Onts = oneofakind(marker.HashTags) } func redoimages(honk *Honk) {@@ -263,7 +265,7 @@ }
honk.Donks = honk.Donks[:j] honk.Noise = re_memes.ReplaceAllString(honk.Noise, "") - honk.Noise = ontologize(mentionize(honk.Noise)) + honk.Noise = mentionize(honk.Noise) honk.Noise = strings.Replace(honk.Noise, "<a href=", "<a class=\"mention u-url\" href=", -1) }@@ -288,24 +290,6 @@ rand.Read(b[:])
return xcelerate(b[:]) } -var re_hashes = regexp.MustCompile(`(?:^| |>)#[[:alnum:]]*[[:alpha:]][[:alnum:]_-]*`) - -func ontologies(s string) []string { - m := re_hashes.FindAllString(s, -1) - j := 0 - for _, h := range m { - if h[0] == '&' { - continue - } - if h[0] != '#' { - h = h[1:] - } - m[j] = h - j++ - } - return m[:j] -} - var re_mentions = regexp.MustCompile(`@[[:alnum:]._-]+@[[:alnum:].-]*[[:alnum:]]`) var re_urltions = regexp.MustCompile(`@https://\S+`)@@ -491,21 +475,9 @@ })
return s } -func ontologize(s string) string { - s = re_hashes.ReplaceAllStringFunc(s, func(o string) string { - if o[0] == '&' { - return o - } - p := "" - h := o - if h[0] != '#' { - p = h[:1] - h = h[1:] - } - return fmt.Sprintf(`%s<a href="https://%s/o/%s">%s</a>`, p, serverName, +func ontoreplacer(h string) string { + return fmt.Sprintf(`<a href="https://%s/o/%s">%s</a>`, serverName, strings.ToLower(h[1:]), h) - }) - return s } var re_unurl = regexp.MustCompile("https://([^/]+).*/([^/]+)")
M
markitzero.go
→
markitzero.go
@@ -16,7 +16,7 @@
package main import ( - mz "humungus.tedunangst.com/r/webs/markitzero" + "humungus.tedunangst.com/r/webs/mz" ) func markitzero(s string) string {