commands: Remove all dates from gendoc

It creates lots of diffs even if there are no changes.
This commit is contained in:
Bjørn Erik Pedersen 2021-05-01 12:03:56 +02:00
parent d7b22aee46
commit 4227cc1bd3
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F

View file

@ -18,7 +18,6 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
"github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/hugofs"
@ -36,7 +35,6 @@ type genDocCmd struct {
func newGenDocCmd() *genDocCmd { func newGenDocCmd() *genDocCmd {
const gendocFrontmatterTemplate = `--- const gendocFrontmatterTemplate = `---
date: %s
title: "%s" title: "%s"
slug: %s slug: %s
url: %s url: %s
@ -57,6 +55,12 @@ It creates one Markdown file per command with front matter suitable
for rendering in Hugo.`, for rendering in Hugo.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
cmd.VisitParents(func(c *cobra.Command) {
// Disable the "Auto generated by spf13/cobra on DATE"
// as it creates a lot of diffs.
c.DisableAutoGenTag = true
})
if !strings.HasSuffix(cc.gendocdir, helpers.FilePathSeparator) { if !strings.HasSuffix(cc.gendocdir, helpers.FilePathSeparator) {
cc.gendocdir += helpers.FilePathSeparator cc.gendocdir += helpers.FilePathSeparator
} }
@ -66,19 +70,17 @@ for rendering in Hugo.`,
return err return err
} }
} }
now := time.Now().Format("2006-01-02")
prepender := func(filename string) string { prepender := func(filename string) string {
name := filepath.Base(filename) name := filepath.Base(filename)
base := strings.TrimSuffix(name, path.Ext(name)) base := strings.TrimSuffix(name, path.Ext(name))
url := "/commands/" + strings.ToLower(base) + "/" url := "/commands/" + strings.ToLower(base) + "/"
return fmt.Sprintf(gendocFrontmatterTemplate, now, strings.Replace(base, "_", " ", -1), base, url) return fmt.Sprintf(gendocFrontmatterTemplate, strings.Replace(base, "_", " ", -1), base, url)
} }
linkHandler := func(name string) string { linkHandler := func(name string) string {
base := strings.TrimSuffix(name, path.Ext(name)) base := strings.TrimSuffix(name, path.Ext(name))
return "/commands/" + strings.ToLower(base) + "/" return "/commands/" + strings.ToLower(base) + "/"
} }
jww.FEEDBACK.Println("Generating Hugo command-line documentation in", cc.gendocdir, "...") jww.FEEDBACK.Println("Generating Hugo command-line documentation in", cc.gendocdir, "...")
doc.GenMarkdownTreeCustom(cmd.Root(), cc.gendocdir, prepender, linkHandler) doc.GenMarkdownTreeCustom(cmd.Root(), cc.gendocdir, prepender, linkHandler)
jww.FEEDBACK.Println("Done.") jww.FEEDBACK.Println("Done.")