Skip to content

Commit 926bf50

Browse files
committed
Add latest version column to function catalog documentation
Signed-off-by: Aravindhan Ayyanathan <[email protected]>
1 parent 5a41d88 commit 926bf50

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ $ go install github.com/monopole/[email protected]
164164

165165
And you need to ensure `$GOPATH/bin` is in your `PATH`.
166166

167+
### Documentation
168+
169+
For details on running the documentation site locally, refer to the
170+
[documentation README](documentation/README.md).
171+
167172
### Change Existing Functions
168173

169174
You must follow the layout convention when you make changes to existing

documentation/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ npm install
2626
Then run the site using `npm run serve`. To have the site run locally with a functioning local search, run
2727
`npm run serve:with-pagefind`.
2828

29+
## API Token for Version Fetching
30+
31+
The documentation site fetches the latest release versions of KRM functions from
32+
the GitHub API. To avoid rate limiting, set the `KRM_CATALOG_API_TOKEN`
33+
environment variable with a GitHub personal access token (no scopes required for
34+
public repos).
35+
36+
- **Locally:** `export KRM_CATALOG_API_TOKEN=<your-token>` before running `make serve`.
37+
- **Netlify:** Set `KRM_CATALOG_API_TOKEN` in the site's environment variables via the Netlify UI.
38+
39+
The token is optional. Without it, unauthenticated API requests are subject to
40+
lower rate limits, which may cause version information to be unavailable during
41+
builds.
42+
2943
## License
3044

3145
Licensed under the [Creative Commons Attribution 4.0 International license](LICENSE-documentation)

documentation/config.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,8 @@ enable = false
190190
[[menu.main]]
191191
name = "Guides"
192192
url = "https://kpt.dev/guides/"
193-
weight = 40
193+
weight = 40
194+
195+
[security]
196+
[security.funcs]
197+
getenv = ['^HUGO_', '^CI$', '^KRM_CATALOG_API_TOKEN$']

documentation/layouts/shortcodes/listfunctions.html

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,55 @@
33

44
{{ $files := readDir $currentDir }}
55

6+
<!-- Fetch latest version per function using git matching-refs API (one call per function) -->
7+
{{ $latestVersions := dict }}
8+
{{ $releaseTags := dict }}
9+
{{ $token := getenv "KRM_CATALOG_API_TOKEN" }}
10+
{{ range $files }}
11+
{{ if .IsDir }}
12+
{{ if ne .Name "examples" }}
13+
{{ $fnName := .Name }}
14+
{{ $apiURL := printf "https://api.github.com/repos/kptdev/krm-functions-catalog/git/matching-refs/tags/functions/go/%s/v" $fnName }}
15+
{{ $opts := cond (ne $token "") (dict "headers" (dict "Authorization" (printf "token %s" $token))) (dict) }}
16+
{{ with resources.GetRemote $apiURL $opts }}
17+
{{ $refs := . | transform.Unmarshal }}
18+
{{ if gt (len $refs) 0 }}
19+
{{ $bestRef := "" }}
20+
{{ $bestMajor := 0 }}
21+
{{ $bestMinor := 0 }}
22+
{{ $bestPatch := 0 }}
23+
{{ range $refs }}
24+
{{ $v := .ref | replaceRE "^.*/v" "" }}
25+
{{ $parts := split $v "." }}
26+
{{ if ge (len $parts) 3 }}
27+
{{ $maj := index $parts 0 | int }}
28+
{{ $min := index $parts 1 | int }}
29+
{{ $pat := index $parts 2 | int }}
30+
{{ if or (gt $maj $bestMajor) (and (eq $maj $bestMajor) (gt $min $bestMinor)) (and (eq $maj $bestMajor) (eq $min $bestMinor) (gt $pat $bestPatch)) }}
31+
{{ $bestRef = .ref }}
32+
{{ $bestMajor = $maj }}
33+
{{ $bestMinor = $min }}
34+
{{ $bestPatch = $pat }}
35+
{{ end }}
36+
{{ end }}
37+
{{ end }}
38+
{{ if $bestRef }}
39+
{{ $tag := $bestRef | replaceRE "^refs/tags/" "" }}
40+
{{ $version := $tag | replaceRE "^.*/v" "v" }}
41+
{{ $latestVersions = merge $latestVersions (dict $fnName $version) }}
42+
{{ $releaseTags = merge $releaseTags (dict $fnName $tag) }}
43+
{{ end }}
44+
{{ end }}
45+
{{ end }}
46+
{{ end }}
47+
{{ end }}
48+
{{ end }}
49+
650
<table class="table table-striped">
751
<thead>
852
<tr>
953
<th>Function</th>
54+
<th>Latest Version</th>
1055
<th>Description</th>
1156
<th>Tags</th>
1257
</tr>
@@ -65,6 +110,13 @@
65110
<a href="{{ printf "%s/%s/" $functionName $highestVersion }}">{{ .Title }}</a>
66111
{{ end }}
67112
</td>
113+
<td>
114+
{{ $ver := index $latestVersions $functionName }}
115+
{{ $tag := index $releaseTags $functionName }}
116+
{{ if $ver }}
117+
<a href="https://github.com/kptdev/krm-functions-catalog/releases/tag/{{ $tag }}">{{ $ver }}</a>
118+
{{ else }}—{{ end }}
119+
</td>
68120
<td>{{ .Params.description | markdownify }}</td>
69121
<td>
70122
{{ if .Params.tags }}
@@ -79,6 +131,13 @@
79131
{{ $title := .Name | replaceRE "\\.[^.]+$" "" }}
80132
<tr>
81133
<td><a href="{{ printf "%s" .Name }}">{{ $title }}</a></td>
134+
<td>
135+
{{ $ver := index $latestVersions .Name }}
136+
{{ $tag := index $releaseTags .Name }}
137+
{{ if $ver }}
138+
<a href="https://github.com/kptdev/krm-functions-catalog/releases/tag/{{ $tag }}">{{ $ver }}</a>
139+
{{ else }}—{{ end }}
140+
</td>
82141
<td>No description available</td>
83142
<td></td>
84143
</tr>

0 commit comments

Comments
 (0)