mirror of
https://github.com/tnypxl/rollup.git
synced 2025-12-13 06:23:18 +00:00
refactor: update writeMultipleFiles to create single output file
This commit is contained in:
31
cmd/web.go
31
cmd/web.go
@@ -113,25 +113,20 @@ func writeSingleFile(content map[string]string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeMultipleFiles(content map[string]string) error {
|
||||
for url, c := range content {
|
||||
filename, err := getFilenameFromContent(c, url)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error generating filename for %s: %v", url, err)
|
||||
}
|
||||
file, err := os.Create(filename)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating output file %s: %v", filename, err)
|
||||
}
|
||||
|
||||
_, err = file.WriteString(fmt.Sprintf("# Content from %s\n\n%s", url, c))
|
||||
file.Close()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error writing content to file %s: %v", filename, err)
|
||||
}
|
||||
|
||||
fmt.Printf("Content from %s has been saved to %s\n", url, filename)
|
||||
func writeMultipleFiles(content map[string]string, outputFilename string) error {
|
||||
file, err := os.Create(outputFilename)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating output file %s: %v", outputFilename, err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
for path, c := range content {
|
||||
_, err = file.WriteString(fmt.Sprintf("# File: %s\n\n%s\n\n", path, c))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error writing content to file %s: %v", outputFilename, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user