// Append the new page to the array and set its name and URL
pages[group]=append(pages[group],wikiPage{
name:element.Text,
url:element.Attr("href"),
})
log.Printf("Found wiki page: %s/%s",group,element.Text)
})
}
})
// After defining the OnHTML callback, visit the group listing
// This won't finish until all groups have been visited inside and the entire callback is done
collector.Visit("https://tildes.net/groups")
// Create the sitemap.md file
file,_:=os.Create("sitemap.md")
deferfile.Close()
// Write the boilerplate stuff first
file.WriteString("# Tildes Wiki Sitemap\n\n")
file.WriteString("Automatically generated by [this program](https://gitlab.com/bauke/tildes-wiki-sitemap). [PM @Bauke](https://tildes.net/user/Bauke/new_message) if this page is outdated and you can't run the program yourself.\n\n")
file.WriteString("This page is a temporary placeholder to help wiki contributors navigate. Find this page easily by bookmarking it!\n\n")
// Sort the groups
sort.Strings(groups)
// Define a variable that will keep track of the pages count
pagesTotal:=0
// Write a . to indicate the start of the tree
file.WriteString(".\n")
// Iterate over the group names
forindex,group:=rangegroups{
prefix:=""
ifindex==len(groups)-1{
// If we're at the last group, write the "L" piece instead