diff --git a/lib/admin.go b/lib/admin.go index 20a5203..3994d64 100644 --- a/lib/admin.go +++ b/lib/admin.go @@ -69,8 +69,8 @@ func editHandler(h handler) { data.Book = book data.S = GetStatus(h) author := "" - if len(book.Author) > 0 { - author = " by " + book.Author[0] + if len(book.Authors) > 0 { + author = " by " + book.Authors[0] } data.S.Title = book.Title + author + " -- Edit -- " + data.S.Title h.template.load(h, "edit", data) @@ -98,7 +98,7 @@ func saveHandler(h handler) { date := h.r.FormValue("date") description := h.r.FormValue("description") author := cleanEmptyStr(h.r.Form["author"]) - subject := cleanEmptyStr(strings.Split(h.r.FormValue("subject"), ",")) + tags := cleanEmptyStr(strings.Split(h.r.FormValue("tags"), ",")) isbn := parser.ISBN(h.r.FormValue("isbn")) // XXX: check for errors lang := cleanEmptyStr(h.r.Form["lang"]) book := map[string]interface{}{"title": title, @@ -106,7 +106,7 @@ func saveHandler(h handler) { "date": date, "description": description, "author": author, - "subject": subject, + "tags": tags, "isbn": isbn, "lang": lang} err := h.db.UpdateBook(id, book) @@ -174,7 +174,7 @@ func newHandler(h handler) { for i, b := range res { data.Books[i].B = b _, data.Books[i].TitleFound, _ = h.db.GetBooks("title:"+b.Title, 1, 0) - _, data.Books[i].AuthorFound, _ = h.db.GetBooks("author:"+strings.Join(b.Author, " author:"), 1, 0) + _, data.Books[i].AuthorFound, _ = h.db.GetBooks("author:"+strings.Join(b.Authors, " author:"), 1, 0) } data.Page = page + 1 if num > (page+1)*newItemsPage { diff --git a/lib/database/books.go b/lib/database/books.go index 557df25..3a5e328 100644 --- a/lib/database/books.go +++ b/lib/database/books.go @@ -5,15 +5,14 @@ import ( "time" ) -// TODO: Author -> Authors, Subject -> Tags type Book struct { Id string Title string - Author []string `sql:"authors" pg:",array"` + Authors []string `sql:"authors" pg:",array"` Contributor string Publisher string Description string - Subject []string `sql:"tags" pg:",array"` + Tags []string `sql:"tags" pg:",array"` Date string Lang string Isbn string diff --git a/lib/database/books_test.go b/lib/database/books_test.go index 0c016de..c69efb1 100644 --- a/lib/database/books_test.go +++ b/lib/database/books_test.go @@ -3,9 +3,9 @@ package database import "testing" var book = Book{ - Id: "r_m-IOzzIbA6QK5w", - Title: "some title", - Author: []string{"Alice", "Bob"}, + Id: "r_m-IOzzIbA6QK5w", + Title: "some title", + Authors: []string{"Alice", "Bob"}, } func TestAddAndDeleteBook(t *testing.T) { @@ -61,8 +61,8 @@ func TestActiveBook(t *testing.T) { if !b.Active { t.Error("Book is not activated") } - if b.Author[0] != books[0].Author[0] { - t.Error("Book author don't match : '", b.Author, "' <=> '", book.Author, "'") + if b.Authors[0] != books[0].Authors[0] { + t.Error("Book author don't match : '", b.Authors, "' <=> '", book.Authors, "'") } bs, num, err := db.GetBooks(book.Title, 20, 0) @@ -72,8 +72,8 @@ func TestActiveBook(t *testing.T) { if num != 1 || len(bs) != 1 { t.Fatal("We got a un expected number of books: ", num, bs) } - if bs[0].Author[0] != book.Author[0] { - t.Error("Book author don't match : '", bs[0].Author, "' <=> '", book.Author, "'") + if bs[0].Authors[0] != book.Authors[0] { + t.Error("Book author don't match : '", bs[0].Authors, "' <=> '", book.Authors, "'") } bs, num, err = db.GetBooks("none", 20, 0) diff --git a/lib/database/stats.go b/lib/database/stats.go index 9d866ed..7eb2a33 100644 --- a/lib/database/stats.go +++ b/lib/database/stats.go @@ -21,7 +21,6 @@ type Visits struct { Count int "count" } -// TODO: split code in files func (db *pgDB) AddStats(stats interface{}) error { return nil } diff --git a/lib/parser/parser.go b/lib/parser/parser.go index 75867cb..98220ba 100644 --- a/lib/parser/parser.go +++ b/lib/parser/parser.go @@ -19,7 +19,7 @@ func EpubMetadata(epub *epubgo.Epub) database.Book { case "title": book.Title = cleanStr(strings.Join(data, ", ")) case "creator": - book.Author = parseAuthr(data) + book.Authors = parseAuthr(data) case "contributor": book.Contributor = cleanStr(strings.Join(data, ", ")) case "publisher": @@ -27,7 +27,7 @@ func EpubMetadata(epub *epubgo.Epub) database.Book { case "description": book.Description = parseDescription(data) case "subject": - book.Subject = parseSubject(data) + book.Tags = parseSubject(data) case "date": book.Date = parseDate(data) case "language": diff --git a/lib/reader.go b/lib/reader.go index 4a4c0e7..f8b7c10 100644 --- a/lib/reader.go +++ b/lib/reader.go @@ -159,8 +159,8 @@ func readHandler(h handler) { data.S = GetStatus(h) author := "" - if len(book.Author) > 0 { - author = " by " + book.Author[0] + if len(book.Authors) > 0 { + author = " by " + book.Authors[0] } data.S.Title = book.Title + author + " -- Read -- " + data.S.Title diff --git a/lib/template.go b/lib/template.go index e6cf989..f5ffad4 100644 --- a/lib/template.go +++ b/lib/template.go @@ -208,11 +208,11 @@ func bookJsonRaw(book database.Book) map[string]interface{} { return map[string]interface{}{ "id": book.Id, "title": book.Title, - "author": book.Author, + "authors": book.Authors, "contributor": book.Contributor, "publisher": book.Publisher, "description": book.Description, - "subject": book.Subject, + "tags": book.Tags, "date": book.Date, "lang": book.Lang, "isbn": book.Isbn, diff --git a/lib/trantor.go b/lib/trantor.go index 88f64c3..b678602 100644 --- a/lib/trantor.go +++ b/lib/trantor.go @@ -68,8 +68,8 @@ func bookHandler(h handler) { data.Book = book author := "" - if len(book.Author) > 0 { - author = " by " + book.Author[0] + if len(book.Authors) > 0 { + author = " by " + book.Authors[0] } data.S.Title = book.Title + author + " -- " + data.S.Title diff --git a/templates/book.html b/templates/book.html index 3fd7b19..b0d28c2 100644 --- a/templates/book.html +++ b/templates/book.html @@ -35,9 +35,9 @@ function delBook(){
- {{if .Author}}
Author
{{range .Author}}{{.}}, {{end}}
{{end}} + {{if .Authors}}
Authors
{{range .Authors}}{{.}}, {{end}}
{{end}} {{if .Publisher}}
Publisher
{{.Publisher}}
{{end}} - {{if .Subject}}
Tags
{{range .Subject}}{{.}}, {{end}}
{{end}} + {{if .Tags}}
Tags
{{range .Tags}}{{.}}, {{end}}
{{end}} {{if .Isbn}}
ISBN
{{.Isbn}}
{{end}} {{if .Date}}
Date
{{.Date}}
{{end}} {{if .Lang}}
Lang
{{.Lang}}
{{end}} diff --git a/templates/edit.html b/templates/edit.html index 776c740..e050d58 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -22,7 +22,7 @@
- {{range .Author}} + {{range .Authors}} {{end}} @@ -37,7 +37,7 @@
- +
diff --git a/templates/help.html b/templates/help.html index 4cfa8d7..d88b660 100644 --- a/templates/help.html +++ b/templates/help.html @@ -12,7 +12,7 @@

There is other topics than lang that can be used:

diff --git a/templates/index.html b/templates/index.html index e3cfcd2..752ed87 100644 --- a/templates/index.html +++ b/templates/index.html @@ -72,7 +72,7 @@
-

{{range .Tags}}{{.}} {{end}}

+

{{range .Tags}}{{.}} {{end}}

{{template "footer.html"}} diff --git a/templates/index.opds b/templates/index.opds index 90e259a..d195ad4 100644 --- a/templates/index.opds +++ b/templates/index.opds @@ -42,11 +42,11 @@ {{html .}} {{$updated}} - {{$baseurl}}/search/?subject:{{urlquery .}} + {{$baseurl}}/search/?tag:{{urlquery .}} {{end}} diff --git a/templates/new.html b/templates/new.html index 04381c8..8477bf8 100644 --- a/templates/new.html +++ b/templates/new.html @@ -34,9 +34,9 @@

{{.Title}} ({{$titleFound}})
- {{if .Author}}Author: {{range .Author}}{{.}}, {{end}} ({{$authorFound}})
{{end}} + {{if .Authors}}Authors: {{range .Authors}}{{.}}, {{end}} ({{$authorFound}})
{{end}} {{if .Publisher}}Publisher: {{.Publisher}}
{{end}} - {{if .Subject}}Tags: {{range .Subject}}{{.}}, {{end}}
{{end}} + {{if .Tags}}Tags: {{range .Tags}}{{.}}, {{end}}
{{end}} {{if .Isbn}}ISBN: {{.Isbn}}
{{end}} {{if .Date}}Date: {{.Date}}
{{end}} {{if .Lang}}Lang: {{.Lang}}
{{end}} diff --git a/templates/search.html b/templates/search.html index ea042dd..e656bcb 100644 --- a/templates/search.html +++ b/templates/search.html @@ -30,7 +30,7 @@ [{{if .Lang}}{{.Lang}}{{end}}] {{.Title}} {{if .Publisher}}{{.Publisher}}{{end}}
- {{range .Author}}{{.}}, {{end}} + {{range .Authors}}{{.}}, {{end}}

diff --git a/templates/search.opds b/templates/search.opds index 6e4ff5b..d8810a1 100644 --- a/templates/search.opds +++ b/templates/search.opds @@ -61,7 +61,7 @@ {{$baseurl}}/book/{{.Id}} {{$updated}} - {{range .Author}} + {{range .Authors}} {{html .}} @@ -83,7 +83,7 @@ {{if .Lang}} {{.Lang}} {{end}} - {{range .Subject}} + {{range .Tags}} {{end}} diff --git a/templates/search.rss b/templates/search.rss index 035ff03..b98451c 100644 --- a/templates/search.rss +++ b/templates/search.rss @@ -14,14 +14,14 @@ {{$baseURL := .S.BaseURL}} {{range .Books}} - {{.Title}} - {{index .Author 0}} + {{.Title}} - {{index .Authors 0}} {{.Description}} {{$baseURL}}/book/{{.Id}} {{if .Isbn}} ISBN: {{.Isbn}} {{end}} -{{range .Subject}} +{{range .Authors}} {{if .}} {{.}} {{end}}