Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add "back to the top" button #2602

Merged
merged 2 commits into from
Feb 19, 2022
Merged
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
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