Skip to content

Commit

Permalink
use anchor link alias for TOC (#1298)
Browse files Browse the repository at this point in the history
* use anchor link alias for TOC in auto-generated helm docs code

Co-authored-by: Luke Kysow <[email protected]>
  • Loading branch information
kschoche and lkysow committed Jun 27, 2022
1 parent 9b7425a commit d3311e9
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 77 deletions.
52 changes: 26 additions & 26 deletions hack/helm-reference-gen/fixtures/full-values.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

Use these links to navigate to a particular top-level stanza.

- [`global`](#global)
- [`server`](#server)
- [`externalServers`](#externalservers)
- [`client`](#client)
- [`dns`](#dns)
- [`ui`](#ui)
- [`syncCatalog`](#synccatalog)
- [`connectInject`](#connectinject)
- [`controller`](#controller)
- [`meshGateway`](#meshgateway)
- [`ingressGateways`](#ingressgateways)
- [`terminatingGateways`](#terminatinggateways)
- [`tests`](#tests)
- [`global`](#h-global)
- [`server`](#h-server)
- [`externalServers`](#h-externalservers)
- [`client`](#h-client)
- [`dns`](#h-dns)
- [`ui`](#h-ui)
- [`syncCatalog`](#h-synccatalog)
- [`connectInject`](#h-connectinject)
- [`controller`](#h-controller)
- [`meshGateway`](#h-meshgateway)
- [`ingressGateways`](#h-ingressgateways)
- [`terminatingGateways`](#h-terminatinggateways)
- [`tests`](#h-tests)

## All Values

### global
### global ((#h-global))

- `global` ((#v-global)) - Holds values that affect multiple components of the chart.

Expand Down Expand Up @@ -245,7 +245,7 @@ Use these links to navigate to a particular top-level stanza.
- `enabled` ((#v-global-openshift-enabled)) (`boolean: false`) - If true, the Helm chart will create necessary configuration for running
its components on OpenShift.

### server
### server ((#h-server))

- `server` ((#v-server)) - Server, when enabled, configures a server cluster to run. This should
be disabled if you plan on connecting to a Consul cluster external to
Expand Down Expand Up @@ -459,7 +459,7 @@ Use these links to navigate to a particular top-level stanza.
feature, in case kubernetes cluster is behind egress http proxies. Additionally,
it could be used to configure custom consul parameters.

### externalServers
### externalServers ((#h-externalservers))

- `externalServers` ((#v-externalservers)) - Configuration for Consul servers when the servers are running outside of Kubernetes.
When running external servers, configuring these values is recommended
Expand Down Expand Up @@ -503,7 +503,7 @@ Use these links to navigate to a particular top-level stanza.
-o jsonpath="{.clusters[?(@.name=='<your cluster name>')].cluster.server}"
```

### client
### client ((#h-client))

- `client` ((#v-client)) - Values that configure running a Consul client on Kubernetes nodes.

Expand Down Expand Up @@ -712,7 +712,7 @@ Use these links to navigate to a particular top-level stanza.
...
```

### dns
### dns ((#h-dns))

- `dns` ((#v-dns)) - Configuration for DNS configuration within the Kubernetes cluster.
This creates a service that routes to all agents (client or server)
Expand All @@ -739,7 +739,7 @@ Use these links to navigate to a particular top-level stanza.
This should be a multi-line string mapping directly to a Kubernetes
ServiceSpec object.

### ui
### ui ((#h-ui))

- `ui` ((#v-ui)) - Values that configure the Consul UI.

Expand Down Expand Up @@ -773,7 +773,7 @@ Use these links to navigate to a particular top-level stanza.
This should be a multi-line string mapping directly to a Kubernetes
ServiceSpec object.

### syncCatalog
### syncCatalog ((#h-synccatalog))

- `syncCatalog` ((#v-synccatalog)) - syncCatalog will run the catalog sync process to sync K8S with Consul
services. This can run bidirectional (default) or unidirectionally (Consul
Expand Down Expand Up @@ -938,7 +938,7 @@ Use these links to navigate to a particular top-level stanza.

- `consulWriteInterval` ((#v-synccatalog-consulwriteinterval)) (`string: null`) - Override the default interval to perform syncing operations creating Consul services.

### connectInject
### connectInject ((#h-connectinject))

- `connectInject` ((#v-connectinject)) - ConnectInject will enable the automatic Connect sidecar injector.

Expand Down Expand Up @@ -1170,7 +1170,7 @@ Use these links to navigate to a particular top-level stanza.

- `cpu` ((#v-connectinject-initcontainer-resources-limits-cpu)) (`string: 50m`)

### controller
### controller ((#h-controller))

- `controller` ((#v-controller)) - Controller handles config entry custom resources.
Requires consul >= 1.8.4.
Expand Down Expand Up @@ -1205,7 +1205,7 @@ Use these links to navigate to a particular top-level stanza.

- `priorityClassName` ((#v-controller-priorityclassname)) (`string: ""`) - Optional priorityClassName.

### meshGateway
### meshGateway ((#h-meshgateway))

- `meshGateway` ((#v-meshgateway)) - Mesh Gateways enable Consul Connect to work across Consul datacenters.

Expand Down Expand Up @@ -1354,7 +1354,7 @@ Use these links to navigate to a particular top-level stanza.
"annotation-key": "annotation-value"
```

### ingressGateways
### ingressGateways ((#h-ingressgateways))

- `ingressGateways` ((#v-ingressgateways)) - Configuration options for ingress gateways. Default values for all
ingress gateways are defined in `ingressGateways.defaults`. Any of
Expand Down Expand Up @@ -1460,7 +1460,7 @@ Use these links to navigate to a particular top-level stanza.

- `name` ((#v-ingressgateways-gateways-name)) (`string: ingress-gateway`)

### terminatingGateways
### terminatingGateways ((#h-terminatinggateways))

- `terminatingGateways` ((#v-terminatinggateways)) - Configuration options for terminating gateways. Default values for all
terminating gateways are defined in `terminatingGateways.defaults`. Any of
Expand Down Expand Up @@ -1555,7 +1555,7 @@ Use these links to navigate to a particular top-level stanza.

- `name` ((#v-terminatinggateways-gateways-name)) (`string: terminating-gateway`)

### tests
### tests ((#h-tests))

- `tests` ((#v-tests)) - Control whether a test Pod manifest is generated when running helm template.
When using helm install, the test Pod is not submitted to the cluster so this
Expand Down
10 changes: 7 additions & 3 deletions hack/helm-reference-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ var (
// And will not match the "# yaml comment" incorrectly.
commentPrefix = regexp.MustCompile(`(?m)^[^\S\n]*#[^\S\n]?`)

funcMap = template.FuncMap{
"ToLower": strings.ToLower,
}

// docNodeTmpl is the go template used to print a DocNode node.
// We use $ instead of ` in the template so we can use the golang raw string
// format. We then do the replace from $ => `.
docNodeTmpl = template.Must(
template.New("").Parse(
template.New("").Funcs(funcMap).Parse(
strings.Replace(
`{{- if eq .Column 1 }}### {{ .Key }}
`{{- if eq .Column 1 }}### {{ .Key }} ((#h-{{ .Key | ToLower }}))
{{ end }}{{ .LeadingIndent }}- ${{ .Key }}$ ((#v{{ .HTMLAnchor }})){{ if ne .FormattedKind "" }} (${{ .FormattedKind }}{{ if .FormattedDefault }}: {{ .FormattedDefault }}{{ end }}$){{ end }}{{ if .FormattedDocumentation}} - {{ .FormattedDocumentation }}{{ end }}`,
"$", "`", -1)),
Expand Down Expand Up @@ -407,7 +411,7 @@ func generateTOC(node DocNode) string {
toc := tocPrefix

for _, c := range node.Children {
toc += fmt.Sprintf("- [`%s`](#%s)\n", c.Key, strings.ToLower(c.Key))
toc += fmt.Sprintf("- [`%s`](#h-%s)\n", c.Key, strings.ToLower(c.Key))
}

return toc + tocSuffix
Expand Down
Loading

0 comments on commit d3311e9

Please sign in to comment.