diff --git a/README.md b/README.md index 47acdd21..549e8e13 100644 --- a/README.md +++ b/README.md @@ -788,6 +788,7 @@ GLOBAL OPTIONS: --drop-h1, --h1_drop don't include the first H1 heading in Confluence output. (default: false) [$MARK_H1_DROP] --strip-linebreaks, -L remove linebreaks inside of tags, to accomodate non-standard Confluence behavior (default: false) [$MARK_STRIP_LINEBREAK] --title-from-h1, --h1_title extract page title from a leading H1 heading. If no H1 heading on a page exists, then title must be set in the page metadata. (default: false) [$MARK_H1_TITLE] + --title-append-generated-hash appends a short hash generated from the path of the page (space, parents, and title) to the title (default: false) [$MARK_TITLE_APPEND_GENERATED_HASH] --minor-edit don't send notifications while updating Confluence page. (default: false) [$MARK_MINOR_EDIT] --version-message value add a message to the page version, to explain the edit (default: "") [$MARK_VERSION_MESSAGE] --color value display logs in color. Possible values: auto, never. (default: "auto") [$MARK_COLOR] diff --git a/main.go b/main.go index ec70bc77..cca1ce43 100644 --- a/main.go +++ b/main.go @@ -81,6 +81,12 @@ var flags = []cli.Flag{ Usage: "extract page title from a leading H1 heading. If no H1 heading on a page exists, then title must be set in the page metadata.", EnvVars: []string{"MARK_H1_TITLE"}, }), + altsrc.NewBoolFlag(&cli.BoolFlag{ + Name: "title-append-generated-hash", + Value: false, + Usage: "appends a short hash generated from the path of the page (space, parents, and title) to the title", + EnvVars: []string{"MARK_TITLE_APPEND_GENERATED_HASH"}, + }), altsrc.NewBoolFlag(&cli.BoolFlag{ Name: "minor-edit", Value: false, @@ -309,7 +315,7 @@ func processFile( parents := strings.Split(cCtx.String("parents"), cCtx.String("parents-delimiter")) - meta, markdown, err := metadata.ExtractMeta(markdown, cCtx.String("space"), cCtx.Bool("title-from-h1"), parents) + meta, markdown, err := metadata.ExtractMeta(markdown, cCtx.String("space"), cCtx.Bool("title-from-h1"), parents, cCtx.Bool("title-append-generated-hash")) if err != nil { log.Fatal(err) } @@ -388,7 +394,7 @@ func processFile( } } - links, err := page.ResolveRelativeLinks(api, meta, markdown, filepath.Dir(file), cCtx.String("space"), cCtx.Bool("title-from-h1"), parents) + links, err := page.ResolveRelativeLinks(api, meta, markdown, filepath.Dir(file), cCtx.String("space"), cCtx.Bool("title-from-h1"), parents, cCtx.Bool("title-append-generated-hash")) if err != nil { log.Fatalf(err, "unable to resolve relative links") } diff --git a/metadata/metadata.go b/metadata/metadata.go index 0365f994..280a0746 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -3,6 +3,8 @@ package metadata import ( "bufio" "bytes" + "crypto/sha256" + "fmt" "regexp" "strings" @@ -44,7 +46,7 @@ var ( reHeaderPatternMacro = regexp.MustCompile(`