Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/v0.39.3/docs-anchor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changelog:
- type: FIX
issueLink: https://github.com/solo-io/doctopus/issues/124
resolvesIssue: true
description: >-
Fix a bug where headings on the same doc page have the same anchor and hence do not work. Numbers anchors for the same headings sequentially.
21 changes: 19 additions & 2 deletions pkg/code-generator/docgen/funcs/template_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,20 @@ func toHeading(docsOptions *options.DocsOptions) func(format string, p *string)
if docsOptions.Output == options.Hugo {
return printPointer
} else {
// Track anchor names to handle duplicates
anchorCounts := make(map[string]int)
//--> <a name="{{ printfptr "%v" .Name }}">{{ printfptr "%v" .Name }}</a>
return func(format string, p *string) string {
val := printPointer(format, p)
return "<a name=" + val + ">" + val + "</a>"
name := strings.ToLower(val)
anchorCounts[name]++
var anchorName string
if anchorCounts[name] > 1 {
anchorName = fmt.Sprintf("%s-%d", name, anchorCounts[name]-1)
} else {
anchorName = name
}
return "<a name=" + anchorName + ">" + val + "</a>"
}
}
}
Expand All @@ -149,8 +159,15 @@ func toAnchorLink(docsOptions *options.DocsOptions) func(format string, p *strin
if docsOptions.Output != options.Hugo {
return printPointer
} else {
// Track anchor names to handle duplicates
anchorCounts := make(map[string]int)
return func(format string, p *string) string {
return strings.ToLower(printPointer(format, p))
name := strings.ToLower(printPointer(format, p))
anchorCounts[name]++
if anchorCounts[name] > 1 {
return fmt.Sprintf("%s-%d", name, anchorCounts[name]-1)
}
return name
}
}
}
Expand Down