summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-28 12:33:41 -0400
committerdemo <demo@antix1>2026-05-28 12:33:41 -0400
commit10ddae559ad28e21c7e1db99d29312907ce2c70f (patch)
tree6ffca0fe21d0720140e1d96bbdaa7263c6015f5f
parente59a7f0dd76b0e837dbd125d446aa02fb2bc18cc (diff)
wip: generate rough draft of sitemap
-rw-r--r--classic.go8
-rw-r--r--xml.go47
2 files changed, 55 insertions, 0 deletions
diff --git a/classic.go b/classic.go
index 19450c1..e30f3b3 100644
--- a/classic.go
+++ b/classic.go
@@ -73,6 +73,14 @@ loop:
cancel()
wg.Wait()
+
+ fmt.Println("Generating sitemap...")
+ sitemap, err := toSitemap(seen)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ fmt.Println(sitemap)
}
func getBatch(u url.URL) []url.URL {
diff --git a/xml.go b/xml.go
new file mode 100644
index 0000000..3471bba
--- /dev/null
+++ b/xml.go
@@ -0,0 +1,47 @@
+package main
+
+import (
+ "encoding/xml"
+ "fmt"
+ "net/url"
+)
+
+type XMLURLset struct {
+ XMLName xml.Name `xml:"urlset"`
+ Xmlns string `xml:"xmlns,attr"`
+ URLs []URL `xml:"url"`
+}
+
+type URL struct {
+ Loc Loc `xml:"loc"`
+}
+
+type Loc struct {
+ Text string `xml:",chardata"`
+}
+
+func toSitemap(seen map[url.URL]int) (string, error) {
+ var xmlURLs []URL
+
+ for u := range seen {
+ xmlURL := URL{
+ Loc: Loc{
+ Text: fmt.Sprintf("%s", &u),
+ },
+ }
+
+ xmlURLs = append(xmlURLs, xmlURL)
+ }
+
+ set := XMLURLset{
+ Xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9",
+ URLs: xmlURLs,
+ }
+
+ output, err := xml.MarshalIndent(&set, "", "\t")
+ if err != nil {
+ return "", err
+ }
+
+ return string(output), nil
+}