diff --git a/main.go b/main.go index 8453cd7..b82bd7d 100644 --- a/main.go +++ b/main.go @@ -27,7 +27,7 @@ func init() { } func main() { - latestBooks := map[string]*storygraph.Book{} + latestBooks := map[string]*[]storygraph.Book{} refreshingBooks := true var lastUpdated *time.Time @@ -41,9 +41,9 @@ func main() { } // Update each category individually with books we have managed to find - for cat, book := range newBookList { + for cat, books := range newBookList { if b, ok := newBookList[cat]; ok && b != nil { - latestBooks[cat] = book + latestBooks[cat] = books } } now := time.Now() @@ -60,7 +60,7 @@ func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { type data struct { - Books map[string]*storygraph.Book + Books map[string]*[]storygraph.Book LastUpdated string Refreshing bool } diff --git a/pkg/storygraph/client.go b/pkg/storygraph/client.go index 511b214..1e88714 100644 --- a/pkg/storygraph/client.go +++ b/pkg/storygraph/client.go @@ -37,7 +37,7 @@ func init() { c = New(cookie) } -func GetLatestBooks() (map[string]*Book, error) { +func GetLatestBooks() (map[string]*[]Book, error) { fmt.Println("Fetching latest book recommendations...") links := []Book{} @@ -46,7 +46,7 @@ func GetLatestBooks() (map[string]*Book, error) { page++ fmt.Println("Fetching page", page) - resp, err := c.Get(fmt.Sprintf("https://app.thestorygraph.com/to-read/averagemarcus?page=%d", page)) + resp, err := c.Get(fmt.Sprintf("https://app.thestorygraph.com/to-read/averagemarcus?per_page=100&page=%d", page)) if err != nil { fmt.Println("Error making request:", err) return nil, err @@ -94,7 +94,7 @@ func GetLatestBooks() (map[string]*Book, error) { return links[i].Rating > links[j].Rating }) - return map[string]*Book{ + return map[string]*[]Book{ "Fiction": nextByTag(links, "Fiction"), "Non-Fiction": nextByTag(links, "Non-Fiction"), "Health": nextByTag(links, "Health"), @@ -230,11 +230,12 @@ func bookContains(links []Book, bookID string) bool { return false } -func nextByTag(links []Book, tag string) *Book { +func nextByTag(links []Book, tag string) *[]Book { + filtered := []Book{} for _, b := range links { if slices.Contains(b.Tags, tag) { - return &b + filtered = append(filtered, b) } } - return nil + return &filtered } diff --git a/templates/index.html b/templates/index.html index 71fd495..048e9c4 100644 --- a/templates/index.html +++ b/templates/index.html @@ -78,7 +78,7 @@ {{ if index .Books "Fiction" }}
{{ $cat := "Fiction" }} - {{ $book := index .Books $cat }} + {{ $book := index (index .Books $cat) 0 }}

{{ $cat }}

@@ -88,7 +88,7 @@
⭐ {{ $book.Rating }}
{{ $cat := "Non-Fiction" }} - {{ $book := index .Books $cat }} + {{ $book := index (index .Books $cat) 0 }}

{{ $cat }}

@@ -98,7 +98,7 @@
⭐ {{ $book.Rating }}
{{ $cat := "Comics" }} - {{ $book := index .Books $cat }} + {{ $book := index (index .Books $cat) 0 }}

{{ $cat }}

@@ -108,10 +108,11 @@
⭐ {{ $book.Rating }}
- {{ range $cat, $book := .Books }} + {{ range $cat, $Books := .Books }} {{ if or (eq $cat "Fiction") (eq $cat "Non-Fiction") (eq $cat "Comics") }} {{ continue }} {{ end }} + {{ $book := index $Books 0 }}

{{ $cat }}