Monorepo for Tangled tangled.org
844
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview: don't use camo for non-external readme images

Signed-off-by: Seongmin Lee <git@boltless.me>

+9 -21
-12
appview/pages/markup/camo.go
··· 5 5 "crypto/sha256" 6 6 "encoding/hex" 7 7 "fmt" 8 - 9 - "github.com/yuin/goldmark/ast" 10 8 ) 11 9 12 10 func GenerateCamoURL(baseURL, secret, imageURL string) string { ··· 18 16 } 19 17 20 18 func (rctx *RenderContext) camoImageLinkTransformer(dst string) string { 21 - // don't camo on dev 22 - if rctx.IsDev { 23 - return dst 24 - } 25 - 26 19 if rctx.CamoUrl != "" && rctx.CamoSecret != "" { 27 20 return GenerateCamoURL(rctx.CamoUrl, rctx.CamoSecret, dst) 28 21 } 29 22 30 23 return dst 31 24 } 32 - 33 - func (rctx *RenderContext) camoImageLinkAstTransformer(img *ast.Image) { 34 - dst := string(img.Destination) 35 - img.Destination = []byte(rctx.camoImageLinkTransformer(dst)) 36 - }
+9 -5
appview/pages/markup/markdown.go
··· 184 184 continue 185 185 } 186 186 187 - camoUrl, _ := url.Parse(ctx.CamoUrl) 188 - dstUrl, _ := url.Parse(attr.Val) 189 - if camoUrl != nil && dstUrl != nil && dstUrl.Host != camoUrl.Host { 187 + if isAbsoluteUrl(attr.Val) { 188 + // apply camo to external links 189 + camoUrl, _ := url.Parse(ctx.CamoUrl) 190 + dstUrl, _ := url.Parse(attr.Val) 191 + if camoUrl != nil && dstUrl != nil && dstUrl.Host != ctx.Hostname && dstUrl.Host != camoUrl.Host { 192 + attr.Val = ctx.camoImageLinkTransformer(attr.Val) 193 + } 194 + } else { 190 195 attr.Val = ctx.imageToRawTransformer(attr.Val) 191 - attr.Val = ctx.camoImageLinkTransformer(attr.Val) 192 - node.Attr[i] = attr 193 196 } 197 + node.Attr[i] = attr 194 198 } 195 199 } 196 200
-4
appview/repo/blob.go
··· 278 278 query.Set("raw", "true") 279 279 280 280 blobURL := fmt.Sprintf("%s/xrpc/%s?%s", config.KnotMirror.Url, tangled.GitTempGetBlobNSID, query.Encode()) 281 - 282 - if config.Camo.Enabled() { 283 - return markup.GenerateCamoURL(config.Camo.Host, config.Camo.SharedSecret, blobURL) 284 - } 285 281 return blobURL 286 282 } 287 283