From 540a7a9572203a9a32736b84e89cc312661d2fb0 Mon Sep 17 00:00:00 2001 From: Anna Kapuscinska Date: Fri, 1 Mar 2024 00:13:16 +0000 Subject: [PATCH] Support Hugo shortcode comment style This will allow to drop the "autogenerated" comment when rendering the metrics reference as a Hugo docs page. Requested here: https://github.com/cilium/tetragon/pull/2164#discussion_r1507274583 Signed-off-by: Anna Kapuscinska --- pkg/metricsmd/config.go | 7 +++++++ pkg/metricsmd/print.go | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/metricsmd/config.go b/pkg/metricsmd/config.go index bc24e14..4b7be7d 100644 --- a/pkg/metricsmd/config.go +++ b/pkg/metricsmd/config.go @@ -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 @@ -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 } diff --git a/pkg/metricsmd/print.go b/pkg/metricsmd/print.go index b9794fe..b770a05 100644 --- a/pkg/metricsmd/print.go +++ b/pkg/metricsmd/print.go @@ -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("\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("\n\n") + } // Document title b.WriteString(fmt.Sprintf("# %s Metrics\n\n", config.Targets[target])) // Generate metrics reference