mirror of
https://github.com/avelino/awesome-go.git
synced 2024-11-07 16:33:40 +00:00
extract "object extractor"
This commit is contained in:
parent
90bd8d65f3
commit
1e1a153e52
50
main.go
50
main.go
@ -76,29 +76,11 @@ func renderAll() error {
|
||||
return fmt.Errorf("unable to create goquery instance: %w", err)
|
||||
}
|
||||
|
||||
objs := make(map[string]Object)
|
||||
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
|
||||
}
|
||||
|
||||
obj, err := makeObjByID(selector, doc)
|
||||
objs, err := extractObjects(doc)
|
||||
if err != nil {
|
||||
return
|
||||
return fmt.Errorf("unable to extract categories: %w", err)
|
||||
}
|
||||
|
||||
objs[selector] = *obj
|
||||
})
|
||||
})
|
||||
|
||||
if err := renderCategories(objs); err != nil {
|
||||
return fmt.Errorf("unable to render categories: %w", err)
|
||||
}
|
||||
@ -135,6 +117,34 @@ func dropCreateDir(dir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func extractObjects(doc *goquery.Document) (map[string]Object, error) {
|
||||
objs := make(map[string]Object)
|
||||
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
|
||||
}
|
||||
|
||||
obj, err := makeObjByID(selector, doc)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
objs[selector] = *obj
|
||||
})
|
||||
})
|
||||
|
||||
// FIXME: handle error
|
||||
return objs, nil
|
||||
}
|
||||
|
||||
func mkdirAll(path string) error {
|
||||
_, err := os.Stat(path)
|
||||
// NOTE: directory is exists
|
||||
|
Loading…
Reference in New Issue
Block a user