mirror of
https://github.com/rystaf/mlmym.git
synced 2024-11-09 08:32:21 +00:00
rewrite fix
This commit is contained in:
parent
23d08a730c
commit
9782144dcb
2
main.go
2
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"},
|
||||
|
|
|
@ -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`)
|
||||
|
|
Loading…
Reference in a new issue