json output for list command

This commit is contained in:
lapwat
2023-02-17 19:47:23 +01:00
parent 23cc576926
commit efcc45316b
7 changed files with 89 additions and 69 deletions

View File

@@ -1,18 +1,10 @@
package book
type link struct {
href string
text string
Href string `json:"href"`
Text string `json:"name"`
}
func NewLink(href, text string) link {
return link{href, text}
}
func (c link) Href() string {
return c.href
}
func (c link) Text() string {
return c.text
}

View File

@@ -27,7 +27,7 @@ func NewProgress(links []link, parent string, depth int) progress {
if len(links) <= 50 {
for index, link := range links {
bar := uiprogress.AddBar(1)
barText := fmt.Sprintf("%v#%v %v", indent, index+1, link.Text())
barText := fmt.Sprintf("%v#%v %v", indent, index+1, link.Text)
bar.AppendFunc(func(b *uiprogress.Bar) string {
return barText
})

View File

@@ -156,12 +156,12 @@ func NewChapterFromURL(url, linkName string, configs []*ScrapeConfig, index int,
// synchronous mode
for index, link := range links {
// and then use it to parse relative URLs
u, err := base.Parse(link.href)
u, err := base.Parse(link.Href)
if err != nil {
log.Fatal(err)
}
sc := NewChapterFromURL(u.String(), link.text, configs[1:], index, p.UpdateName)
sc := NewChapterFromURL(u.String(), link.Text, configs[1:], index, p.UpdateName)
subchapters[index] = sc
if config.Quiet == false {
p.Increment(index)
@@ -189,12 +189,12 @@ func NewChapterFromURL(url, linkName string, configs []*ScrapeConfig, index int,
defer wg.Done()
// and then use it to parse relative URLs
u, err := base.Parse(l.href)
u, err := base.Parse(l.Href)
if err != nil {
log.Fatal(err)
}
sc := NewChapterFromURL(u.String(), l.text, configs[1:], index, p.UpdateName)
sc := NewChapterFromURL(u.String(), l.Text, configs[1:], index, p.UpdateName)
subchapters[index] = sc
if config.Quiet == false {
@@ -279,12 +279,12 @@ func tableOfContent(url string, config *ScrapeConfig, subConfig *ScrapeConfig, q
for index, l := range links {
// and then use it to parse relative URLs
u, err := base.Parse(l.href)
u, err := base.Parse(l.Href)
if err != nil {
log.Fatal(err)
}
chapters[index] = NewChapterFromURL(u.String(), l.text, []*ScrapeConfig{subConfig}, 0, func(index int, name string) {})
chapters[index] = NewChapterFromURL(u.String(), l.Text, []*ScrapeConfig{subConfig}, 0, func(index int, name string) {})
if quiet == false {
p.Increment(index)
@@ -317,12 +317,12 @@ func tableOfContent(url string, config *ScrapeConfig, subConfig *ScrapeConfig, q
defer wg.Done()
// and then use it to parse relative URLs
u, err := base.Parse(l.href)
u, err := base.Parse(l.Href)
if err != nil {
log.Fatal(err)
}
chapters[index] = NewChapterFromURL(u.String(), l.text, []*ScrapeConfig{subConfig}, 0, func(index int, name string) {})
chapters[index] = NewChapterFromURL(u.String(), l.Text, []*ScrapeConfig{subConfig}, 0, func(index int, name string) {})
if quiet == false {
p.Increment(index)
@@ -361,8 +361,6 @@ func GetLinks(url *urllib.URL, selector string, limit, offset int, reverse, incl
parser := gofeed.NewParser()
feed, err := parser.ParseURL(url.String())
fmt.Println(feed, url.String(), err)
if err == nil {
// RSS feed