composition support for inline images
This commit is contained in:
parent
bd5183c44f
commit
054aa15a17
|
@ -33,7 +33,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"humungus.tedunangst.com/r/webs/cache"
|
"humungus.tedunangst.com/r/webs/cache"
|
||||||
"humungus.tedunangst.com/r/webs/htfilter"
|
|
||||||
"humungus.tedunangst.com/r/webs/httpsig"
|
"humungus.tedunangst.com/r/webs/httpsig"
|
||||||
"humungus.tedunangst.com/r/webs/image"
|
"humungus.tedunangst.com/r/webs/image"
|
||||||
"humungus.tedunangst.com/r/webs/junk"
|
"humungus.tedunangst.com/r/webs/junk"
|
||||||
|
@ -824,11 +823,6 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
|
||||||
content = content[:90001]
|
content = content[:90001]
|
||||||
}
|
}
|
||||||
|
|
||||||
// grab any inline imgs
|
|
||||||
imgfilt := htfilter.New()
|
|
||||||
imgfilt.Imager = inlineimgsfor(&xonk)
|
|
||||||
imgfilt.String(content)
|
|
||||||
|
|
||||||
// init xonk
|
// init xonk
|
||||||
xonk.What = what
|
xonk.What = what
|
||||||
xonk.XID = xid
|
xonk.XID = xid
|
||||||
|
@ -844,6 +838,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
|
||||||
xonk.Whofore = 1
|
xonk.Whofore = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
imaginate(&xonk)
|
||||||
|
|
||||||
if isUpdate {
|
if isUpdate {
|
||||||
log.Printf("something has changed! %s", xonk.XID)
|
log.Printf("something has changed! %s", xonk.XID)
|
||||||
|
@ -1023,7 +1018,7 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) {
|
||||||
if !h.Public {
|
if !h.Public {
|
||||||
jo["directMessage"] = true
|
jo["directMessage"] = true
|
||||||
}
|
}
|
||||||
translate(h)
|
translate(h, true)
|
||||||
h.Noise = re_memes.ReplaceAllString(h.Noise, "")
|
h.Noise = re_memes.ReplaceAllString(h.Noise, "")
|
||||||
jo["summary"] = html.EscapeString(h.Precis)
|
jo["summary"] = html.EscapeString(h.Precis)
|
||||||
jo["content"] = ontologize(mentionize(h.Noise))
|
jo["content"] = ontologize(mentionize(h.Noise))
|
||||||
|
|
|
@ -2,6 +2,8 @@ changelog
|
||||||
|
|
||||||
-- next
|
-- next
|
||||||
|
|
||||||
|
+ Inline images in posts. Send and receive.
|
||||||
|
|
||||||
+ Somewhat functional admin console (TTY).
|
+ Somewhat functional admin console (TTY).
|
||||||
|
|
||||||
+ More JS free fallbacks for some basic functions.
|
+ More JS free fallbacks for some basic functions.
|
||||||
|
@ -14,8 +16,6 @@ changelog
|
||||||
|
|
||||||
+++ Add Honk Filtering and Censorship System (HFCS).
|
+++ Add Honk Filtering and Censorship System (HFCS).
|
||||||
|
|
||||||
+ Inline images in received posts.
|
|
||||||
|
|
||||||
+ Times for events.
|
+ Times for events.
|
||||||
|
|
||||||
+ Split media database into separate blob.db.
|
+ Split media database into separate blob.db.
|
||||||
|
|
|
@ -44,6 +44,11 @@ Inline `code fragments` with single ticks.
|
||||||
int main() { return 0; }
|
int main() { return 0; }
|
||||||
```
|
```
|
||||||
.Ed
|
.Ed
|
||||||
|
.It images
|
||||||
|
Inline images with img tags.
|
||||||
|
.Bd -literal
|
||||||
|
<img alt="Lifecycle of a honk" src="https://example.com/diagram.png">
|
||||||
|
.Ed
|
||||||
.It links
|
.It links
|
||||||
URLs beginning with
|
URLs beginning with
|
||||||
.Dq http
|
.Dq http
|
||||||
|
|
42
fun.go
42
fun.go
|
@ -58,7 +58,7 @@ func reverbolate(userid int64, honks []*Honk) {
|
||||||
if !h.Public {
|
if !h.Public {
|
||||||
h.Style += " limited"
|
h.Style += " limited"
|
||||||
}
|
}
|
||||||
translate(h)
|
translate(h, false)
|
||||||
if h.Whofore == 2 || h.Whofore == 3 {
|
if h.Whofore == 2 || h.Whofore == 3 {
|
||||||
h.URL = h.XID
|
h.URL = h.XID
|
||||||
if h.What != "bonked" {
|
if h.What != "bonked" {
|
||||||
|
@ -92,7 +92,7 @@ func reverbolate(userid int64, honks []*Honk) {
|
||||||
zap := make(map[string]bool)
|
zap := make(map[string]bool)
|
||||||
{
|
{
|
||||||
filt := htfilter.New()
|
filt := htfilter.New()
|
||||||
filt.Imager = replaceimgsand(zap)
|
filt.Imager = replaceimgsand(zap, false)
|
||||||
filt.SpanClasses = allowedclasses
|
filt.SpanClasses = allowedclasses
|
||||||
p, _ := filt.String(h.Precis)
|
p, _ := filt.String(h.Precis)
|
||||||
n, _ := filt.String(h.Noise)
|
n, _ := filt.String(h.Noise)
|
||||||
|
@ -145,7 +145,7 @@ func reverbolate(userid int64, honks []*Honk) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func replaceimgsand(zap map[string]bool) func(node *html.Node) string {
|
func replaceimgsand(zap map[string]bool, absolute bool) func(node *html.Node) string {
|
||||||
return func(node *html.Node) string {
|
return func(node *html.Node) string {
|
||||||
src := htfilter.GetAttr(node, "src")
|
src := htfilter.GetAttr(node, "src")
|
||||||
alt := htfilter.GetAttr(node, "alt")
|
alt := htfilter.GetAttr(node, "alt")
|
||||||
|
@ -156,7 +156,11 @@ func replaceimgsand(zap map[string]bool) func(node *html.Node) string {
|
||||||
d := finddonk(src)
|
d := finddonk(src)
|
||||||
if d != nil {
|
if d != nil {
|
||||||
zap[d.XID] = true
|
zap[d.XID] = true
|
||||||
return string(templates.Sprintf(`<img alt="%s" title="%s" src="/d/%s">`, alt, alt, d.XID))
|
base := ""
|
||||||
|
if absolute {
|
||||||
|
base = "https://" + serverName
|
||||||
|
}
|
||||||
|
return string(templates.Sprintf(`<img alt="%s" title="%s" src="%s/d/%s">`, alt, alt, base, d.XID))
|
||||||
}
|
}
|
||||||
return string(templates.Sprintf(`<img alt="%s" src="<a href="%s">%s<a>">`, alt, src, src))
|
return string(templates.Sprintf(`<img alt="%s" src="<a href="%s">%s<a>">`, alt, src, src))
|
||||||
}
|
}
|
||||||
|
@ -177,7 +181,13 @@ func inlineimgsfor(honk *Honk) func(node *html.Node) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func translate(honk *Honk) {
|
func imaginate(honk *Honk) {
|
||||||
|
imgfilt := htfilter.New()
|
||||||
|
imgfilt.Imager = inlineimgsfor(honk)
|
||||||
|
imgfilt.String(honk.Noise)
|
||||||
|
}
|
||||||
|
|
||||||
|
func translate(honk *Honk, redoimages bool) {
|
||||||
if honk.Format == "html" {
|
if honk.Format == "html" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -197,9 +207,29 @@ func translate(honk *Honk) {
|
||||||
noise = strings.TrimSpace(noise)
|
noise = strings.TrimSpace(noise)
|
||||||
noise = quickrename(noise, honk.UserID)
|
noise = quickrename(noise, honk.UserID)
|
||||||
noise = markitzero(noise)
|
noise = markitzero(noise)
|
||||||
|
|
||||||
honk.Noise = noise
|
honk.Noise = noise
|
||||||
honk.Onts = oneofakind(ontologies(honk.Noise))
|
honk.Onts = oneofakind(ontologies(honk.Noise))
|
||||||
|
|
||||||
|
if redoimages {
|
||||||
|
zap := make(map[string]bool)
|
||||||
|
{
|
||||||
|
filt := htfilter.New()
|
||||||
|
filt.Imager = replaceimgsand(zap, true)
|
||||||
|
filt.SpanClasses = allowedclasses
|
||||||
|
p, _ := filt.String(honk.Precis)
|
||||||
|
n, _ := filt.String(honk.Noise)
|
||||||
|
honk.Precis = string(p)
|
||||||
|
honk.Noise = string(n)
|
||||||
|
}
|
||||||
|
j := 0
|
||||||
|
for i := 0; i < len(honk.Donks); i++ {
|
||||||
|
if !zap[honk.Donks[i].XID] {
|
||||||
|
honk.Donks[j] = honk.Donks[i]
|
||||||
|
j++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
honk.Donks = honk.Donks[:j]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func shortxid(xid string) string {
|
func shortxid(xid string) string {
|
||||||
|
|
3
web.go
3
web.go
|
@ -1065,7 +1065,7 @@ func submithonk(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
noise = hooterize(noise)
|
noise = hooterize(noise)
|
||||||
honk.Noise = noise
|
honk.Noise = noise
|
||||||
translate(honk)
|
translate(honk, false)
|
||||||
|
|
||||||
var convoy string
|
var convoy string
|
||||||
if rid != "" {
|
if rid != "" {
|
||||||
|
@ -1189,6 +1189,7 @@ func submithonk(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memetize(honk)
|
memetize(honk)
|
||||||
|
imaginate(honk)
|
||||||
|
|
||||||
placename := strings.TrimSpace(r.FormValue("placename"))
|
placename := strings.TrimSpace(r.FormValue("placename"))
|
||||||
placelat := strings.TrimSpace(r.FormValue("placelat"))
|
placelat := strings.TrimSpace(r.FormValue("placelat"))
|
||||||
|
|
Loading…
Reference in New Issue