From 104577455dcc0d45d0c0b6b9f07221beb1eb455f Mon Sep 17 00:00:00 2001 From: demo Date: Fri, 12 Jun 2026 11:45:59 -0400 Subject: refactor: move sitemap-creation to 'run' and fix missing xml dir --- run.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'run.go') diff --git a/run.go b/run.go index 5f56572..a1c64f7 100644 --- a/run.go +++ b/run.go @@ -2,8 +2,12 @@ package main import ( "context" + "errors" "fmt" + "io/fs" + "log" "net/url" + "os" "runtime/pprof" "strings" "time" @@ -35,10 +39,29 @@ func run(ctx context.Context, cmd *cli.Command) error { return err } + var seen map[url.URL]int getLeakProfile(func() { - classic(u, cmd.Int("concurrency"), cmd.Int("maxurls"), cmd.Int("depth")) + seen = classic(u, cmd.Int("concurrency"), cmd.Int("maxurls"), cmd.Int("depth")) }) + // Generate a sitemap. + fmt.Println("Generating sitemap...") + sitemap, err := toSitemap(seen, cmd.Int("depth"), cmd.Int("maxurls")) + if err != nil { + log.Fatal(err) + } + + if err := os.Mkdir("xml", 0750); err != nil && !errors.Is(err, fs.ErrExist) { + log.Fatal(err) + } + + xmlFilename := fmt.Sprintf("xml/%s.xml", u.Host) + if err := os.WriteFile(xmlFilename, []byte(sitemap), 0666); err != nil { + log.Fatal(err) + } + + fmt.Printf("Wrote sitemap to %s\n", xmlFilename) + return nil } -- cgit v1.2.3