diff --git a/helpers/path.go b/helpers/path.go index 53e29591f..e7b84ade3 100644 --- a/helpers/path.go +++ b/helpers/path.go @@ -299,6 +299,22 @@ func GetRelativePath(path, base string) (final string, err error) { return name, nil } +func PaginateAliasPath(base string, page int) string { + paginatePath := viper.GetString("paginatePath") + uglify := viper.GetBool("UglyURLs") + var p string + if base != "" { + p = filepath.FromSlash(fmt.Sprintf("/%s/%s/%d", base, paginatePath, page)) + } else { + p = filepath.FromSlash(fmt.Sprintf("/%s/%d", paginatePath, page)) + } + if uglify { + p += ".html" + } + + return p +} + // GuessSection returns the section given a source path. // A section is the part between the root slash and the second slash // or before the first slash. diff --git a/hugolib/site.go b/hugolib/site.go index 3e639760a..2018df4bb 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -1096,7 +1096,7 @@ func taxonomyRenderer(s *Site, taxes <-chan taxRenderInfo, results chan<- error, paginatePath := viper.GetString("paginatePath") // write alias for page 1 - s.WriteDestAlias(fmt.Sprintf("%s/%s/%d/index.html", base, paginatePath, 1), s.permalink(base)) + s.WriteDestAlias(helpers.PaginateAliasPath(base, 1), s.permalink(base)) pagers := n.paginator.Pagers() @@ -1191,7 +1191,7 @@ func (s *Site) RenderSectionLists() error { paginatePath := viper.GetString("paginatePath") // write alias for page 1 - s.WriteDestAlias(filepath.FromSlash(fmt.Sprintf("/%s/%s/%d", section, paginatePath, 1)), s.permalink(section)) + s.WriteDestAlias(helpers.PaginateAliasPath(section, 1), s.permalink(section)) pagers := n.paginator.Pagers() @@ -1248,7 +1248,7 @@ func (s *Site) RenderHomePage() error { paginatePath := viper.GetString("paginatePath") // write alias for page 1 - s.WriteDestAlias(filepath.FromSlash(fmt.Sprintf("/%s/%d", paginatePath, 1)), s.permalink("/")) + s.WriteDestAlias(helpers.PaginateAliasPath("", 1), s.permalink("/")) pagers := n.paginator.Pagers()