Rename author to authors and subject to tags
This commit is contained in:
parent
e72de38725
commit
7f9c172853
17 changed files with 37 additions and 39 deletions
10
lib/admin.go
10
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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -21,7 +21,6 @@ type Visits struct {
|
|||
Count int "count"
|
||||
}
|
||||
|
||||
// TODO: split code in files
|
||||
func (db *pgDB) AddStats(stats interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -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":
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -35,9 +35,9 @@ function delBook(){
|
|||
<div class="row">
|
||||
<div class="span5">
|
||||
<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 .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 .Date}}<dt>Date</dt> <dd>{{.Date}}</dd>{{end}}
|
||||
{{if .Lang}}<dt>Lang</dt> <dd><a href="/search/?q=lang:{{.Lang}}">{{.Lang}}</a> </dd>{{end}}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<div class="control-group">
|
||||
<label class="control-label" for="author">Author</label>
|
||||
<div class="controls">
|
||||
{{range .Author}}
|
||||
{{range .Authors}}
|
||||
<input class="input-xlarge" type="text" id="author" value="{{.}}" name="author">
|
||||
{{end}}
|
||||
<input class="input-xlarge" type="text" id="author" placeholder="Add author" name="author">
|
||||
|
@ -37,7 +37,7 @@
|
|||
<div class="control-group">
|
||||
<label class="control-label" for="tags">Tags</label>
|
||||
<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 class="control-group">
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<p>There is other topics than <em>lang</em> that can be used:
|
||||
<ul>
|
||||
<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>
|
||||
</p>
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
</ul>
|
||||
|
||||
<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>
|
||||
|
||||
{{template "footer.html"}}
|
||||
|
|
|
@ -42,11 +42,11 @@
|
|||
<entry>
|
||||
<title>{{html .}}</title>
|
||||
<link rel="http://opds-spec.org/facet"
|
||||
href="/search/?q=subject:{{urlquery .}}&fmt=opds"
|
||||
href="/search/?q=tag:{{urlquery .}}&fmt=opds"
|
||||
title="{{html .}}"
|
||||
type="application/atom+xml;profile=opds-catalog;kind=acquisition"/>
|
||||
<updated>{{$updated}}</updated>
|
||||
<id>{{$baseurl}}/search/?subject:{{urlquery .}}</id>
|
||||
<id>{{$baseurl}}/search/?tag:{{urlquery .}}</id>
|
||||
</entry>
|
||||
{{end}}
|
||||
</feed>
|
||||
|
|
|
@ -34,9 +34,9 @@
|
|||
</div>
|
||||
<div class="span9">
|
||||
<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 .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 .Date}}<strong>Date:</strong> {{.Date}}<br />{{end}}
|
||||
{{if .Lang}}<strong>Lang:</strong> <a href="/search/?q=lang:{{.Lang}}">{{.Lang}}</a> <br />{{end}}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<span class="muted">[{{if .Lang}}{{.Lang}}{{end}}]</span>
|
||||
<a href="/book/{{.Id}}"><strong>{{.Title}}</strong></a>
|
||||
<span class="muted">{{if .Publisher}}{{.Publisher}}{{end}}</span><br />
|
||||
{{range .Author}}{{.}}, {{end}}
|
||||
{{range .Authors}}{{.}}, {{end}}
|
||||
</p>
|
||||
</div>
|
||||
<div class="span3">
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
<id>{{$baseurl}}/book/{{.Id}}</id>
|
||||
<updated>{{$updated}}</updated>
|
||||
|
||||
{{range .Author}}
|
||||
{{range .Authors}}
|
||||
<author>
|
||||
<name>{{html .}}</name>
|
||||
</author>
|
||||
|
@ -83,7 +83,7 @@
|
|||
{{if .Lang}}
|
||||
<dcterms:language>{{.Lang}}</dcterms:language>
|
||||
{{end}}
|
||||
{{range .Subject}}
|
||||
{{range .Tags}}
|
||||
<category term="{{html .}}"
|
||||
label="{{html .}}"/>
|
||||
{{end}}
|
||||
|
|
|
@ -14,14 +14,14 @@
|
|||
{{$baseURL := .S.BaseURL}}
|
||||
{{range .Books}}
|
||||
<item>
|
||||
<title>{{.Title}} - {{index .Author 0}}</title>
|
||||
<title>{{.Title}} - {{index .Authors 0}}</title>
|
||||
<description>{{.Description}}</description>
|
||||
<link>{{$baseURL}}/book/{{.Id}}</link>
|
||||
{{if .Isbn}}
|
||||
<guid isPermaLink="false">ISBN: {{.Isbn}}</guid>
|
||||
{{end}}
|
||||
<enclosure url="{{$baseURL}}/download/{{.Id}}/{{.Title}}.epub" length="{{.FileSize}}" type="application/epub+zip" />
|
||||
{{range .Subject}}
|
||||
{{range .Authors}}
|
||||
{{if .}}
|
||||
<category>{{.}}</category>
|
||||
{{end}}
|
||||
|
|
Reference in a new issue