Skip to content

Commit

Permalink
Merge pull request #17 from fogo-sh/dedupe-backlinks
Browse files Browse the repository at this point in the history
dedupe and sort backlinks
  • Loading branch information
jackharrhy authored Aug 31, 2023
2 parents c5364ad + 50e35de commit c665678
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pkg/content/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,27 @@ func PopulateBacklinks(pages map[string]*Page) {
for _, page := range pages {
for _, link := range page.LinksTo {
if _, ok := pages[link]; ok {
pages[link].Backlinks = append(pages[link].Backlinks, page.Title)
found := false

for _, backlink := range pages[link].Backlinks {
if backlink == page.Title {
found = true
break
}
}

if !found {
pages[link].Backlinks = append(pages[link].Backlinks, page.Title)
}
}
}
}

for _, page := range pages {
sort.Slice(page.Backlinks, func(i, j int) bool {
return strings.ToLower(page.Backlinks[i]) < strings.ToLower(page.Backlinks[j])
})
}
}

func AllPageTitles(pages map[string]*Page) []string {
Expand Down

0 comments on commit c665678

Please sign in to comment.