mirror of
https://github.com/tnypxl/rollup.git
synced 2025-12-15 15:03:17 +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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeMultipleFiles(content map[string]string) error {
|
func writeMultipleFiles(content map[string]string, outputFilename string) error {
|
||||||
for url, c := range content {
|
file, err := os.Create(outputFilename)
|
||||||
filename, err := getFilenameFromContent(c, url)
|
if err != nil {
|
||||||
if err != nil {
|
return fmt.Errorf("error creating output 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", 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)
|
|
||||||
}
|
}
|
||||||
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user