Wire everything together, now it's amen

This commit is contained in:
2024-11-06 00:40:28 +01:00
parent 0cdc57bf9a
commit 7a04d16a2e
4 changed files with 49 additions and 24 deletions

55
main.go
View File

@@ -6,9 +6,11 @@ import (
"io"
"log"
"os"
"regexp"
)
var url = `https://wowprogramming.com/docs/api.html`
var rootUrl = `https://wowprogramming.com/`
var apiUrl = fmt.Sprintf("%s/docs/api.html", rootUrl)
var Error *log.Logger
var Warning *log.Logger
@@ -37,30 +39,45 @@ var html string
//go:embed doc.html
var doc string
var pageNameExtractor = regexp.MustCompile(`\/([^/]+).html`)
var outDir = "out"
func main() {
//res, err := FetchFull(url)
//if err != nil {
// Error.Printf("Error fetching %s: %v", url, err)
// return
//}
res, err := Fetch(apiUrl)
if err != nil {
Error.Printf("Error fetching %s: %v", apiUrl, err)
return
}
//os.WriteFile("test.html", []byte(res), 0644)
// foo, err := ParseHTML(html)
// if err != nil {
// Error.Printf("Error parsing HTML: %v", err)
// return
// }
// log.Printf("%#v", foo)
foo, err := ParseDoc(doc)
pages, err := ParseHTML(res)
if err != nil {
Error.Printf("Error parsing HTML: %v", err)
return
}
foo.Name = "JoinPermanentChannel"
log.Printf("%#v", foo)
err = foo.WriteFile()
if err != nil {
Error.Printf("Error writing file: %v", err)
return
for _, page := range pages {
log.Printf("Processing page %s", page)
pname := pageNameExtractor.FindStringSubmatch(page)
if len(pname) != 2 {
Error.Printf("Failed to extract page name from %s", page)
continue
}
res, err := Fetch(rootUrl + page)
if err != nil {
Error.Printf("Error fetching %s: %v", rootUrl+page, err)
}
function, err := ParseDoc(res)
if err != nil {
Error.Printf("Error parsing HTML: %v", err)
continue
}
function.Name = pname[1]
err = function.WriteFile(outDir)
if err != nil {
Error.Printf("Error writing file: %v", err)
continue
}
}
}