mirror of
https://github.com/avelino/awesome-go.git
synced 2024-11-07 16:33:40 +00:00
move extractCategories closer to extractCategory
This commit is contained in:
parent
3710b307dd
commit
c6266ba8c9
56
main.go
56
main.go
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user