From 7c6102b9db7431ff689b0c9c98643c54326afdf3 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Sun, 15 Nov 2020 12:46:24 +0100 Subject: [PATCH] Fix index navigation --- blogs.go | 4 ++++ posts.go | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/blogs.go b/blogs.go index d36efaf..2d5bb03 100644 --- a/blogs.go +++ b/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) +} diff --git a/posts.go b/posts.go index a2f4c3c..8b9b1f5 100644 --- a/posts.go +++ b/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), }, }) }