mirror of
https://github.com/tnypxl/rollup.git
synced 2025-12-15 15:03:17 +00:00
fix: update writeMultipleFiles function to handle multiple files
This commit is contained in:
28
cmd/web.go
28
cmd/web.go
@@ -114,18 +114,26 @@ func writeSingleFile(content map[string]string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeMultipleFiles(content map[string]string, outputFilename string) error {
|
func writeMultipleFiles(content map[string]string) error {
|
||||||
file, err := os.Create(outputFilename)
|
for url, c := range content {
|
||||||
if err != nil {
|
filename, err := getFilenameFromContent(c, url)
|
||||||
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("error writing content to file %s: %v", outputFilename, err)
|
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\n", url, c))
|
||||||
|
if err != nil {
|
||||||
|
file.Close()
|
||||||
|
return fmt.Errorf("error writing content to file %s: %v", filename, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
file.Close()
|
||||||
|
fmt.Printf("Content from %s has been saved to %s\n", url, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user