don't try to rewrite links with anchors. fixes #45
This commit is contained in:
parent
3fe31bd5b3
commit
463b3fe49d
3 changed files with 5 additions and 1 deletions
1
main.go
1
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"},
|
||||
|
|
|
|||
|
|
@ -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 == "" {
|
||||
|
|
|
|||
3
state.go
3
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue