Rename author to authors and subject to tags

This commit is contained in:
Las Zenow 2016-07-30 07:36:58 -04:00
parent e72de38725
commit 7f9c172853
17 changed files with 37 additions and 39 deletions

View file

@ -69,8 +69,8 @@ func editHandler(h handler) {
data.Book = book data.Book = book
data.S = GetStatus(h) data.S = GetStatus(h)
author := "" author := ""
if len(book.Author) > 0 { if len(book.Authors) > 0 {
author = " by " + book.Author[0] author = " by " + book.Authors[0]
} }
data.S.Title = book.Title + author + " -- Edit -- " + data.S.Title data.S.Title = book.Title + author + " -- Edit -- " + data.S.Title
h.template.load(h, "edit", data) h.template.load(h, "edit", data)
@ -98,7 +98,7 @@ func saveHandler(h handler) {
date := h.r.FormValue("date") date := h.r.FormValue("date")
description := h.r.FormValue("description") description := h.r.FormValue("description")
author := cleanEmptyStr(h.r.Form["author"]) 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 isbn := parser.ISBN(h.r.FormValue("isbn")) // XXX: check for errors
lang := cleanEmptyStr(h.r.Form["lang"]) lang := cleanEmptyStr(h.r.Form["lang"])
book := map[string]interface{}{"title": title, book := map[string]interface{}{"title": title,
@ -106,7 +106,7 @@ func saveHandler(h handler) {
"date": date, "date": date,
"description": description, "description": description,
"author": author, "author": author,
"subject": subject, "tags": tags,
"isbn": isbn, "isbn": isbn,
"lang": lang} "lang": lang}
err := h.db.UpdateBook(id, book) err := h.db.UpdateBook(id, book)
@ -174,7 +174,7 @@ func newHandler(h handler) {
for i, b := range res { for i, b := range res {
data.Books[i].B = b data.Books[i].B = b
_, data.Books[i].TitleFound, _ = h.db.GetBooks("title:"+b.Title, 1, 0) _, 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 data.Page = page + 1
if num > (page+1)*newItemsPage { if num > (page+1)*newItemsPage {

View file

@ -5,15 +5,14 @@ import (
"time" "time"
) )
// TODO: Author -> Authors, Subject -> Tags
type Book struct { type Book struct {
Id string Id string
Title string Title string
Author []string `sql:"authors" pg:",array"` Authors []string `sql:"authors" pg:",array"`
Contributor string Contributor string
Publisher string Publisher string
Description string Description string
Subject []string `sql:"tags" pg:",array"` Tags []string `sql:"tags" pg:",array"`
Date string Date string
Lang string Lang string
Isbn string Isbn string

View file

@ -3,9 +3,9 @@ package database
import "testing" import "testing"
var book = Book{ var book = Book{
Id: "r_m-IOzzIbA6QK5w", Id: "r_m-IOzzIbA6QK5w",
Title: "some title", Title: "some title",
Author: []string{"Alice", "Bob"}, Authors: []string{"Alice", "Bob"},
} }
func TestAddAndDeleteBook(t *testing.T) { func TestAddAndDeleteBook(t *testing.T) {
@ -61,8 +61,8 @@ func TestActiveBook(t *testing.T) {
if !b.Active { if !b.Active {
t.Error("Book is not activated") t.Error("Book is not activated")
} }
if b.Author[0] != books[0].Author[0] { if b.Authors[0] != books[0].Authors[0] {
t.Error("Book author don't match : '", b.Author, "' <=> '", book.Author, "'") t.Error("Book author don't match : '", b.Authors, "' <=> '", book.Authors, "'")
} }
bs, num, err := db.GetBooks(book.Title, 20, 0) bs, num, err := db.GetBooks(book.Title, 20, 0)
@ -72,8 +72,8 @@ func TestActiveBook(t *testing.T) {
if num != 1 || len(bs) != 1 { if num != 1 || len(bs) != 1 {
t.Fatal("We got a un expected number of books: ", num, bs) t.Fatal("We got a un expected number of books: ", num, bs)
} }
if bs[0].Author[0] != book.Author[0] { if bs[0].Authors[0] != book.Authors[0] {
t.Error("Book author don't match : '", bs[0].Author, "' <=> '", book.Author, "'") t.Error("Book author don't match : '", bs[0].Authors, "' <=> '", book.Authors, "'")
} }
bs, num, err = db.GetBooks("none", 20, 0) bs, num, err = db.GetBooks("none", 20, 0)

View file

@ -21,7 +21,6 @@ type Visits struct {
Count int "count" Count int "count"
} }
// TODO: split code in files
func (db *pgDB) AddStats(stats interface{}) error { func (db *pgDB) AddStats(stats interface{}) error {
return nil return nil
} }

View file

@ -19,7 +19,7 @@ func EpubMetadata(epub *epubgo.Epub) database.Book {
case "title": case "title":
book.Title = cleanStr(strings.Join(data, ", ")) book.Title = cleanStr(strings.Join(data, ", "))
case "creator": case "creator":
book.Author = parseAuthr(data) book.Authors = parseAuthr(data)
case "contributor": case "contributor":
book.Contributor = cleanStr(strings.Join(data, ", ")) book.Contributor = cleanStr(strings.Join(data, ", "))
case "publisher": case "publisher":
@ -27,7 +27,7 @@ func EpubMetadata(epub *epubgo.Epub) database.Book {
case "description": case "description":
book.Description = parseDescription(data) book.Description = parseDescription(data)
case "subject": case "subject":
book.Subject = parseSubject(data) book.Tags = parseSubject(data)
case "date": case "date":
book.Date = parseDate(data) book.Date = parseDate(data)
case "language": case "language":

View file

@ -159,8 +159,8 @@ func readHandler(h handler) {
data.S = GetStatus(h) data.S = GetStatus(h)
author := "" author := ""
if len(book.Author) > 0 { if len(book.Authors) > 0 {
author = " by " + book.Author[0] author = " by " + book.Authors[0]
} }
data.S.Title = book.Title + author + " -- Read -- " + data.S.Title data.S.Title = book.Title + author + " -- Read -- " + data.S.Title

View file

@ -208,11 +208,11 @@ func bookJsonRaw(book database.Book) map[string]interface{} {
return map[string]interface{}{ return map[string]interface{}{
"id": book.Id, "id": book.Id,
"title": book.Title, "title": book.Title,
"author": book.Author, "authors": book.Authors,
"contributor": book.Contributor, "contributor": book.Contributor,
"publisher": book.Publisher, "publisher": book.Publisher,
"description": book.Description, "description": book.Description,
"subject": book.Subject, "tags": book.Tags,
"date": book.Date, "date": book.Date,
"lang": book.Lang, "lang": book.Lang,
"isbn": book.Isbn, "isbn": book.Isbn,

View file

@ -68,8 +68,8 @@ func bookHandler(h handler) {
data.Book = book data.Book = book
author := "" author := ""
if len(book.Author) > 0 { if len(book.Authors) > 0 {
author = " by " + book.Author[0] author = " by " + book.Authors[0]
} }
data.S.Title = book.Title + author + " -- " + data.S.Title data.S.Title = book.Title + author + " -- " + data.S.Title

View file

@ -35,9 +35,9 @@ function delBook(){
<div class="row"> <div class="row">
<div class="span5"> <div class="span5">
<dl class="dl-horizontal"> <dl class="dl-horizontal">
{{if .Author}}<dt>Author</dt> <dd>{{range .Author}}<a href="/search/?q=author:{{.}}">{{.}}</a>, {{end}}</dd>{{end}} {{if .Authors}}<dt>Authors</dt> <dd>{{range .Authors}}<a href="/search/?q=author:{{.}}">{{.}}</a>, {{end}}</dd>{{end}}
{{if .Publisher}}<dt>Publisher</dt> <dd><a href="/search/?q=publisher:{{.Publisher}}">{{.Publisher}}</a></dd>{{end}} {{if .Publisher}}<dt>Publisher</dt> <dd><a href="/search/?q=publisher:{{.Publisher}}">{{.Publisher}}</a></dd>{{end}}
{{if .Subject}}<dt>Tags</dt> <dd>{{range .Subject}}<a href="/search/?q=subject:{{.}}">{{.}}</a>, {{end}}</dd>{{end}} {{if .Tags}}<dt>Tags</dt> <dd>{{range .Tags}}<a href="/search/?q=tag:{{.}}">{{.}}</a>, {{end}}</dd>{{end}}
{{if .Isbn}}<dt>ISBN</dt> <dd>{{.Isbn}}</dd>{{end}} {{if .Isbn}}<dt>ISBN</dt> <dd>{{.Isbn}}</dd>{{end}}
{{if .Date}}<dt>Date</dt> <dd>{{.Date}}</dd>{{end}} {{if .Date}}<dt>Date</dt> <dd>{{.Date}}</dd>{{end}}
{{if .Lang}}<dt>Lang</dt> <dd><a href="/search/?q=lang:{{.Lang}}">{{.Lang}}</a> </dd>{{end}} {{if .Lang}}<dt>Lang</dt> <dd><a href="/search/?q=lang:{{.Lang}}">{{.Lang}}</a> </dd>{{end}}

View file

@ -22,7 +22,7 @@
<div class="control-group"> <div class="control-group">
<label class="control-label" for="author">Author</label> <label class="control-label" for="author">Author</label>
<div class="controls"> <div class="controls">
{{range .Author}} {{range .Authors}}
<input class="input-xlarge" type="text" id="author" value="{{.}}" name="author"> <input class="input-xlarge" type="text" id="author" value="{{.}}" name="author">
{{end}} {{end}}
<input class="input-xlarge" type="text" id="author" placeholder="Add author" name="author"> <input class="input-xlarge" type="text" id="author" placeholder="Add author" name="author">
@ -37,7 +37,7 @@
<div class="control-group"> <div class="control-group">
<label class="control-label" for="tags">Tags</label> <label class="control-label" for="tags">Tags</label>
<div class="controls"> <div class="controls">
<input class="input-xlarge" type="text" id="tags" value="{{range .Subject}}{{.}},{{end}}" name="subject" placeholder="Add tag and hit enter"> <input class="input-xlarge" type="text" id="tags" value="{{range .Tags}}{{.}},{{end}}" name="tags" placeholder="Add tag and hit enter">
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">

View file

@ -12,7 +12,7 @@
<p>There is other topics than <em>lang</em> that can be used: <p>There is other topics than <em>lang</em> that can be used:
<ul> <ul>
<li><a href="/search/?q=author:doctorow">author:doctorow</a></li> <li><a href="/search/?q=author:doctorow">author:doctorow</a></li>
<li><a href="/search/?q=subject:computers title:python">subject:computers title:python</a></li> <li><a href="/search/?q=tag:computers title:python">tag:computers title:python</a></li>
</ul> </ul>
</p> </p>

View file

@ -72,7 +72,7 @@
</ul> </ul>
<div class="row"> <div class="row">
<p class="centered">{{range .Tags}}<a class="label" href="/search/?q=subject:{{.}}">{{.}}</a> {{end}}</p> <p class="centered">{{range .Tags}}<a class="label" href="/search/?q=tag:{{.}}">{{.}}</a> {{end}}</p>
</div> </div>
{{template "footer.html"}} {{template "footer.html"}}

View file

@ -42,11 +42,11 @@
<entry> <entry>
<title>{{html .}}</title> <title>{{html .}}</title>
<link rel="http://opds-spec.org/facet" <link rel="http://opds-spec.org/facet"
href="/search/?q=subject:{{urlquery .}}&amp;fmt=opds" href="/search/?q=tag:{{urlquery .}}&amp;fmt=opds"
title="{{html .}}" title="{{html .}}"
type="application/atom+xml;profile=opds-catalog;kind=acquisition"/> type="application/atom+xml;profile=opds-catalog;kind=acquisition"/>
<updated>{{$updated}}</updated> <updated>{{$updated}}</updated>
<id>{{$baseurl}}/search/?subject:{{urlquery .}}</id> <id>{{$baseurl}}/search/?tag:{{urlquery .}}</id>
</entry> </entry>
{{end}} {{end}}
</feed> </feed>

View file

@ -34,9 +34,9 @@
</div> </div>
<div class="span9"> <div class="span9">
<p><a href="/search/?q=title:{{.Title}}"><strong>{{.Title}}</strong></a> <small>({{$titleFound}})</small><br /> <p><a href="/search/?q=title:{{.Title}}"><strong>{{.Title}}</strong></a> <small>({{$titleFound}})</small><br />
{{if .Author}}<strong>Author:</strong> {{range .Author}}<a href="/search/?q=author:{{.}}">{{.}}</a>, {{end}} <small>({{$authorFound}})</small><br />{{end}} {{if .Authors}}<strong>Authors:</strong> {{range .Authors}}<a href="/search/?q=author:{{.}}">{{.}}</a>, {{end}} <small>({{$authorFound}})</small><br />{{end}}
{{if .Publisher}}<strong>Publisher:</strong> <a href="/search/?q=publisher:{{.Publisher}}">{{.Publisher}}</a><br />{{end}} {{if .Publisher}}<strong>Publisher:</strong> <a href="/search/?q=publisher:{{.Publisher}}">{{.Publisher}}</a><br />{{end}}
{{if .Subject}}<strong>Tags:</strong> {{range .Subject}}<a href="/search/?q=subject:{{.}}">{{.}}</a>, {{end}}<br />{{end}} {{if .Tags}}<strong>Tags:</strong> {{range .Tags}}<a href="/search/?q=tag:{{.}}">{{.}}</a>, {{end}}<br />{{end}}
{{if .Isbn}}<strong>ISBN:</strong> {{.Isbn}}<br />{{end}} {{if .Isbn}}<strong>ISBN:</strong> {{.Isbn}}<br />{{end}}
{{if .Date}}<strong>Date:</strong> {{.Date}}<br />{{end}} {{if .Date}}<strong>Date:</strong> {{.Date}}<br />{{end}}
{{if .Lang}}<strong>Lang:</strong> <a href="/search/?q=lang:{{.Lang}}">{{.Lang}}</a> <br />{{end}} {{if .Lang}}<strong>Lang:</strong> <a href="/search/?q=lang:{{.Lang}}">{{.Lang}}</a> <br />{{end}}

View file

@ -30,7 +30,7 @@
<span class="muted">[{{if .Lang}}{{.Lang}}{{end}}]</span> <span class="muted">[{{if .Lang}}{{.Lang}}{{end}}]</span>
<a href="/book/{{.Id}}"><strong>{{.Title}}</strong></a> <a href="/book/{{.Id}}"><strong>{{.Title}}</strong></a>
<span class="muted">{{if .Publisher}}{{.Publisher}}{{end}}</span><br /> <span class="muted">{{if .Publisher}}{{.Publisher}}{{end}}</span><br />
{{range .Author}}{{.}}, {{end}} {{range .Authors}}{{.}}, {{end}}
</p> </p>
</div> </div>
<div class="span3"> <div class="span3">

View file

@ -61,7 +61,7 @@
<id>{{$baseurl}}/book/{{.Id}}</id> <id>{{$baseurl}}/book/{{.Id}}</id>
<updated>{{$updated}}</updated> <updated>{{$updated}}</updated>
{{range .Author}} {{range .Authors}}
<author> <author>
<name>{{html .}}</name> <name>{{html .}}</name>
</author> </author>
@ -83,7 +83,7 @@
{{if .Lang}} {{if .Lang}}
<dcterms:language>{{.Lang}}</dcterms:language> <dcterms:language>{{.Lang}}</dcterms:language>
{{end}} {{end}}
{{range .Subject}} {{range .Tags}}
<category term="{{html .}}" <category term="{{html .}}"
label="{{html .}}"/> label="{{html .}}"/>
{{end}} {{end}}

View file

@ -14,14 +14,14 @@
{{$baseURL := .S.BaseURL}} {{$baseURL := .S.BaseURL}}
{{range .Books}} {{range .Books}}
<item> <item>
<title>{{.Title}} - {{index .Author 0}}</title> <title>{{.Title}} - {{index .Authors 0}}</title>
<description>{{.Description}}</description> <description>{{.Description}}</description>
<link>{{$baseURL}}/book/{{.Id}}</link> <link>{{$baseURL}}/book/{{.Id}}</link>
{{if .Isbn}} {{if .Isbn}}
<guid isPermaLink="false">ISBN: {{.Isbn}}</guid> <guid isPermaLink="false">ISBN: {{.Isbn}}</guid>
{{end}} {{end}}
<enclosure url="{{$baseURL}}/download/{{.Id}}/{{.Title}}.epub" length="{{.FileSize}}" type="application/epub+zip" /> <enclosure url="{{$baseURL}}/download/{{.Id}}/{{.Title}}.epub" length="{{.FileSize}}" type="application/epub+zip" />
{{range .Subject}} {{range .Authors}}
{{if .}} {{if .}}
<category>{{.}}</category> <category>{{.}}</category>
{{end}} {{end}}