Skip to content

Commit

Permalink
Add title and subtitle to edition
Browse files Browse the repository at this point in the history
  • Loading branch information
ahobsonsayers committed Dec 26, 2024
1 parent 6a0340d commit bf2bdb2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion goodreads/book.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (w Work) AverageRating() float64 {
type Edition struct {
Id string `xml:"id"`
ISBN *string `xml:"isbn13"`
Title string `xml:"title"`
FullTitle string `xml:"title"`
Description string `xml:"description"`
NumPages string `xml:"num_pages"`
ImageURL string `xml:"image_url"`
Expand All @@ -120,6 +120,23 @@ type Edition struct {
Language string `xml:"language_code"`
}

// Title is the full title with any subtitle removed.
// A subtitle is anything after the first : in the full title
func (e Edition) Title() string {
titleParts := strings.Split(e.FullTitle, ":")
return strings.TrimSpace(titleParts[0])
}

// Subtitle is the subtle part of the full title.
// A subtitle is anything after the first : in the full title
func (e Edition) Subtitle() string {
colonIdx := strings.Index(e.FullTitle, ":")
if colonIdx == -1 {
return ""
}
return strings.TrimSpace(e.FullTitle[colonIdx+1:])
}

func (e *Edition) Sanitise() {
// Description can sometimes be html and contain preamble about alternative covers
description := strings.TrimSpace(e.Description)
Expand Down

0 comments on commit bf2bdb2

Please sign in to comment.