diff --git a/.ci/build b/.ci/build index 51ead38a..309a840e 100755 --- a/.ci/build +++ b/.ci/build @@ -34,8 +34,7 @@ cd ${SOURCE_PATH} ############################################################################### EFFECTIVE_VERSION_FILE="${VERSION_PATH}/version" -if [[ -f ${EFFECTIVE_VERSION_FILE} ]] -then +if [[ -f ${EFFECTIVE_VERSION_FILE} ]]; then VERSION_FILE="${EFFECTIVE_VERSION_FILE}" else VERSION_FILE="$(${READLINK_BIN} -f "${SOURCE_PATH}/VERSION")" @@ -74,5 +73,6 @@ else go build \ -v \ -o ${BINARY_PATH}/docforge \ + -ldflags "-w -X github.com/gardener/docforge/pkg/version.Version=$(git rev-parse HEAD)" \ cmd/*.go fi diff --git a/pkg/processors/frontmatter.go b/pkg/processors/frontmatter.go index 17b0d3f6..6676d80f 100644 --- a/pkg/processors/frontmatter.go +++ b/pkg/processors/frontmatter.go @@ -5,8 +5,6 @@ package processors import ( - "bytes" - "io/ioutil" "strings" "github.com/gardener/docforge/pkg/markdown" @@ -25,6 +23,7 @@ func (f *FrontMatter) Process(documentBlob []byte, node *api.Node) ([]byte, erro nodeFmBytes, fmBytes, content []byte props, fm, docFm map[string]interface{} ok bool + err error ) // Frontmatter from node if props = node.Properties; props == nil { @@ -45,11 +44,6 @@ func (f *FrontMatter) Process(documentBlob []byte, node *api.Node) ([]byte, erro } } - nodeFmBytes, err := yaml.Marshal(fm) - if err != nil { - return nil, err - } - // document front matter if fmBytes, content, err = markdown.StripFrontMatter(documentBlob); err != nil { return nil, err @@ -59,21 +53,22 @@ func (f *FrontMatter) Process(documentBlob []byte, node *api.Node) ([]byte, erro return nil, err } + for propertyKey, propertyValue := range docFm { + if _, ok := fm[propertyKey]; !ok { + fm[propertyKey] = propertyValue + } + } + + nodeFmBytes, err = yaml.Marshal(fm) + if err != nil { + return nil, err + } + // TODO: merge node + doc frontmatter per configurable strategy: // - merge where node frontmatter entries win over document frontmatter // - merge where document frontmatter entries win over node frontmatter // - merge where document frontmatter are merged with node frontmatter ignoring duplicates (currently impl.) - buf := bytes.NewBuffer([]byte{}) - if fmBytes != nil { - buf.Write(fmBytes) - } - if nodeFmBytes != nil { - buf.Write(nodeFmBytes) - } - if fmBytes, err = ioutil.ReadAll(buf); err != nil { - return nil, err - } - if documentBlob, err = markdown.InsertFrontMatter(fmBytes, content); err != nil { + if documentBlob, err = markdown.InsertFrontMatter(nodeFmBytes, content); err != nil { return nil, err } return documentBlob, nil diff --git a/pkg/processors/frontmatter_test.go b/pkg/processors/frontmatter_test.go index a70754d0..e0dd5cfb 100644 --- a/pkg/processors/frontmatter_test.go +++ b/pkg/processors/frontmatter_test.go @@ -81,7 +81,6 @@ title: Test1 }, wantErr: nil, wantDocument: `--- -title: Test1 title: Test2 --- `,