diff --git a/main.go b/main.go index b38cc10..4c49046 100644 --- a/main.go +++ b/main.go @@ -84,6 +84,7 @@ func test() { []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"}, []string{"https://lemmy.world/post/123", "/lemmy.local/post/123@lemmy.world", "/post/123@lemmy.world"}, + []string{"https://lemmy.world/post/123#123", "https://lemmy.world/post/123#123", "https://lemmy.world/post/123#123"}, []string{"/post/123", "/lemmy.local/post/123", "/post/123"}, []string{"/comment/123", "/lemmy.local/comment/123", "/comment/123"}, []string{"https://lemmy.local/comment/123", "/lemmy.local/comment/123", "/comment/123"}, diff --git a/routes.go b/routes.go index e8af5f0..b727261 100644 --- a/routes.go +++ b/routes.go @@ -167,7 +167,7 @@ var funcMap = template.FuncMap{ func LemmyLinkRewrite(input string, host string, lemmy_domain string) (body string) { body = input // localize community and user links - body = RegReplace(body, `href="https:\/\/([a-zA-Z0-9\.\-]+)\/((c|u|comment|post)\/.*?)"`, `href="/$2@$1"`) + body = RegReplace(body, `href="https:\/\/([a-zA-Z0-9\.\-]+)\/((c|u|comment|post)\/[^#\?]*?)"`, `href="/$2@$1"`) // remove extra instance tag 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 == "" { diff --git a/state.go b/state.go index 181417f..19dfd6c 100644 --- a/state.go +++ b/state.go @@ -314,6 +314,9 @@ func (state *State) GetComment(commentid int) { state.Comments = append(state.Comments, comment) } } + if len(state.Comments) == 0 { + return + } ctx, err := state.GetContext(state.Context, state.Comments[0]) if err != nil { fmt.Println(err)