Skip to content

Commit

Permalink
rewrite fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rystaf committed Jul 16, 2023
1 parent 23d08a7 commit 9782144
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func test() {
[]string{"https://lemmy.local/u/dude", "/lemmy.local/u/dude", "/u/dude"},
[]string{"https://lemmy.local/u/[email protected]", "/lemmy.local/u/dude", "/u/dude"},
[]string{"/u/dude", "/lemmy.local/u/dude", "/u/dude"},
[]string{"/u/[email protected]", "/lemmy.local/u/[email protected]", "/u/[email protected]"},
[]string{"/u/[email protected]", "/lemmy.local/u/dude", "/u/dude"},
[]string{"https://lemmy.world/c/dude", "/lemmy.local/c/[email protected]", "/c/[email protected]"},
[]string{"https://lemmy.world/u/dude", "/lemmy.local/u/[email protected]", "/u/[email protected]"},
[]string{"https://lemmy.world/u/[email protected]", "/lemmy.local/u/[email protected]", "/u/[email protected]"},
Expand Down
4 changes: 2 additions & 2 deletions routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\.\-]+)[ $]?`, `<a href="/c/$1">!$1@$2</a> `)
body = RegReplace(body, `!([a-zA-Z0-9]+)@([a-zA-Z0-9\.\-]+)([ \n\r]+|<\/p>)`, `<a href="/c/$1@$2">!$1@$2</a> `)
// 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`)
Expand Down

0 comments on commit 9782144

Please sign in to comment.