Skip to content

Commit

Permalink
Merge pull request #62 from juanolon/fix-backlinks
Browse files Browse the repository at this point in the history
Fix backlinks
  • Loading branch information
emad-elsaid committed Jun 19, 2024
2 parents 3099d7f + b41a558 commit ca6f454
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions extensions/autolink_pages/autolink_pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"embed"
"html/template"
"path"
"sort"
"strings"
"sync"

_ "embed"
Expand Down Expand Up @@ -81,6 +83,27 @@ func containLinkTo(n ast.Node, p Page) bool {
return true
}
}
if n.Kind() == ast.KindLink {
t, _ := n.(*ast.Link)
dst := string(t.Destination)

// link is absolute: remove /
if strings.HasPrefix(dst, "/") {
path := strings.TrimPrefix(dst, "/")
if string(path) == p.Name() {
return true
}
} else { // link is relative: get relative part
// TODO: what if another folder has the same filename?
// * just ignore that fact
// * dont support relative paths
// there is no way to know who is the parent folder
base := path.Base(p.Name())
if dst == base {
return true
}
}
}

for c := n.FirstChild(); c != nil; c = c.NextSibling() {
if containLinkTo(c, p) {
Expand Down

0 comments on commit ca6f454

Please sign in to comment.