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
54
main.go
54
main.go
@ -76,28 +76,10 @@ func renderAll() error {
|
|||||||
return fmt.Errorf("unable to create goquery instance: %w", err)
|
return fmt.Errorf("unable to create goquery instance: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
objs := make(map[string]Object)
|
objs, err := extractObjects(doc)
|
||||||
doc.
|
if err != nil {
|
||||||
Find("body #contents").
|
return fmt.Errorf("unable to extract categories: %w", err)
|
||||||
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
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
if err := renderCategories(objs); err != nil {
|
if err := renderCategories(objs); err != nil {
|
||||||
return fmt.Errorf("unable to render categories: %w", err)
|
return fmt.Errorf("unable to render categories: %w", err)
|
||||||
@ -135,6 +117,34 @@ func dropCreateDir(dir string) error {
|
|||||||
return nil
|
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 {
|
func mkdirAll(path string) error {
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
// NOTE: directory is exists
|
// NOTE: directory is exists
|
||||||
|
Loading…
Reference in New Issue
Block a user