Added support for comics

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
2025-05-03 08:19:44 +01:00
parent 6a16f4285b
commit ba58d6b435

View File

@@ -3,6 +3,7 @@ package storygraph
import (
"fmt"
"iter"
"maps"
"net/http"
"os"
"slices"
@@ -110,6 +111,7 @@ func GetLatestBooks() (map[string]*Book, error) {
"Business": nextByTag(links, "Business"),
"Technology": nextByTag(links, "Technology"),
"Sci-Fi": nextByTag(links, "Sci-Fi"),
"Comics": nextByTag(links, "Comics"),
}, nil
}
@@ -180,7 +182,8 @@ func getImage(decs iter.Seq[*html.Node]) string {
}
func getTags(decs iter.Seq[*html.Node]) []string {
tags := []string{}
tags := map[string]bool{}
for n := range decs {
if n.Type == html.ElementNode && n.DataAtom == atom.Div {
for _, a := range n.Attr {
@@ -191,25 +194,27 @@ func getTags(decs iter.Seq[*html.Node]) []string {
if b.Type == html.TextNode {
switch b.Data {
case "fiction":
tags = append(tags, "Fiction")
tags["Fiction"] = true
case "nonfiction":
tags = append(tags, "Non-Fiction")
tags["Non-Fiction"] = true
case "psychology":
fallthrough
case "self help":
fallthrough
case "health":
tags = append(tags, "Health")
tags["Health"] = true
case "art":
tags = append(tags, "Art")
tags["Art"] = true
case "business":
tags = append(tags, "Business")
tags["Business"] = true
case "technology":
fallthrough
case "computer science":
tags = append(tags, "Technology")
tags["Technology"] = true
case "science fiction":
tags = append(tags, "Sci-Fi")
tags["Sci-Fi"] = true
case "comics":
tags["Comics"] = true
}
}
}
@@ -219,7 +224,13 @@ func getTags(decs iter.Seq[*html.Node]) []string {
}
}
}
return tags
// Only include comics in the "comics" category
if tags["Comics"] {
tags = map[string]bool{"Comics": true}
}
return slices.Collect(maps.Keys(tags))
}
func bookContains(links []Book, bookID string) bool {