From 9782144dcb041908113a306e183205de3eb525f5 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Sat, 15 Jul 2023 22:41:39 -0400 Subject: [PATCH] rewrite fix --- main.go | 2 ++ routes.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index b00f6cc..c50efbe 100644 --- a/main.go +++ b/main.go @@ -74,6 +74,8 @@ func test() { []string{"https://lemmy.local/u/dude", "/lemmy.local/u/dude", "/u/dude"}, []string{"https://lemmy.local/u/dude@lemmy.local", "/lemmy.local/u/dude", "/u/dude"}, []string{"/u/dude", "/lemmy.local/u/dude", "/u/dude"}, + []string{"/u/dude@lemmy.world", "/lemmy.local/u/dude@lemmy.world", "/u/dude@lemmy.world"}, + []string{"/u/dude@lemmy.local", "/lemmy.local/u/dude", "/u/dude"}, []string{"https://lemmy.world/c/dude", "/lemmy.local/c/dude@lemmy.world", "/c/dude@lemmy.world"}, []string{"https://lemmy.world/u/dude", "/lemmy.local/u/dude@lemmy.world", "/u/dude@lemmy.world"}, []string{"https://lemmy.world/u/dude@lemmy.world", "/lemmy.local/u/dude@lemmy.world", "/u/dude@lemmy.world"}, diff --git a/routes.go b/routes.go index a933b77..8ff74d1 100644 --- a/routes.go +++ b/routes.go @@ -165,11 +165,11 @@ var funcMap = template.FuncMap{ func LemmyLinkRewrite(input string, host string, lemmy_domain string) (body string) { body = input // community bangs - body = RegReplace(body, `!([a-zA-Z0-9]+)@([a-zA-Z0-9\.\-]+)[ $]?`, `!$1@$2 `) + body = RegReplace(body, `!([a-zA-Z0-9]+)@([a-zA-Z0-9\.\-]+)([ \n\r]+|<\/p>)`, `!$1@$2 `) // localize community and user links body = RegReplace(body, `href="https:\/\/([a-zA-Z0-9\.\-]+)\/((c|u)\/.*?)"`, `href="/$2@$1"`) // remove extra instance tag - body = RegReplace(body, `href="\/((c|u)\/.*@.*?)@(.*?)"`, `href="/$1"`) + body = RegReplace(body, `href="(https:\/)?(\/[a-zA-Z0-9\.\-]+)?\/((c|u)\/[a-zA-Z0-9]+@[a-zA-Z0-9\.\-]+)@([a-zA-Z0-9\.\-]+)"`, `href="/$3"`) if lemmy_domain == "" { // add domain to relative links body = RegReplace(body, `href="\/(c\/[a-zA-Z0-9\-]+"|(post|comment)\/\d+"|(c|u)\/(.*?)")`, `href="/`+host+`/$1`)