mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
yaml.Marshal defaults to 4 spaces, and only the config package forced 2. Saving a plugin re-encodes the whole config.yaml, so installing one reindented a user's entire file; skill/agent frontmatter and audit-rules.yaml were written with 4 spaces too. Route all YAML writers (config, registry, plugins, MCP, frontmatter, audit rules) through one utils.MarshalYAML so they cannot drift apart.
23 lines
482 B
Go
23 lines
482 B
Go
package utils
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// MarshalYAML marshals v with 2-space indentation (Go yaml default is 4).
|
|
// Every YAML file skillshare writes goes through it, so edits never reindent a user's file.
|
|
func MarshalYAML(v any) ([]byte, error) {
|
|
var buf bytes.Buffer
|
|
enc := yaml.NewEncoder(&buf)
|
|
enc.SetIndent(2)
|
|
if err := enc.Encode(v); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := enc.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
return buf.Bytes(), nil
|
|
}
|