move hashtag to mz module

This commit is contained in:
Ted Unangst 2020-07-20 23:00:36 -04:00
parent 781bbde3e8
commit a7dbec14c4
2 changed files with 9 additions and 37 deletions

44
fun.go
View File

@ -34,6 +34,7 @@ import (
"humungus.tedunangst.com/r/webs/htfilter" "humungus.tedunangst.com/r/webs/htfilter"
"humungus.tedunangst.com/r/webs/httpsig" "humungus.tedunangst.com/r/webs/httpsig"
"humungus.tedunangst.com/r/webs/templates" "humungus.tedunangst.com/r/webs/templates"
"humungus.tedunangst.com/r/webs/mz"
) )
var allowedclasses = make(map[string]bool) var allowedclasses = make(map[string]bool)
@ -68,7 +69,6 @@ func reverbolate(userid int64, honks []*Honk) {
if local && h.What != "bonked" { if local && h.What != "bonked" {
h.Noise = re_memes.ReplaceAllString(h.Noise, "") h.Noise = re_memes.ReplaceAllString(h.Noise, "")
h.Noise = mentionize(h.Noise) h.Noise = mentionize(h.Noise)
h.Noise = ontologize(h.Noise)
} }
h.Username, h.Handle = handles(h.Honker) h.Username, h.Handle = handles(h.Honker)
if !local { if !local {
@ -236,10 +236,12 @@ func translate(honk *Honk) {
} }
honk.Precis = markitzero(strings.TrimSpace(honk.Precis)) honk.Precis = markitzero(strings.TrimSpace(honk.Precis))
var marker mz.Marker
marker.HashLinker = ontoreplacer
noise = strings.TrimSpace(noise) noise = strings.TrimSpace(noise)
noise = markitzero(noise) noise = marker.Mark(noise)
honk.Noise = noise honk.Noise = noise
honk.Onts = oneofakind(ontologies(honk.Noise)) honk.Onts = oneofakind(marker.HashTags)
} }
func redoimages(honk *Honk) { func redoimages(honk *Honk) {
@ -263,7 +265,7 @@ func redoimages(honk *Honk) {
honk.Donks = honk.Donks[:j] honk.Donks = honk.Donks[:j]
honk.Noise = re_memes.ReplaceAllString(honk.Noise, "") 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) honk.Noise = strings.Replace(honk.Noise, "<a href=", "<a class=\"mention u-url\" href=", -1)
} }
@ -288,24 +290,6 @@ func xfiltrate() string {
return xcelerate(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_mentions = regexp.MustCompile(`@[[:alnum:]._-]+@[[:alnum:].-]*[[:alnum:]]`)
var re_urltions = regexp.MustCompile(`@https://\S+`) var re_urltions = regexp.MustCompile(`@https://\S+`)
@ -491,21 +475,9 @@ func mentionize(s string) string {
return s return s
} }
func ontologize(s string) string { func ontoreplacer(h string) string {
s = re_hashes.ReplaceAllStringFunc(s, func(o string) string { return fmt.Sprintf(`<a href="https://%s/o/%s">%s</a>`, serverName,
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,
strings.ToLower(h[1:]), h) strings.ToLower(h[1:]), h)
})
return s
} }
var re_unurl = regexp.MustCompile("https://([^/]+).*/([^/]+)") var re_unurl = regexp.MustCompile("https://([^/]+).*/([^/]+)")

View File

@ -16,7 +16,7 @@
package main package main
import ( import (
mz "humungus.tedunangst.com/r/webs/markitzero" "humungus.tedunangst.com/r/webs/mz"
) )
func markitzero(s string) string { func markitzero(s string) string {