Skip to content

Commit

Permalink
Support Hugo shortcode comment style
Browse files Browse the repository at this point in the history
This will allow to drop the "autogenerated" comment when rendering the metrics
reference as a Hugo docs page.

Requested here:
cilium/tetragon#2164 (comment)

Signed-off-by: Anna Kapuscinska <[email protected]>
  • Loading branch information
lambdanis committed Mar 1, 2024
1 parent 71b3906 commit 540a7a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pkg/metricsmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

const (
HugoShortcodeCommentStyle CommentStyle = "hugo-shortcode"
)

type CommentStyle string

type LabelValues struct {
Label string
Values []string
Expand All @@ -24,4 +30,5 @@ type Config struct {
Targets map[string]string // cli argument -> docs header
LabelOverrides []LabelOverrides
InitMetrics func(target string, reg *prometheus.Registry, log *slog.Logger) error
CommentStyle CommentStyle
}
10 changes: 9 additions & 1 deletion pkg/metricsmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ func NewCmd(vp *viper.Viper, log *slog.Logger, config *Config) *cobra.Command {

var b bytes.Buffer
// Comment to inform people this file is autogenerated.
b.WriteString("<!-- This file is autogenerated via https://github.com/isovalent/metricstool -->\n\n")
switch config.CommentStyle {
case HugoShortcodeCommentStyle:
b.WriteString(`{{< comment >}}
This page is autogenerated via https://github.com/isovalent/metricstool,
please do not edit directly.
{{< /comment >}}`)
default:
b.WriteString("<!-- This file is autogenerated via https://github.com/isovalent/metricstool -->\n\n")
}
// Document title
b.WriteString(fmt.Sprintf("# %s Metrics\n\n", config.Targets[target]))
// Generate metrics reference
Expand Down

0 comments on commit 540a7a9

Please sign in to comment.