Skip to content
Open
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
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ $ go install github.com/monopole/mdrip@v1.0.2

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

### Documentation

For details on running the documentation site locally, refer to the
[documentation README](documentation/README.md).

### Change Existing Functions

You must follow the layout convention when you make changes to existing
Expand Down
14 changes: 14 additions & 0 deletions documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ npm install
Then run the site using `npm run serve`. To have the site run locally with a functioning local search, run
`npm run serve:with-pagefind`.

## API Token for Version Fetching

The documentation site fetches the latest release versions of KRM functions from
the GitHub API. To avoid rate limiting, set the `KRM_CATALOG_API_TOKEN`
environment variable with a GitHub personal access token (no scopes required for
public repos).

- **Locally:** `export KRM_CATALOG_API_TOKEN=<your-token>` before running `npm run serve`.
- **Netlify:** Set `KRM_CATALOG_API_TOKEN` in the site's environment variables via the Netlify UI.

The token is optional. Without it, unauthenticated API requests are subject to
lower rate limits, which may cause version information to be unavailable during
builds.

## License

Licensed under the [Creative Commons Attribution 4.0 International license](LICENSE-documentation)
Expand Down
6 changes: 5 additions & 1 deletion documentation/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,8 @@ enable = false
[[menu.main]]
name = "Guides"
url = "https://kpt.dev/guides/"
weight = 40
weight = 40

[security]
[security.funcs]
getenv = ['^HUGO_', '^CI$', '^KRM_CATALOG_API_TOKEN$']
61 changes: 61 additions & 0 deletions documentation/layouts/shortcodes/listfunctions.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,57 @@

{{ $files := readDir $currentDir }}

<!-- Fetch all function release tags -->
{{ $latestVersions := dict }}
{{ $releaseTags := dict }}
{{ $token := getenv "KRM_CATALOG_API_TOKEN" }}
{{ $apiURL := "https://api.github.com/repos/kptdev/krm-functions-catalog/git/matching-refs/tags/functions/go/" }}
{{ $apiHeaders := dict "Accept" "application/vnd.github+json" "X-GitHub-Api-Version" "2026-03-10" }}
{{ if ne $token "" }}
{{ $apiHeaders = merge $apiHeaders (dict "Authorization" (printf "Bearer %s" $token)) }}
{{ end }}
{{ $opts := dict "headers" $apiHeaders }}
{{ with resources.GetRemote $apiURL $opts }}
{{ $refs := . | transform.Unmarshal }}
{{ if and (reflect.IsSlice $refs) (gt (len $refs) 0) }}
{{ range $refs }}
{{ $tag := .ref | replaceRE "^refs/tags/functions/go/" "" }}
{{ $parts := split $tag "/" }}
{{ if eq (len $parts) 2 }}
{{ $fnName := index $parts 0 }}
{{ $v := index $parts 1 | replaceRE "^v" "" | replaceRE "[-+].*" "" }}
{{ $semver := split $v "." }}
{{ if ge (len $semver) 3 }}
{{ $maj := index $semver 0 | int }}
{{ $min := index $semver 1 | int }}
{{ $pat := index $semver 2 | int }}
{{ $curVer := index $latestVersions $fnName }}
{{ $isBetter := true }}
{{ if $curVer }}
{{ $curV := $curVer | replaceRE "^v" "" | replaceRE "[-+].*" "" }}
{{ $curParts := split $curV "." }}
{{ $curMaj := index $curParts 0 | int }}
{{ $curMin := index $curParts 1 | int }}
{{ $curPat := index $curParts 2 | int }}
{{ $isBetter = or (gt $maj $curMaj) (and (eq $maj $curMaj) (gt $min $curMin)) (and (eq $maj $curMaj) (eq $min $curMin) (gt $pat $curPat)) }}
{{ end }}
{{ if $isBetter }}
{{ $version := index $parts 1 }}
{{ $fullTag := printf "functions/go/%s/%s" $fnName $version }}
{{ $latestVersions = merge $latestVersions (dict $fnName $version) }}
{{ $releaseTags = merge $releaseTags (dict $fnName $fullTag) }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}

<table class="table table-striped">
<thead>
<tr>
<th>Function</th>
<th>Latest Version</th>
<th>Description</th>
<th>Tags</th>
</tr>
Expand Down Expand Up @@ -65,6 +112,13 @@
<a href="{{ printf "%s/%s/" $functionName $highestVersion }}">{{ .Title }}</a>
{{ end }}
</td>
<td>
{{ $ver := index $latestVersions $functionName }}
{{ $tag := index $releaseTags $functionName }}
{{ if $ver }}
<a href="https://github.com/kptdev/krm-functions-catalog/releases/tag/{{ $tag }}">{{ $ver }}</a>
{{ else }}—{{ end }}
</td>
<td>{{ .Params.description | markdownify }}</td>
<td>
{{ if .Params.tags }}
Expand All @@ -79,6 +133,13 @@
{{ $title := .Name | replaceRE "\\.[^.]+$" "" }}
<tr>
<td><a href="{{ printf "%s" .Name }}">{{ $title }}</a></td>
<td>
{{ $ver := index $latestVersions .Name }}
{{ $tag := index $releaseTags .Name }}
{{ if $ver }}
<a href="https://github.com/kptdev/krm-functions-catalog/releases/tag/{{ $tag }}">{{ $ver }}</a>
{{ else }}—{{ end }}
</td>
<td>No description available</td>
<td></td>
</tr>
Expand Down
Loading