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
}
func loadBackrefs(fp *FilePages, p string) ([]Backref, error) {
func loadBackrefs(fp *FilePages, p string) (map[string][]Backref, error) {
refs := make(Refs)
p = strings.Replace(p, " ", "_", -1)
@ -82,11 +82,15 @@ func loadBackrefs(fp *FilePages, p string) ([]Backref, error) {
return nil, err
}
var result []Backref
result := make(map[string][]Backref)
for _, ref := range refs[p] {
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,
Title: title,
Line: strings.TrimLeft(ref.Link.Line, " *"),

View File

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

View File

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

View File

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