Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit b1717f9

Browse files
committed
Added option to not index covers
1 parent 5b3b020 commit b1717f9

File tree

6 files changed

+28
-9
lines changed

6 files changed

+28
-9
lines changed

bookbrowser.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,16 @@ func main() {
5050
Value: ":8090",
5151
Usage: "`ADDR` is the address to bind the server to. It is in the format IP:PORT. The IP is optional.",
5252
},
53+
cli.BoolFlag{
54+
Name: "nocovers, n",
55+
Usage: "Do not index covers",
56+
},
5357
}
5458
app.HideHelp = true
5559
app.Action = func(c *cli.Context) {
5660
bookdir := c.String("bookdir")
5761
tempdir := c.String("tempdir")
62+
nocovers := c.Bool("nocovers")
5863
noRemoveTempDir := false
5964

6065
addr := c.String("addr")
@@ -113,7 +118,7 @@ func main() {
113118
}
114119
}
115120

116-
s := server.NewServer(addr, bookdir, tempdir, curversion, true)
121+
s := server.NewServer(addr, bookdir, tempdir, curversion, true, nocovers)
117122
s.RefreshBookIndex()
118123

119124
if len(*s.Books) == 0 {

modules/booklist/booklist.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type IndexerError struct {
2626
}
2727

2828
// NewBookListFromDir creates a BookList from a directory of books.
29-
func NewBookListFromDir(dir, coverOutDir string, verbose bool) (*BookList, []*IndexerError) {
29+
func NewBookListFromDir(dir, coverOutDir string, verbose, nocovers bool) (*BookList, []*IndexerError) {
3030
errors := []*IndexerError{}
3131
books := BookList{}
3232

@@ -77,7 +77,7 @@ func NewBookListFromDir(dir, coverOutDir string, verbose bool) (*BookList, []*In
7777
continue
7878
}
7979

80-
if cover != nil {
80+
if !nocovers && book.HasCover && cover != nil {
8181
coverPath := filepath.Join(coverOutDir, book.ID+".jpg")
8282
thumbPath := filepath.Join(coverOutDir, book.ID+"_thumb.jpg")
8383

@@ -108,6 +108,10 @@ func NewBookListFromDir(dir, coverOutDir string, verbose bool) (*BookList, []*In
108108
book.HasCover = true
109109
}
110110

111+
if nocovers {
112+
book.HasCover = false
113+
}
114+
111115
books = append(books, book)
112116
}
113117
}

modules/server/bindata_assetfs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9503,7 +9503,7 @@ func publicTemplatesBaseTmpl() (*asset, error) {
95039503
return a, nil
95049504
}
95059505

9506-
var _publicTemplatesBookTmpl = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xec\x53\x3d\x73\xe3\x20\x14\xec\xfd\x2b\x38\xae\xb6\xf8\x03\xb6\x6e\xee\xc6\x73\x33\x6e\xae\xb8\x38\x7d\x90\xf4\x64\x91\x48\x40\x00\x5b\xc9\x10\xfe\x7b\xd0\x87\x65\x24\xcb\x71\x91\x32\x51\x23\x86\x7d\x6f\x77\xe1\x2d\xd6\xd6\xcc\x14\x28\xfa\x23\xc4\x93\x73\x8b\x55\xc6\x8e\x28\x2d\xa9\xd6\x6b\xac\x19\xdf\x97\xb0\x4c\x3c\x82\xe3\x05\xf2\x5f\x88\xa6\xe2\x08\xaa\xdf\x6f\x31\x56\xed\x91\x56\xe9\x1a\x93\x16\xd2\xc4\xda\x68\xbb\x71\x2e\x7a\x94\x7b\x8c\x68\x69\x66\x7a\x02\xbe\xe4\x60\x8c\xe0\x3a\x40\xdb\x0a\x8a\x0a\x05\xb9\x27\xcd\x44\xcd\x4b\x41\xb3\x81\xd6\xff\xff\xb2\x12\x76\xaf\x12\x9c\xc3\x63\x1a\x74\xaa\xc6\xf1\xa6\x5f\x21\x6b\xd1\xd0\x80\xde\xd0\x4e\xdc\x4b\x09\x0a\x39\xb7\x22\x74\x2c\x6a\x2d\xcb\x11\x3c\x07\xe5\x18\xe4\x21\xc1\xfe\x7e\x26\xde\xc6\xa2\x0a\xbc\xe0\xc9\xaf\x36\xd4\xb0\x94\x34\x7b\xa0\x48\xd3\x4f\x7e\xfe\xb8\x75\x8a\xf8\xbf\x2f\x9f\xf1\x03\x3c\x73\x6e\xce\x97\xcc\xf2\xcf\xd8\xf2\xed\xa4\x86\x84\x1c\x19\xd4\xa0\xa2\xc2\x54\xe5\xaf\xdc\x93\xaf\x6f\x18\x7d\xf8\xd8\xe9\x79\xc0\xc4\x4f\xb8\xcf\x4e\xb0\x0c\xc6\x5e\x81\xa1\x57\x12\x61\x98\x29\x01\xc7\x5e\x78\xd7\xac\x9a\x41\x0d\x14\x9d\x58\x17\xdd\xdf\x07\x53\x08\x15\xaa\x0e\xa1\xa1\x2d\x34\x44\x71\x48\x49\xb7\xdf\x72\xff\xa3\x15\x4c\x32\x70\xbe\xef\x4e\xe0\x0e\x14\x03\x1d\x0a\x84\xaf\xa4\x05\xaf\xc6\xb6\x83\x2f\x0c\x70\xaf\x3a\x91\x47\xcb\x31\x85\x96\x94\x9f\xca\x19\xcf\xe0\xa5\xad\xdf\x36\xab\xa6\xa1\x81\xe3\xb9\x8b\xbe\x48\x4c\xb4\x01\x9d\x2a\x26\x0d\x13\xfc\xca\x21\xb2\x73\x05\x9e\x4e\x34\x6c\xf7\xef\x46\xd1\x7a\x7e\xc0\xb3\xf3\xff\x7e\xe0\x5f\xed\x81\xf7\xbf\xbe\xf0\x3d\x00\x00\xff\xff\x64\xb8\xe5\x24\x5f\x06\x00\x00")
9506+
var _publicTemplatesBookTmpl = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xec\x53\xcb\x92\xd3\x30\x10\xbc\xef\x57\x08\x71\x5e\xeb\x07\x12\x53\x40\x8a\x62\x2f\x1c\x20\xdc\x51\xec\x71\x2c\x90\x25\x21\x29\x31\x94\xf1\xbf\x33\x92\x1f\x91\xb3\xce\xee\x81\x23\xeb\x8b\x55\x9e\x99\xee\xf6\x74\xab\xeb\x5a\xe1\x6b\x92\xbd\xd3\xfa\x47\xdf\xdf\x6d\x4a\x71\x26\x85\xe4\xce\x6d\xa9\x13\xea\x28\xe1\xfe\x80\x15\x9a\xdf\x11\x7c\xd2\x6a\xa1\xcf\x60\xc7\xef\xe1\xe9\x3a\x51\x91\xec\x23\x77\xef\x43\x01\xa1\xa6\xc2\x46\x34\x47\xe2\x6c\xb1\xa5\x2c\xce\x38\xd6\x75\xd9\xc3\xae\xef\xb3\xef\xe6\x48\x09\x97\x7e\x0d\x0c\xa4\x83\x75\x10\xe7\xb9\x17\x05\x53\x3a\x0e\x3d\x0d\xa2\xca\x14\x23\x51\x7f\x38\x79\xaf\x95\x4b\xba\x63\x07\x27\xb5\x85\x0a\x49\x4a\xdd\x2a\xa9\x79\x39\x6b\xc5\xf7\x07\x21\x61\xff\xdb\xa0\x2c\xba\x84\x21\x53\x37\xcd\x77\xe3\x09\xc9\xc9\x3c\x40\xfe\x90\xbd\xfe\x6a\x0c\x58\xd2\xf7\x1b\xc6\x97\xa4\x71\x71\xf0\x33\x69\xa7\x60\x4e\x07\x9a\x28\x1f\xb5\x2d\x49\x2d\x20\xe1\xa4\x77\x5c\x4a\xf8\x06\x96\x85\x79\xf6\xfa\xd5\x73\x7f\x91\x7f\xc6\xf6\x15\x3d\x71\x6d\x6b\xba\x4c\x59\xfd\x8b\x2c\x1c\x67\x2d\x1c\xd8\x59\x40\x8b\xce\xd5\xbe\x91\x6f\x2a\x04\xdf\x3e\x23\xf4\xdb\xd3\x4a\x2f\x06\x33\x74\x78\x4c\x6a\x72\x4c\x6c\x6f\xc0\xf3\xc4\xf3\xb4\xe4\x85\x97\x40\x73\x24\xde\x87\x53\x30\x6a\x86\x18\xc8\x86\x8b\xf2\xf6\xe4\x6b\xbd\xc8\xf7\x1c\x1a\x1e\x4b\x73\xbe\xe7\x94\x0c\xdf\x23\xf6\x27\xde\xc0\x55\x06\x2e\xfb\x1e\x08\xbe\x80\x15\xe0\x6e\xe4\xd6\xc5\xe2\xcd\xd8\x0e\xe5\x47\x02\x14\xb2\x5e\xd1\x93\xfb\x25\x84\x33\x5c\x4d\xed\x42\x95\xf0\x2b\xf6\x3f\x84\x53\x18\x08\xe5\x7c\x6d\xd1\x8f\x12\x93\xed\xc0\x15\x56\x18\x2f\xb4\xba\xf1\x13\xe5\xa5\x83\x5e\x3b\x9a\x8e\xe3\xbd\xb1\xbc\x5d\x37\x78\xd5\xff\x97\x0b\xfe\xbf\x5d\xf0\xf1\x35\x36\xfe\x0d\x00\x00\xff\xff\xd3\xf9\x70\xb0\xcd\x06\x00\x00")
95079507

95089508
func publicTemplatesBookTmplBytes() ([]byte, error) {
95099509
return bindataRead(
@@ -9518,12 +9518,12 @@ func publicTemplatesBookTmpl() (*asset, error) {
95189518
return nil, err
95199519
}
95209520

9521-
info := bindataFileInfo{name: "public/templates/book.tmpl", size: 1631, mode: os.FileMode(420), modTime: time.Unix(1508190817, 0)}
9521+
info := bindataFileInfo{name: "public/templates/book.tmpl", size: 1741, mode: os.FileMode(420), modTime: time.Unix(1508602659, 0)}
95229522
a := &asset{bytes: bytes, info: info}
95239523
return a, nil
95249524
}
95259525

9526-
var _publicTemplatesBooksTmpl = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x84\x52\xbd\x6e\x83\x30\x10\xde\x79\x8a\x93\xf7\xc0\x0b\x24\x91\x5a\x75\xc9\x92\xa5\xdd\x2b\x07\x0e\x70\x0b\x76\x64\x1b\x52\xc9\xf2\xbb\xd7\x36\x3f\x72\x30\x6a\x99\xce\x77\xdf\xdf\x9d\x38\x56\x6c\x84\xb2\xa3\x4a\x9d\x48\x39\x48\x89\x5c\x1f\x46\x86\x0f\xb8\x09\xf1\xad\xa0\xa4\xb2\x52\xe4\x9c\x81\xfb\x8c\x91\x94\x37\x08\xf9\xab\x1f\x59\x1b\x9a\x31\xdf\x53\x66\x6c\x18\x51\x68\x25\xd6\x27\x52\x04\xad\xc2\x98\xfc\xf2\x66\x2d\x59\xed\xc4\x88\x32\xc2\x07\x0e\xeb\x1b\x50\xb2\x74\xa4\x30\x5e\x59\x9f\xba\x1d\xfa\x5b\xfe\x75\x6f\x08\xd0\x4e\xa7\xec\x63\x41\xa3\x47\x94\xaa\x47\x4d\xb7\x2e\xff\x24\xd3\x4c\x77\x48\xce\xae\xfd\xe1\x2b\x6b\x9f\xc4\xa7\x5b\x3c\x98\x6e\x21\x7f\x19\x74\x2b\xe4\x7c\x8b\x54\x9e\x86\x71\x6a\x30\xf5\x83\xc3\x95\xf6\xfb\x06\xc8\x2b\x6b\x57\xa3\x77\x94\x0c\xd5\xd6\x28\x5a\x53\x05\xc0\x66\xd1\xe7\x34\x13\x24\x09\xc3\x5d\x82\xbf\xa2\xf8\xef\x90\xca\xaa\x3b\xe5\x8b\x04\xe3\x15\xfe\x04\x8d\x8b\xaf\xbc\x88\x1f\x6f\xae\x5e\xb8\xb8\xbb\x5b\x66\x3b\x90\xa8\x5c\x50\x73\x2b\x33\x86\xd5\xc0\x85\x5e\xff\x44\xb8\xba\x47\x2d\x06\x5e\x2d\xd8\xdf\x00\x00\x00\xff\xff\xa3\x81\x04\x88\xd7\x02\x00\x00")
9526+
var _publicTemplatesBooksTmpl = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x84\x93\xcf\x6e\x83\x30\x0c\xc6\xef\x7d\x8a\x28\xf7\xc2\x0b\xb4\x95\xf6\xe7\xb0\x5e\x7a\xd9\xee\x93\x0b\x6e\xc9\x06\x49\x95\x84\x76\x12\xca\xbb\x2f\x31\x10\xa5\xb0\x8e\x9c\x82\xfd\xf9\xf7\xd9\x06\x36\xa5\xb8\xb2\xa2\x06\x63\xb6\xbc\x68\xb5\x46\x69\xd7\x57\x81\x37\x76\x54\xea\xdb\xb0\x02\x74\x69\xf8\x6e\xc5\xfc\xe9\x3a\x0d\xf2\x8c\x2c\x7b\x0e\x29\xe7\x28\x98\xd6\x87\x92\x41\x4b\x29\x60\x95\xc6\xd3\x96\xe7\xc4\xca\xbb\x2e\xdb\xbf\x3a\xc7\xa3\x9d\xba\xa2\x4e\xf4\xbd\x87\x38\xb1\xec\x0d\xcc\x4b\x48\x0e\x1e\x11\x28\x9a\x33\x33\xba\xf0\x44\xaa\x8d\xc8\x4f\x5b\xb5\xcd\x31\xfb\xba\x9c\x39\x83\xda\x3e\x42\x63\x6d\xf0\x31\xd2\x58\xb0\xa2\xc8\xa5\xa2\xe2\x65\x98\x2c\x13\xd6\x26\x87\x64\xf0\x64\x27\x0d\x5a\x98\xd4\x2e\xed\xc5\x0a\x5b\x23\xdf\xf9\xf0\x47\xb8\x39\x77\x07\xef\xdd\x6f\xc2\x56\x2c\x7b\x6a\x6d\xa5\x66\x5b\x8a\x78\xa0\xf4\xdc\xa0\x8f\x93\xc3\x01\x9a\xbf\x0d\x68\xbc\x68\xf4\x8e\x5a\xa0\x99\x1a\x25\x63\x1a\x12\x4c\x06\xbd\xef\xa6\x97\xcc\x9a\x91\xbe\x83\xff\x5a\x09\x67\x3d\xc7\x9a\x0b\xc8\x11\x21\x64\x89\x3f\xc4\xd8\x87\x5b\x80\x84\xf4\x64\xeb\xb9\x6f\x77\xe9\x25\x46\x49\x72\x1d\x55\x43\x68\x45\x9f\xa8\x54\x36\xfe\x07\xec\xe0\x1f\x4e\xaa\x95\xe5\xa8\xfd\x0d\x00\x00\xff\xff\x87\xaa\x63\x9b\x55\x03\x00\x00")
95279527

95289528
func publicTemplatesBooksTmplBytes() ([]byte, error) {
95299529
return bindataRead(
@@ -9538,7 +9538,7 @@ func publicTemplatesBooksTmpl() (*asset, error) {
95389538
return nil, err
95399539
}
95409540

9541-
info := bindataFileInfo{name: "public/templates/books.tmpl", size: 727, mode: os.FileMode(420), modTime: time.Unix(1508190817, 0)}
9541+
info := bindataFileInfo{name: "public/templates/books.tmpl", size: 853, mode: os.FileMode(420), modTime: time.Unix(1508602676, 0)}
95429542
a := &asset{bytes: bytes, info: info}
95439543
return a, nil
95449544
}

modules/server/server.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Server struct {
3232
booksLock *sync.RWMutex
3333
BookDir string
3434
CoverDir string
35+
NoCovers bool
3536
Addr string
3637
Verbose bool
3738
router *httprouter.Router
@@ -40,13 +41,14 @@ type Server struct {
4041
}
4142

4243
// NewServer creates a new BookBrowser server. It will not index the books automatically.
43-
func NewServer(addr, bookdir, coverdir, version string, verbose bool) *Server {
44+
func NewServer(addr, bookdir, coverdir, version string, verbose, nocovers bool) *Server {
4445
s := &Server{
4546
Books: &booklist.BookList{},
4647
booksLock: &sync.RWMutex{},
4748
BookDir: bookdir,
4849
Addr: addr,
4950
CoverDir: coverdir,
51+
NoCovers: nocovers,
5052
Verbose: verbose,
5153
router: httprouter.New(),
5254
version: version,
@@ -72,7 +74,7 @@ func (s *Server) RefreshBookIndex() error {
7274
defer s.printLog("Unlocking book index\n")
7375
defer s.booksLock.Unlock()
7476

75-
books, errs := booklist.NewBookListFromDir(s.BookDir, s.CoverDir, s.Verbose)
77+
books, errs := booklist.NewBookListFromDir(s.BookDir, s.CoverDir, s.Verbose, s.NoCovers)
7678
if len(errs) != 0 {
7779
if s.Verbose {
7880
log.Printf("Indexing finished with %v errors", len(errs))

public/templates/book.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{{with .Book}}
22
<div class="single-book">
33
<div class="cover">
4+
{{if .HasCover}}
45
<img src="/covers/{{.ID}}.jpg" alt="cover">
6+
{{else}}
7+
<img src="/static/nocover.jpg" alt="cover">
8+
{{end}}
59
<div class="buttons">
610
<a href="/download/{{.ID}}.{{.FileType}}" class="button download">Download {{ .FileType | ToUpper }}</a>
711
{{if eq .FileType "epub"}}

public/templates/books.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
{{range .Books}}
33
<div class="book">
44
<a href="/books/{{.ID}}" class="cover">
5+
{{if .HasCover}}
56
<img src="/covers/{{.ID}}_thumb.jpg" alt="cover">
7+
{{else}}
8+
<img src="/static/nocover.jpg" alt="cover">
9+
{{end}}
610
</a>
711
<div class="meta">
812
<a href="/books/{{.ID}}" class="title">{{.Title}}</a>

0 commit comments

Comments
 (0)