Groups lines from pages in backrefs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Peter Stuifzand 2020-05-16 22:27:48 +02:00
parent 465ebcb8cb
commit 0380238e00
4 changed files with 20 additions and 12 deletions

View File

@ -66,7 +66,7 @@ func processBackrefs(fp *FilePages) error {
return err return err
} }
func loadBackrefs(fp *FilePages, p string) ([]Backref, error) { func loadBackrefs(fp *FilePages, p string) (map[string][]Backref, error) {
refs := make(Refs) refs := make(Refs)
p = strings.Replace(p, " ", "_", -1) p = strings.Replace(p, " ", "_", -1)
@ -82,11 +82,15 @@ func loadBackrefs(fp *FilePages, p string) ([]Backref, error) {
return nil, err return nil, err
} }
var result []Backref result := make(map[string][]Backref)
for _, ref := range refs[p] { for _, ref := range refs[p] {
title := strings.Replace(ref.Name, "_", " ", -1) title := strings.Replace(ref.Name, "_", " ", -1)
result = append(result, Backref{ if _, e := result[ref.Name]; !e {
result[ref.Name] = nil
}
result[ref.Name] = append(result[ref.Name], Backref{
Name: ref.Name, Name: ref.Name,
Title: title, Title: title,
Line: strings.TrimLeft(ref.Link.Line, " *"), Line: strings.TrimLeft(ref.Link.Line, " *"),

View File

@ -47,7 +47,7 @@ type Page struct {
Content string Content string
Refs []Backref Refs map[string][]Backref
} }
type DiffPage struct { type DiffPage struct {
@ -85,7 +85,7 @@ type indexPage struct {
Title string Title string
Name string Name string
Content template.HTML Content template.HTML
Backrefs []Backref Backrefs map[string][]Backref
} }
type editPage struct { type editPage struct {
@ -94,7 +94,7 @@ type editPage struct {
Content string Content string
Name string Name string
Editor template.HTML Editor template.HTML
Backrefs []Backref Backrefs map[string][]Backref
} }
type historyPage struct { type historyPage struct {

View File

@ -13,10 +13,12 @@
<div class="backrefs content"> <div class="backrefs content">
<h3>Linked references</h3> <h3>Linked references</h3>
<ul> <ul>
{{ range $ref := .Backrefs }} {{ range $name, $refs := .Backrefs }}
<li><a href="/{{ $ref.Name }}">{{ $ref.Title }}</a> <li><a href="/{{ $name }}">{{ (index $refs 0).Title }}</a>
<ul> <ul>
<li>{{ $ref.Line }}</li> {{ range $ref := $refs }}
<li>{{ $ref.Line }}</li>
{{ end }}
</ul> </ul>
</li> </li>
{{ end }} {{ end }}

View File

@ -7,10 +7,12 @@
<div class="backrefs content"> <div class="backrefs content">
<h3>Backrefs</h3> <h3>Backrefs</h3>
<ul> <ul>
{{ range $ref := .Backrefs }} {{ range $name, $refs := .Backrefs }}
<li><a href="/{{ $ref.Name }}">{{ $ref.Title }}</a> <li><a href="/{{ $name }}">{{ $name }}</a>
<ul> <ul>
<li>{{ $ref.Line }}</li> {{ range $ref := $refs }}
<li>{{ $ref.Line }}</li>
{{ end }}
</ul> </ul>
</li> </li>
{{ end }} {{ end }}