Use Ids for address no titles
This commit is contained in:
parent
a95887a996
commit
88b4809e99
7 changed files with 23 additions and 19 deletions
20
reader.go
20
reader.go
|
@ -23,14 +23,14 @@ func parseUrl(url string) (string, string, string, string) {
|
||||||
exp, _ := regexp.Compile("^(\\/read[^\\/]*\\/)([^\\/]*)\\/?(.*\\.([^\\.]*))?$")
|
exp, _ := regexp.Compile("^(\\/read[^\\/]*\\/)([^\\/]*)\\/?(.*\\.([^\\.]*))?$")
|
||||||
res := exp.FindStringSubmatch(url)
|
res := exp.FindStringSubmatch(url)
|
||||||
base := res[1]
|
base := res[1]
|
||||||
title := res[2]
|
id := res[2]
|
||||||
file := ""
|
file := ""
|
||||||
ext := ""
|
ext := ""
|
||||||
if len(res) == 5 {
|
if len(res) == 5 {
|
||||||
file = res[3]
|
file = res[3]
|
||||||
ext = res[4]
|
ext = res[4]
|
||||||
}
|
}
|
||||||
return base, title, file, ext
|
return base, id, file, ext
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanHtml(html string) string {
|
func cleanHtml(html string) string {
|
||||||
|
@ -47,7 +47,7 @@ func cleanHtml(html string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return next and prev urls from document */
|
/* return next and prev urls from document */
|
||||||
func nextPrev(e *epub.Epub, file string, title string, base string) (string, string) {
|
func nextPrev(e *epub.Epub, file string, id string, base string) (string, string) {
|
||||||
it := e.Iterator(epub.EITERATOR_LINEAR)
|
it := e.Iterator(epub.EITERATOR_LINEAR)
|
||||||
defer it.Close()
|
defer it.Close()
|
||||||
|
|
||||||
|
@ -67,18 +67,18 @@ func nextPrev(e *epub.Epub, file string, title string, base string) (string, str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if prev != "" {
|
if prev != "" {
|
||||||
prev = base + title + "/" + prev
|
prev = base + id + "/" + prev
|
||||||
}
|
}
|
||||||
if next != "" {
|
if next != "" {
|
||||||
next = base + title + "/" + next
|
next = base + id + "/" + next
|
||||||
}
|
}
|
||||||
return next, prev
|
return next, prev
|
||||||
}
|
}
|
||||||
|
|
||||||
func readHandler(coll *mgo.Collection) func(http.ResponseWriter, *http.Request) {
|
func readHandler(coll *mgo.Collection) func(http.ResponseWriter, *http.Request) {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
base, title, file, ext := parseUrl(r.URL.Path)
|
base, id, file, ext := parseUrl(r.URL.Path)
|
||||||
books, _, err := GetBook(coll, bson.M{"title": title})
|
books, _, err := GetBook(coll, bson.M{"_id": bson.ObjectIdHex(id)})
|
||||||
if err != nil || len(books) == 0 {
|
if err != nil || len(books) == 0 {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
|
@ -89,7 +89,7 @@ func readHandler(coll *mgo.Collection) func(http.ResponseWriter, *http.Request)
|
||||||
if file == "" {
|
if file == "" {
|
||||||
it := e.Iterator(epub.EITERATOR_LINEAR)
|
it := e.Iterator(epub.EITERATOR_LINEAR)
|
||||||
defer it.Close()
|
defer it.Close()
|
||||||
http.Redirect(w, r, base + title + "/" + it.CurrUrl(), 307)
|
http.Redirect(w, r, base + id + "/" + it.CurrUrl(), 307)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,11 +97,11 @@ func readHandler(coll *mgo.Collection) func(http.ResponseWriter, *http.Request)
|
||||||
var data readData
|
var data readData
|
||||||
data.S = GetStatus(w, r)
|
data.S = GetStatus(w, r)
|
||||||
data.Book = book
|
data.Book = book
|
||||||
data.Next, data.Prev = nextPrev(e, file, title, base)
|
data.Next, data.Prev = nextPrev(e, file, id, base)
|
||||||
if base == "/readnew/" {
|
if base == "/readnew/" {
|
||||||
data.Back = "/new/"
|
data.Back = "/new/"
|
||||||
} else {
|
} else {
|
||||||
data.Back = "/book/" + title
|
data.Back = "/book/" + id
|
||||||
}
|
}
|
||||||
page := string(e.Data(file))
|
page := string(e.Data(file))
|
||||||
data.Txt = template.HTML(cleanHtml(page))
|
data.Txt = template.HTML(cleanHtml(page))
|
||||||
|
|
|
@ -54,7 +54,7 @@ function delBook(){
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="btn-group pull-right">
|
<div class="btn-group pull-right">
|
||||||
<a href="/{{.Path}}" class="btn btn-large btn-inverse"><i class="icon-download-alt icon-white"></i> download</a>
|
<a href="/{{.Path}}" class="btn btn-large btn-inverse"><i class="icon-download-alt icon-white"></i> download</a>
|
||||||
<a href="/read/{{.Title}}" class="btn btn-large btn-warning"><i class="icon-eye-open icon-white"></i> read it!</a>
|
<a href="/read/{{.Id}}" class="btn btn-large btn-warning"><i class="icon-eye-open icon-white"></i> read it!</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -68,7 +68,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button type="submit" class="btn btn-primary">Save</button>
|
<button type="submit" class="btn btn-primary">Save</button>
|
||||||
<a href="/book/{{.Title}}" class="btn">Cancel</a>
|
<a href="/book/{{.Id}}" class="btn">Cancel</a>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
{{with .Books}}
|
{{with .Books}}
|
||||||
{{range .}}
|
{{range .}}
|
||||||
<div class="span2">
|
<div class="span2">
|
||||||
<p class="centered down"><a href="/book/{{.Title}}">{{if .CoverSmall}}<img src="{{.CoverSmall}}" alt="{{.Title}}" />{{end}}</a></p>
|
<p class="centered down"><a href="/book/{{.Id}}">{{if .CoverSmall}}<img src="{{.CoverSmall}}" alt="{{.Title}}" />{{end}}</a></p>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
{{with .Books}}
|
{{with .Books}}
|
||||||
{{range .}}
|
{{range .}}
|
||||||
<div class="span2">
|
<div class="span2">
|
||||||
<p class="centered"><a href="/book/{{.Title}}"><strong>{{.Title}}</strong></a></p>
|
<p class="centered"><a href="/book/{{.Id}}"><strong>{{.Title}}</strong></a></p>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="span2">
|
<div class="span2">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<p><a href="/readnew/{{.Title}}" class="btn btn-warning pull-right"><i class="icon-eye-open icon-white"></i> read it!</a>
|
<p><a href="/readnew/{{.Id}}" class="btn btn-warning pull-right"><i class="icon-eye-open icon-white"></i> read it!</a>
|
||||||
<a href="/{{.Path}}" class="btn btn-inverse pull-right"><i class="icon-download-alt icon-white"></i> download</a></p>
|
<a href="/{{.Path}}" class="btn btn-inverse pull-right"><i class="icon-download-alt icon-white"></i> download</a></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="row"><p></p></div>
|
<div class="row"><p></p></div>
|
||||||
|
|
|
@ -19,18 +19,18 @@
|
||||||
{{range .}}
|
{{range .}}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span1">
|
<div class="span1">
|
||||||
<p class="pull-right"><a href="/book/{{.Title}}">{{if .CoverSmall}}<img src="{{.CoverSmall}}" alt="{{.Title}}" />{{end}}</a></p>
|
<p class="pull-right"><a href="/book/{{.Id}}">{{if .CoverSmall}}<img src="{{.CoverSmall}}" alt="{{.Title}}" />{{end}}</a></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="span10 well">
|
<div class="span10 well">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span7">
|
<div class="span7">
|
||||||
<p><a href="/book/{{.Title}}"><strong>{{.Title}}</strong></a><br />
|
<p><a href="/book/{{.Id}}"><strong>{{.Title}}</strong></a><br />
|
||||||
{{range .Author}}{{.}}, {{end}}</p>
|
{{range .Author}}{{.}}, {{end}}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="span3">
|
<div class="span3">
|
||||||
<div class="btn-group pull-right">
|
<div class="btn-group pull-right">
|
||||||
<a href="/{{.Path}}" class="btn btn-inverse"><i class="icon-download-alt icon-white"></i> download</a>
|
<a href="/{{.Path}}" class="btn btn-inverse"><i class="icon-download-alt icon-white"></i> download</a>
|
||||||
<a href="/read/{{.Title}}" class="btn btn-warning"><i class="icon-eye-open icon-white"></i> read it!</a>
|
<a href="/read/{{.Id}}" class="btn btn-warning"><i class="icon-eye-open icon-white"></i> read it!</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -66,7 +66,8 @@ func bookHandler(coll *mgo.Collection) func(http.ResponseWriter, *http.Request)
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var data bookData
|
var data bookData
|
||||||
data.S = GetStatus(w, r)
|
data.S = GetStatus(w, r)
|
||||||
books, _, err := GetBook(coll, bson.M{"title": r.URL.Path[len("/book/"):]})
|
id := bson.ObjectIdHex(r.URL.Path[len("/book/"):])
|
||||||
|
books, _, err := GetBook(coll, bson.M{"_id": id})
|
||||||
if err != nil || len(books) == 0 {
|
if err != nil || len(books) == 0 {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
|
@ -114,6 +115,9 @@ func indexHandler(coll *mgo.Collection) func(http.ResponseWriter, *http.Request)
|
||||||
data.S.Home = true
|
data.S.Home = true
|
||||||
data.Count, _ = coll.Count()
|
data.Count, _ = coll.Count()
|
||||||
coll.Find(bson.M{}).Sort("-_id").Limit(6).All(&data.Books)
|
coll.Find(bson.M{}).Sort("-_id").Limit(6).All(&data.Books)
|
||||||
|
for i, b := range data.Books {
|
||||||
|
data.Books[i].Id = bson.ObjectId(b.Id).Hex()
|
||||||
|
}
|
||||||
loadTemplate(w, "index", data)
|
loadTemplate(w, "index", data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue