Fix index navigation

This commit is contained in:
Jan-Lukas Else 2020-11-15 12:46:24 +01:00
parent 6c7672d3ec
commit 7c6102b9db
2 changed files with 18 additions and 8 deletions

View File

@ -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)
}

View File

@ -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),
},
})
}