Skip to content

Commit 0cdb64f

Browse files
committed
feat: item cards shortcode
1 parent 8bcb458 commit 0cdb64f

File tree

6 files changed

+135
-3
lines changed

6 files changed

+135
-3
lines changed

docs/content/docs/formatters/_index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ golangci-lint formatters
2525

2626
## All formatters
2727

28-
{.Formatters}
28+
{{< cards >}}
29+
{{< item-cards path="formatters" data="formatters_info" >}}
30+
{{< /cards >}}

docs/content/docs/linters/_index.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ golangci-lint linters
2525

2626
## Enabled by Default
2727

28-
{.EnabledByDefaultLinters}
28+
{{< cards >}}
29+
{{< item-cards path="linters" data="linters_info" group="standard" >}}
30+
{{< /cards >}}
2931

3032
## Disabled by Default
3133

32-
{.DisabledByDefaultLinters}
34+
{{< cards >}}
35+
{{< item-cards path="linters" data="linters_info" group="!standard" >}}
36+
{{< /cards >}}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{- /*
2+
Compares two versions.
3+
4+
@param {string} a Version A
5+
@param {string} b Version B
6+
@returns {boolean}
7+
8+
@example {{ partial "compare-versions.html" (dict "a" "v1.2.3" "b" "v1.2.4") }}
9+
*/ -}}
10+
11+
{{- $aVersion := path.Dir (replace .a "." "/") -}}
12+
{{- $bVersion := path.Dir (replace .b "." "/") -}}
13+
14+
{{- return (eq $aVersion $bVersion) -}}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- /*
2+
Formats a item (linter/formatter) description.
3+
4+
@param {string} (positional parameter 0) Description
5+
@returns {string}
6+
7+
@example {{ partial "format-description" "message" }}
8+
*/ -}}
9+
10+
{{- $desc := . -}}
11+
{{- $desc = strings.FirstUpper $desc -}}
12+
{{- if not (hasSuffix $desc ".") -}}
13+
{{- $desc = print $desc "." -}}
14+
{{- end -}}
15+
{{- return $desc -}}

docs/layouts/_partials/item-tag.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{- /*
2+
Creates tag information for an item (linter/formatter).
3+
4+
@param {string} (positional parameter 0) Description
5+
@returns {map[tag: string, tagType: string]}
6+
7+
@example {{ partial "item-tag.html" (dict "gcilVersion" "v1.2.3" "item" .) }}
8+
*/ -}}
9+
10+
{{- $gcilVersion := .gcilVersion -}}
11+
{{- $item := .item -}}
12+
13+
{{- $tag := newScratch -}}
14+
15+
{{- if $item.deprecation -}}
16+
{{- $replacement := "" -}}
17+
{{- if $item.deprecation.replacement -}}
18+
{{- $replacement = print " Use `" $item.deprecation.replacement "` instead." -}}
19+
{{- end -}}
20+
21+
{{- $tag.SetInMap "options" "subtitle" (print (strings.FirstUpper $item.deprecation.message) $replacement) -}}
22+
{{- $tag.SetInMap "options" "tag" (print "Deprecated since " $item.deprecation.since) -}}
23+
{{- $tag.SetInMap "options" "tagType" "error" -}}
24+
{{- else if (partial "compare-versions.html" (dict "a" $gcilVersion "b" $item.since)) -}}
25+
{{- $tag.SetInMap "options" "tag" "New" -}}
26+
{{- $tag.SetInMap "options" "tagType" "warning" -}}
27+
{{- else if $item.canAutoFix -}}
28+
{{- $tag.SetInMap "options" "tag" "Autofix" -}}
29+
{{- $tag.SetInMap "options" "tagType" "info" -}}
30+
{{- end -}}
31+
32+
{{- return ($tag.Get "options") -}}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{{- /*
2+
Creates a card for each item (linter/formatter) in a data file.
3+
4+
@param {string} data The name of the data file.
5+
@param {string} path The path to the data file.
6+
@param {string} group The group to filter items by (use the prefix `!` to exclude items from the group).
7+
@returns {string}
8+
9+
@example {{< item-cards path="formatters" data="formatters_info" >}}
10+
@example {{< item-cards path="linters" data="linters_info" group="!standard" >}}
11+
*/ -}}
12+
13+
{{- $file := .Get "data" -}}
14+
{{- $path := .Get "path" -}}
15+
{{- $group := .Get "group" | default "" -}}
16+
17+
{{- $info := index $.Site.Data $file -}}
18+
19+
{{- /* Determine if we should exclude items from the group */ -}}
20+
{{- $notInGroup := hasPrefix $group "!" -}}
21+
{{- if $notInGroup -}}
22+
{{- $group = strings.TrimPrefix "!" $group -}}
23+
{{- end -}}
24+
25+
{{- /* Filter items by group */ -}}
26+
{{ $items := slice }}
27+
{{- range sort $info "name" -}}
28+
{{- if $group -}}
29+
{{- if in .groups $group -}}
30+
{{- if not $notInGroup -}}
31+
{{- $items = $items | append . -}}
32+
{{- end -}}
33+
{{- else -}}
34+
{{- if $notInGroup -}}
35+
{{- $items = $items | append . -}}
36+
{{- end -}}
37+
{{- end -}}
38+
{{- else -}}
39+
{{- $items = $items | append . -}}
40+
{{- end -}}
41+
{{- end -}}
42+
43+
{{- $gcilVersion := index $.Site.Data.version.version -}}
44+
45+
{{- /* Create cards */ -}}
46+
{{- range $items -}}
47+
{{- if .internal -}}
48+
{{- continue -}}
49+
{{- end -}}
50+
51+
{{- $s := newScratch -}}
52+
{{- $s.SetInMap "options" "page" .Page -}}
53+
{{- $s.SetInMap "options" "link" (print "/docs/" $path "/configuration/#" .name) -}}
54+
{{- $s.SetInMap "options" "title" .name -}}
55+
{{- $s.SetInMap "options" "subtitle" (partial "format-description" .desc) -}}
56+
57+
{{- /* Create tag information */ -}}
58+
{{- $tagOptions := partial "item-tag.html" (dict "gcilVersion" $gcilVersion "item" .) -}}
59+
{{- range $k, $v := $tagOptions -}}
60+
{{- $s.SetInMap "options" $k $v -}}
61+
{{- end -}}
62+
63+
{{- partial "shortcodes/card" ($s.Get "options") -}}
64+
65+
{{- end -}}

0 commit comments

Comments
 (0)