move extractCategories closer to extractCategory

This commit is contained in:
Kirill Zhuravlev 2023-02-15 00:53:54 +01:00 committed by Avelino
parent 3710b307dd
commit c6266ba8c9
No known key found for this signature in database
GPG Key ID: B345B4D52E98180A

56
main.go
View File

@ -116,34 +116,6 @@ func dropCreateDir(dir string) error {
return nil
}
func extractCategories(doc *goquery.Document) (map[string]Category, error) {
categories := make(map[string]Category)
doc.
Find("body #contents").
NextFiltered("ul").
Find("ul").
Each(func(_ int, selUl *goquery.Selection) {
selUl.
Find("li a").
Each(func(_ int, s *goquery.Selection) {
selector, exists := s.Attr("href")
if !exists {
return
}
category, err := makeCategoryByID(selector, doc)
if err != nil {
return
}
categories[selector] = *category
})
})
// FIXME: handle error
return categories, nil
}
func mkdirAll(path string) error {
_, err := os.Stat(path)
// NOTE: directory is exists
@ -220,6 +192,34 @@ func renderSitemap(categories map[string]Category) error {
return nil
}
func extractCategories(doc *goquery.Document) (map[string]Category, error) {
categories := make(map[string]Category)
doc.
Find("body #contents").
NextFiltered("ul").
Find("ul").
Each(func(_ int, selUl *goquery.Selection) {
selUl.
Find("li a").
Each(func(_ int, s *goquery.Selection) {
selector, exists := s.Attr("href")
if !exists {
return
}
category, err := makeCategoryByID(selector, doc)
if err != nil {
return
}
categories[selector] = *category
})
})
// FIXME: handle error
return categories, nil
}
func makeCategoryByID(selector string, doc *goquery.Document) (*Category, error) {
var category Category
var err error