Skip to content

Commit

Permalink
Implement request changes
Browse files Browse the repository at this point in the history
Signed-off-by: Saswata Mukherjee <[email protected]>
  • Loading branch information
saswatamcode committed Mar 6, 2021
1 parent 92d712c commit 6a56309
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pkg/mdformatter/mdformatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,26 @@ func (FormatFrontMatter) TransformFrontMatter(_ SourceContext, frontMatter map[s

b := bytes.NewBuffer([]byte("---"))
for _, k := range keys {
// check if frontMatter[k] is a map
// Check if frontMatter[k] is a map.
frontMatterStr := fmt.Sprintf("%s", frontMatter[k])
isMap := strings.HasPrefix(frontMatterStr, "map[")

// split string to get all key-value pairs
_, isMap := frontMatter[k].(map[string]interface{})
// Split string to get all key-value pairs.
if isMap {
_, _ = fmt.Fprintf(b, "\n%v:", k)
pairs := strings.Split(frontMatterStr[4:len(frontMatterStr)-1], " ")
pair := make([]string, 2)
// ignore spaces in values
// Ignore spaces in values.
for _, val := range pairs {
if strings.Contains(val, ":") {
pair = strings.Split(val, ":")
_, _ = fmt.Fprintf(b, "\n %v: %v", pair[0], pair[1])
} else {
_, _ = fmt.Fprintf(b, " %v", val)
continue
}
_, _ = fmt.Fprintf(b, " %v", val)
}
} else {
_, _ = fmt.Fprintf(b, "\n%v: %v", k, frontMatter[k])
continue
}
_, _ = fmt.Fprintf(b, "\n%v: %v", k, frontMatter[k])
}
_, _ = b.Write([]byte("\n---\n\n"))
return b.Bytes(), nil
Expand Down

0 comments on commit 6a56309

Please sign in to comment.