From bf28343c1594903701c5b225a59365079fc48396 Mon Sep 17 00:00:00 2001 From: Kirill Zhuravlev Date: Tue, 14 Feb 2023 20:24:30 +0100 Subject: [PATCH] add notes --- main.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 68aaf921..4deed39d 100644 --- a/main.go +++ b/main.go @@ -166,16 +166,21 @@ func makeObjByID(selector string, s *goquery.Selection) (*Object, error) { var obj Object var err error - s.Find(selector).Each(func(_ int, s *goquery.Selection) { - desc := s.NextFiltered("p") - ul := s.NextFilteredUntil("ul", "h2") + s.Find(selector).Each(func(_ int, selCatHeader *goquery.Selection) { + selDescr := selCatHeader.NextFiltered("p") + // FIXME: bug. this would select links from all neighboring + // sub-categories until the next category. To prevent this we should + // find only first ul + ul := selCatHeader.NextFilteredUntil("ul", "h2") var links []Link - ul.Find("li").Each(func(_ int, s *goquery.Selection) { - url, _ := s.Find("a").Attr("href") + ul.Find("li").Each(func(_ int, selLi *goquery.Selection) { + selLink := selLi.Find("a") + url, _ := selLink.Attr("href") link := Link{ - Title: s.Find("a").Text(), - Description: s.Text(), + Title: selLink.Text(), + // FIXME: Title contains only title but description contains Title + description + Description: selLi.Text(), Url: url, } links = append(links, link) @@ -186,9 +191,9 @@ func makeObjByID(selector string, s *goquery.Selection) (*Object, error) { return } obj = Object{ - Slug: slug.Generate(s.Text()), - Title: s.Text(), - Description: desc.Text(), + Slug: slug.Generate(selCatHeader.Text()), + Title: selCatHeader.Text(), + Description: selDescr.Text(), Items: links, } })