Compare commits
1 Commits
229c2d535e
...
4aea64f71f
Author | SHA1 | Date | |
---|---|---|---|
4aea64f71f |
@ -15,6 +15,12 @@ Bouquins in Go
|
||||
* JS: https://www.danstools.com/javascript-minify/
|
||||
* CSS: curl -X POST -s --data-urlencode 'input@assets/css/bouquins.css' https://cssminifier.com/raw > assets/css/bouquins.min.css
|
||||
|
||||
## Versionning
|
||||
|
||||
Build with flag to define `main.version`
|
||||
|
||||
go build -ldflags "-X main.version=myVersion"
|
||||
|
||||
## Deployment archive
|
||||
|
||||
tar czf ~/tmp/go-bouquins.tar.gz go-bouquins assets/ templates/
|
||||
|
@ -19,9 +19,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// Version defines application version
|
||||
Version = "master"
|
||||
|
||||
tplBooks = "book.html"
|
||||
tplAuthors = "author.html"
|
||||
tplSeries = "series.html"
|
||||
@ -56,11 +53,11 @@ const (
|
||||
// URLAbout url of about page
|
||||
URLAbout = "/about/"
|
||||
// URLJs url of js assets
|
||||
URLJs = "/" + Version + "/js/"
|
||||
URLJs = "/js/"
|
||||
// URLCss url of css assets
|
||||
URLCss = "/" + Version + "/css/"
|
||||
URLCss = "/css/"
|
||||
// URLFonts url of fonts assets
|
||||
URLFonts = "/" + Version + "/webfonts/"
|
||||
URLFonts = "/webfonts/"
|
||||
// URLCalibre url of calibre resources (covers, ebooks files)
|
||||
URLCalibre = "/calibre/"
|
||||
)
|
||||
@ -186,7 +183,6 @@ type SeriesFull struct {
|
||||
type Model struct {
|
||||
Title string
|
||||
Page string
|
||||
Version string
|
||||
Username string
|
||||
}
|
||||
|
||||
@ -195,7 +191,6 @@ func (app *Bouquins) NewModel(title, page string, req *http.Request) *Model {
|
||||
return &Model{
|
||||
Title: title,
|
||||
Page: page,
|
||||
Version: Version,
|
||||
Username: app.Username(req),
|
||||
}
|
||||
}
|
||||
@ -285,18 +280,21 @@ type ReqParams struct {
|
||||
}
|
||||
|
||||
// TemplatesFunc adds functions to templates
|
||||
func TemplatesFunc(prod bool) *template.Template {
|
||||
func TemplatesFunc(prod bool, version string) *template.Template {
|
||||
return template.New("").Funcs(template.FuncMap{
|
||||
"assetUrl": func(name string, ext string) string {
|
||||
sep := "."
|
||||
if prod {
|
||||
sep = ".min."
|
||||
}
|
||||
return "/" + Version + "/" + ext + "/" + name + sep + ext
|
||||
return "/" + ext + "/" + name + sep + ext
|
||||
},
|
||||
"humanSize": func(sz int64) string {
|
||||
return datasize.ByteSize(sz).HumanReadable()
|
||||
},
|
||||
"version": func() string {
|
||||
return version
|
||||
},
|
||||
"bookCover": func(book *BookFull) string {
|
||||
fmt.Println(book.Path)
|
||||
return "/calibre/" + url.PathEscape(book.Path) + "/cover.jpg"
|
||||
|
16
main.go
16
main.go
@ -2,11 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"gopkg.in/yaml.v2"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
|
||||
"github.com/gorilla/sessions"
|
||||
@ -15,6 +16,10 @@ import (
|
||||
"meutel.net/meutel/go-bouquins/bouquins"
|
||||
)
|
||||
|
||||
var (
|
||||
version string
|
||||
)
|
||||
|
||||
// ReadConfig loads configuration file and initialize default value
|
||||
func ReadConfig() (*bouquins.Conf, error) {
|
||||
conf := new(bouquins.Conf)
|
||||
@ -53,7 +58,7 @@ func initApp() *bouquins.Bouquins {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
tpl, err := bouquins.TemplatesFunc(conf.Prod).ParseGlob("templates/*.html")
|
||||
tpl, err := bouquins.TemplatesFunc(conf.Prod, version).ParseGlob("templates/*.html")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@ -86,9 +91,9 @@ func initApp() *bouquins.Bouquins {
|
||||
}
|
||||
|
||||
func assets(calibre string) {
|
||||
http.Handle(bouquins.URLJs, http.StripPrefix("/"+bouquins.Version, http.FileServer(http.Dir("assets"))))
|
||||
http.Handle(bouquins.URLCss, http.StripPrefix("/"+bouquins.Version, http.FileServer(http.Dir("assets"))))
|
||||
http.Handle(bouquins.URLFonts, http.StripPrefix("/"+bouquins.Version, http.FileServer(http.Dir("assets"))))
|
||||
http.Handle(bouquins.URLJs, http.FileServer(http.Dir("assets")))
|
||||
http.Handle(bouquins.URLCss, http.FileServer(http.Dir("assets")))
|
||||
http.Handle(bouquins.URLFonts, http.FileServer(http.Dir("assets")))
|
||||
}
|
||||
|
||||
func handle(f func(res http.ResponseWriter, req *http.Request) error) func(res http.ResponseWriter, req *http.Request) {
|
||||
@ -120,6 +125,7 @@ func router(app *bouquins.Bouquins) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.Println("go-bouquins", version)
|
||||
app := initApp()
|
||||
defer app.DB.Close()
|
||||
defer app.UserDB.Close()
|
||||
|
@ -1,5 +1,6 @@
|
||||
{{ template "header.html" . }}
|
||||
<div class="container" id="about">
|
||||
<p>go-bouquins {{ version }}</p>
|
||||
<p><b>bouquins</b> est une interface web pour le gestionnaire de livres numériques <a href="https://calibre-ebook.com/">calibre</a>. Cette version utilise le langage <a href="https://golang.org/">Go</a>, le framework <a href="https://getbootstrap.com/">bootstap</a> et le framework <a href="https://vuejs.org/">Vue.js</a>.</p>
|
||||
<p>Ce logiciel est open-source et distribué sous <a href="https://opensource.org/licenses/BSD-3-Clause">license BSD</a>. Le code source est disponible ici: <a href="https://git.meutel.net/meutel/go-bouquins">https://git.meutel.net/meutel/go-bouquins</a>.
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user