~m15o/the-neon-kiosk

ac2e4f77b435df8d63ea9b41e1372418174006a3 — m15o 2 years ago ebf8a24
fix for images
1 files changed, 13 insertions(+), 0 deletions(-)

M main.go
M main.go => main.go +13 -0
@@ 75,7 75,9 @@ func resolveLink(b, l string) (string, error) {
}

var are = regexp.MustCompile(`<a [^<>]*>`)
var ire = regexp.MustCompile(`<img [^<>]*>`)
var hre = regexp.MustCompile(`href="([^"]+)"`)
var sre = regexp.MustCompile(`src="([^"]+)"`)

func processContent(u, content string) (string, error) {
	rv := are.ReplaceAllStringFunc(content, func(s string) string {


@@ 89,6 91,17 @@ func processContent(u, content string) (string, error) {
		}
		return s
	})
	rv = ire.ReplaceAllStringFunc(rv, func(s string) string {
		matches := sre.FindStringSubmatch(s)
		if len(matches) > 1 {
			l, err := resolveLink(u, matches[1])
			if err != nil {
				return s
			}
			return strings.Replace(s, matches[0], "src=\""+l+"\"", 1)
		}
		return s
	})
	return rv, nil
}