Display cover, configure calibre path

This commit is contained in:
Meutel 2017-08-04 20:06:10 +02:00
parent c565a9318a
commit daa6d2152e
3 changed files with 18 additions and 6 deletions

View File

@ -3,13 +3,15 @@ package bouquins
import (
"database/sql"
"encoding/json"
"github.com/c2h5oh/datasize"
"fmt"
"html/template"
"log"
"net/http"
"net/url"
"strconv"
"strings"
"github.com/c2h5oh/datasize"
)
const (
@ -35,6 +37,7 @@ const (
URL_JS = "/js/"
URL_CSS = "/css/"
URL_FONTS = "/fonts/"
URL_CALIBRE = "/calibre/"
)
type Bouquins struct {
@ -188,8 +191,12 @@ func TemplatesFunc() *template.Template {
"humanSize": func(sz int64) string {
return datasize.ByteSize(sz).HumanReadable()
},
"bookCover": func(book *BookFull) string {
fmt.Println(book.Path)
return "/calibre/" + url.PathEscape(book.Path) + "/cover.jpg"
},
"bookLink": func(data *BookData, book *BookFull) string {
return "/images/" + url.QueryEscape(book.Path) + "/" + url.QueryEscape(data.Name) + "." + strings.ToLower(data.Format)
return "/calibre/" + url.PathEscape(book.Path) + "/" + url.PathEscape(data.Name) + "." + strings.ToLower(data.Format)
},
})
return tpl

11
main.go
View File

@ -15,6 +15,7 @@ import (
type BouquinsConf struct {
BindAddress string `json:"bind-address"`
DbPath string `json:"db-path"`
CalibrePath string `json:"calibre-path"`
}
var db *sql.DB
@ -35,8 +36,11 @@ func ReadConfig() (*BouquinsConf, error) {
err = nil
}
// default values
if conf.CalibrePath == "" {
conf.CalibrePath = "."
}
if conf.DbPath == "" {
conf.DbPath = "calibre.db"
conf.DbPath = conf.CalibrePath + "/metadata.db"
}
if conf.BindAddress == "" {
conf.BindAddress = ":9000"
@ -67,15 +71,16 @@ func initApp() *BouquinsConf {
if err != nil {
log.Fatalln(err)
}
assets()
assets(conf.CalibrePath)
router(app)
return conf
}
func assets() {
func assets(calibre string) {
http.Handle(URL_JS, http.FileServer(http.Dir("assets")))
http.Handle(URL_CSS, http.FileServer(http.Dir("assets")))
http.Handle(URL_FONTS, http.FileServer(http.Dir("assets")))
http.Handle(URL_CALIBRE, http.StripPrefix(URL_CALIBRE, http.FileServer(http.Dir(calibre))))
}
func router(app *Bouquins) {

View File

@ -4,7 +4,7 @@
<div class="page-header">
{{ if .Has_cover }}
<div class="row">
<img :src="bookCover(book)" alt="Pas de couverture" title="Couverture" class="img-responsive img-rounded"/>
<img src="{{ bookCover .BookFull }}" alt="Pas de couverture" title="Couverture" class="img-responsive img-rounded" width="400px"/>
</div>
{{ end }}
<div class="row">