mirror of https://github.com/jlelse/GoBlog
Fix index navigation
This commit is contained in:
parent
6c7672d3ec
commit
7c6102b9db
4
blogs.go
4
blogs.go
|
@ -11,3 +11,7 @@ func (blog *configBlog) getRelativePath(path string) string {
|
||||||
}
|
}
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getBlogRelativePath(blog, path string) string {
|
||||||
|
return appConfig.Blogs[blog].getRelativePath(path)
|
||||||
|
}
|
||||||
|
|
22
posts.go
22
posts.go
|
@ -219,35 +219,41 @@ func serveIndex(ic *indexConfig) func(w http.ResponseWriter, r *http.Request) {
|
||||||
generateFeed(ic.blog, ft, w, r, posts, title, description)
|
generateFeed(ic.blog, ft, w, r, posts, title, description)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Path
|
||||||
|
path := ic.path
|
||||||
|
if strings.Contains(path, searchPlaceholder) {
|
||||||
|
path = strings.ReplaceAll(path, searchPlaceholder, searchEncode(search))
|
||||||
|
}
|
||||||
// Navigation
|
// Navigation
|
||||||
prevPage, err := p.PrevPage()
|
prevPage, err := p.PrevPage()
|
||||||
if err == paginator.ErrNoPrevPage {
|
if err == paginator.ErrNoPrevPage {
|
||||||
prevPage = p.Page()
|
prevPage = p.Page()
|
||||||
}
|
}
|
||||||
|
prevPath := fmt.Sprintf("%s/page/%d", path, prevPage)
|
||||||
|
if prevPage < 2 {
|
||||||
|
prevPath = path
|
||||||
|
}
|
||||||
nextPage, err := p.NextPage()
|
nextPage, err := p.NextPage()
|
||||||
if err == paginator.ErrNoNextPage {
|
if err == paginator.ErrNoNextPage {
|
||||||
nextPage = p.Page()
|
nextPage = p.Page()
|
||||||
}
|
}
|
||||||
|
nextPath := fmt.Sprintf("%s/page/%d", path, nextPage)
|
||||||
template := ic.template
|
template := ic.template
|
||||||
if len(template) == 0 {
|
if len(template) == 0 {
|
||||||
template = templateIndex
|
template = templateIndex
|
||||||
}
|
}
|
||||||
path := ic.path
|
|
||||||
if strings.Contains(path, searchPlaceholder) {
|
|
||||||
path = strings.ReplaceAll(path, searchPlaceholder, searchEncode(search))
|
|
||||||
}
|
|
||||||
render(w, template, &renderData{
|
render(w, template, &renderData{
|
||||||
blogString: ic.blog,
|
blogString: ic.blog,
|
||||||
Canonical: appConfig.Server.PublicAddress + r.URL.Path,
|
Canonical: appConfig.Server.PublicAddress + getBlogRelativePath(ic.blog, path),
|
||||||
Data: &indexTemplateData{
|
Data: &indexTemplateData{
|
||||||
Title: title,
|
Title: title,
|
||||||
Description: description,
|
Description: description,
|
||||||
Posts: posts,
|
Posts: posts,
|
||||||
HasPrev: p.HasPrev(),
|
HasPrev: p.HasPrev(),
|
||||||
HasNext: p.HasNext(),
|
HasNext: p.HasNext(),
|
||||||
First: ic.path,
|
First: getBlogRelativePath(ic.blog, path),
|
||||||
Prev: fmt.Sprintf("%s/page/%d", path, prevPage),
|
Prev: getBlogRelativePath(ic.blog, prevPath),
|
||||||
Next: fmt.Sprintf("%s/page/%d", path, nextPage),
|
Next: getBlogRelativePath(ic.blog, nextPath),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue