Skip to content

Commit c82ffc4

Browse files
committed
Fix YAML formatting: remove leading empty lines
- Filter out empty sections when updating existing config files - Trim whitespace from YAML output when creating new files - No more empty lines at the beginning of sitedog.yml files - Applies to both new file creation and existing file updates
1 parent 10ba537 commit c82ffc4

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

main.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const (
4545
globalTemplatePath = ".sitedog/demo.html.tpl"
4646
authFilePath = ".sitedog/auth"
4747
apiBaseURL = "https://app.sitedog.io"
48-
Version = "v0.6.3"
48+
Version = "v0.6.4"
4949
)
5050

5151
func main() {
@@ -1497,8 +1497,21 @@ func createConfigFromDetectorResults(configPath string, results map[string]strin
14971497
sections = append(sections, newSection)
14981498
}
14991499

1500-
// Join all sections back with empty lines between them
1501-
finalContent := strings.Join(sections, "\n\n") + "\n"
1500+
// Filter out empty sections and join with empty lines between them
1501+
var nonEmptySections []string
1502+
for _, section := range sections {
1503+
trimmed := strings.TrimSpace(section)
1504+
if trimmed != "" {
1505+
nonEmptySections = append(nonEmptySections, trimmed)
1506+
}
1507+
}
1508+
1509+
var finalContent string
1510+
if len(nonEmptySections) > 0 {
1511+
finalContent = strings.Join(nonEmptySections, "\n\n") + "\n"
1512+
} else {
1513+
finalContent = ""
1514+
}
15021515

15031516
if err := os.WriteFile(configPath, []byte(finalContent), 0644); err != nil {
15041517
fmt.Printf("⚠️ Could not write %s: %v\n", configPath, err)
@@ -1518,7 +1531,10 @@ func createConfigFromDetectorResults(configPath string, results map[string]strin
15181531
return
15191532
}
15201533

1521-
if err := os.WriteFile(configPath, yamlData, 0644); err != nil {
1534+
// Clean up any leading/trailing whitespace from YAML output
1535+
cleanedContent := strings.TrimSpace(string(yamlData)) + "\n"
1536+
1537+
if err := os.WriteFile(configPath, []byte(cleanedContent), 0644); err != nil {
15221538
fmt.Printf("⚠️ Could not write %s: %v\n", configPath, err)
15231539
return
15241540
}

0 commit comments

Comments
 (0)