Skip to content

Commit

Permalink
docs: add "back to the top" button (golangci#2602)
Browse files Browse the repository at this point in the history
* feat: use non-breaking space
* feat: add back on top button
  • Loading branch information
ldez authored and SeigeC committed Apr 4, 2023
1 parent 3d3bf5c commit 21cf52c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions scripts/expand_website_templates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/golangci/golangci-lint/pkg/lint/lintersdb"
)

const listItemPrefix = "list-item-"

var stateFilePath = filepath.Join("docs", "template_data.state")

func main() {
Expand Down Expand Up @@ -257,7 +259,7 @@ func getName(lc *linter.Config) string {
}

if hasSettings(lc.Name()) {
name = fmt.Sprintf("%s [%s](#%s)", name, span("Configuration", "⚙️"), lc.Name())
name = fmt.Sprintf("%s [%s](#%s)", name, spanWithID(listItemPrefix+lc.Name(), "Configuration", "⚙️"), lc.Name())
}

if !lc.IsDeprecated() {
Expand All @@ -269,7 +271,7 @@ func getName(lc *linter.Config) string {
title += fmt.Sprintf(" since %s", lc.Deprecation.Since)
}

return name + " " + span(title, "⚠")
return name + " " + span(title, "⚠")
}

func getDesc(lc *linter.Config) string {
Expand Down Expand Up @@ -307,6 +309,10 @@ func span(title, icon string) string {
return fmt.Sprintf(`<span title=%q>%s</span>`, title, icon)
}

func spanWithID(id, title, icon string) string {
return fmt.Sprintf(`<span id=%q title=%q>%s</span>`, id, title, icon)
}

func getThanksList() string {
var lines []string
addedAuthors := map[string]bool{}
Expand Down Expand Up @@ -472,6 +478,8 @@ func getLintersSettingSnippets(node, nextNode *yaml.Node) (string, error) {

_, _ = fmt.Fprintln(builder, "```")
_, _ = fmt.Fprintln(builder)
_, _ = fmt.Fprintf(builder, "[%s](#%s)\n\n", span("Back to the top", "🔼"), listItemPrefix+nextNode.Content[i].Value)
_, _ = fmt.Fprintln(builder)
}

return builder.String(), nil
Expand Down

0 comments on commit 21cf52c

Please sign in to comment.