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
|
||||
}
|
||||
|
||||
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)
|
||||
return
|
||||
}
|
||||
// Path
|
||||
path := ic.path
|
||||
if strings.Contains(path, searchPlaceholder) {
|
||||
path = strings.ReplaceAll(path, searchPlaceholder, searchEncode(search))
|
||||
}
|
||||
// Navigation
|
||||
prevPage, err := p.PrevPage()
|
||||
if err == paginator.ErrNoPrevPage {
|
||||
prevPage = p.Page()
|
||||
}
|
||||
prevPath := fmt.Sprintf("%s/page/%d", path, prevPage)
|
||||
if prevPage < 2 {
|
||||
prevPath = path
|
||||
}
|
||||
nextPage, err := p.NextPage()
|
||||
if err == paginator.ErrNoNextPage {
|
||||
nextPage = p.Page()
|
||||
}
|
||||
nextPath := fmt.Sprintf("%s/page/%d", path, nextPage)
|
||||
template := ic.template
|
||||
if len(template) == 0 {
|
||||
template = templateIndex
|
||||
}
|
||||
path := ic.path
|
||||
if strings.Contains(path, searchPlaceholder) {
|
||||
path = strings.ReplaceAll(path, searchPlaceholder, searchEncode(search))
|
||||
}
|
||||
render(w, template, &renderData{
|
||||
blogString: ic.blog,
|
||||
Canonical: appConfig.Server.PublicAddress + r.URL.Path,
|
||||
Canonical: appConfig.Server.PublicAddress + getBlogRelativePath(ic.blog, path),
|
||||
Data: &indexTemplateData{
|
||||
Title: title,
|
||||
Description: description,
|
||||
Posts: posts,
|
||||
HasPrev: p.HasPrev(),
|
||||
HasNext: p.HasNext(),
|
||||
First: ic.path,
|
||||
Prev: fmt.Sprintf("%s/page/%d", path, prevPage),
|
||||
Next: fmt.Sprintf("%s/page/%d", path, nextPage),
|
||||
First: getBlogRelativePath(ic.blog, path),
|
||||
Prev: getBlogRelativePath(ic.blog, prevPath),
|
||||
Next: getBlogRelativePath(ic.blog, nextPath),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue