Browse Source

Fix index navigation

master
Jan-Lukas Else 2 months ago
parent
commit
7c6102b9db
2 changed files with 18 additions and 8 deletions
  1. +4
    -0
      blogs.go
  2. +14
    -8
      posts.go

+ 4
- 0
blogs.go 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)
}

+ 14
- 8
posts.go 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),
},
})
}


Loading…
Cancel
Save